statistics

Functions for spectral statistical analysis.

specviz.analysis.statistics.extract(data, x_range)[source]

Extract a region from a spectrum.

Parameters:
  • data (Data) – Contains the spectrum to be extracted.
  • x_range (tuple) – A spectral coordinate range as in (wave1, wave2).
Returns:

result – Spectrum data with extracted region.

Return type:

Data

Examples

>>> d = Data(...)
>>> d2 = extract(d, (10000, 20000))
specviz.analysis.statistics.stats(data)[source]

Compute basic statistics for a spectral region contained in a Data instance.

Parameters:data (Data) – Typically this is returned by the extract() function.
Returns:statistics – Statistics results.
Return type:dict

Examples

>>> d = Data(...)
>>> d_stats = stats(d)
specviz.analysis.statistics.eq_width(cont1_stats, cont2_stats, line, mask=None)[source]

Compute an equivalent width given stats for two continuum regions, and a Data instance with the extracted spectral line region.

This uses for now a very simple continuum subtraction method; i.e., it just subtracts a constant from the line spectrum, where the constant is (continuum1[mean] + continuum2[mean]) / 2.

Parameters:
  • cont2_stats (cont1_stats,) – This is returned by the stats() function.
  • line (Data) – This is returned by the extract() function.
  • mask (ndarray) – Boolean mask.
Returns:

ew, flux, avg_cont – Flux and equivalent width values.

Return type:

float

Examples

>>> d = Data(...)
>>> cont1 = extract(d, (100, 5000))
>>> cont2 = extract(d, (18000, 20000))
>>> cont1_stats = stats(cont1)
>>> cont2_stats = stats(cont2)
>>> line = extract(d, (15000, 18000))
>>> flux, ew = eq_width(cont1_stats, cont2_stats, line)
specviz.analysis.statistics.fwzi(cont1_stats, cont2_stats, line)[source]

Compute full width at zero intensity (FWZI) for the given spectrum. Continuum calculations are similar to eq_width().

Parameters:
  • cont2_stats (cont1_stats,) – This is returned by the stats() function.
  • line (Data) – This is returned by the extract() function.
Returns:

  • fwzi_value (float) – FWZI value.
  • w_range (tuple) – Wavelengths used to calculate FWZI.

Examples

>>> d = Data(...)
>>> cont1 = extract(d, (100, 5000))
>>> cont2 = extract(d, (18000, 20000))
>>> cont1_stats = stats(cont1)
>>> cont2_stats = stats(cont2)
>>> line = extract(d, (15000, 18000))
>>> fwzi_value, w_range = fwzi(cont1_stats, cont2_stats, line)
specviz.analysis.statistics.centroid(data, mask=None)[source]

Compute centroid for the given spectrum.

w_cen = integral(wave*flux) / integral(flux)
Parameters:data (Data) – Extracted spectrum data.
Returns:wcen – Centroid wavelength.
Return type:float

Examples

>>> d = Data(...)
>>> line = extract(d, (15000, 20000))
>>> wcen_em = centroid(line)