spec_analysis.features

The features is responsible for measuring the properties of individual spectral features. Individual classes are used to represent separate calculations of feature properties. These classes may be used individually, however, it is recommended you use the ObservedFeature class which combines all of the calculations into a single object.

spec_analysis.features.FeatureArea Represents the area calculation for a spectroscopic feature
spec_analysis.features.FeaturePEW Represents the pEW calculation for a spectroscopic feature
spec_analysis.features.FeatureVelocity Represents the velocity calculation for a spectroscopic feature
spec_analysis.features.ObservedFeature Represents a spectral observation spanning a single absorption feature

Usage Examples

Included in the ObservedFeature class is the ability to calculate the area, pseudo equivalent width (PEW), and flux of a given feature. Feature classes are instantiated using the rest frame wavelength, flux, and binned flux (e.g., the flux through a median filter).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import numpy as np
from scipy.ndimage.filters import median_filter

from spec_analysis.features import find_peak_wavelength
from spec_analysis.simulate import gaussian

wave = np.arange(1000, 2000)
flux, flux_err = gaussian(wave, stddev=100)
bin_flux = median_filter(flux, size=10)

feature = ObservedFeature(wave, flux, bin_flux)

Feature properties can be accessed using attributes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# From the area calculation
area = feature.area            # Feature area

# From the PEW calculation
continuum = feature.continuum  # Sudo continuum flux per wavelength
norm_flux = feature.norm_flux  # Normalized flux per wavelength
pew = feature.pew              # Pseudo equivalent width

# From the velocity calculation
velocity = feature.velocity    # velocity of the feature in km / s
amp = feature.gauss_amplitude  # Amplitude of fitted gaussian
avg = feature.gauss_avg        # Average of fitted gaussian
stddev = feature.gauss_stddev  # Standard deviation of fitted gaussian
offset = feature.gauss_offset  # y-offset of fitted gaussian

Note that the velocity is determined by fitting the normalized flux using an inverted Gaussian of the form

\[- A * e^{(-(x - \mu)^2 / (2 \sigma^2)} + c\]

This function is accessible programmatically as spec_analysis.features.gaussian, or the evaluated fit can be determined using

gauss_fit = feature.gaussian_fit()

API Documentation

spec_analysis.features.gaussian(x, depth, avg, std, offset)[source]

Evaluate a negative gaussian

f = -depth * e^(-((x - avg)^2) / (2 * std ** 2)) + offset

Parameters:
  • x (ndarray) – Values to evaluate the gaussian at
  • depth (float) – Amplitude of the gaussian
  • avg (float) – Average of the gaussian
  • std (float) – Standard deviation of the gaussian
  • offset (float) – Vertical offset
Returns:

The evaluated gaussian

class spec_analysis.features.FeatureArea(wave, flux, bin_flux)[source]

Represents the area calculation for a spectroscopic feature

__init__(wave, flux, bin_flux)[source]

Calculates the area of a spectroscopic feature

Parameters:
  • wave (ndarray) – The wavelength values of the feature
  • flux (ndarray) – The flux values for the feature
  • bin_flux (ndarray) – The binned flux values for the feature
area

The area of the feature

Area is determined between the sudo continuum of the binned flux and the flux values from the non-binned flux.

class spec_analysis.features.FeaturePEW(wave, flux, bin_flux)[source]

Represents the pEW calculation for a spectroscopic feature

__init__(wave, flux, bin_flux)[source]

Calculates the pEW of a spectroscopic feature

Parameters:
  • wave (ndarray) – The wavelength values of the feature
  • flux (ndarray) – The flux values for the feature
  • bin_flux (ndarray) – The binned flux values for the feature
continuum

Array of values for the fitted sudo continuum

norm_flux

The flux normalized by the sudo continuum

pew

Calculate the pseudo equivalent-width of the feature

Returns:The pseudo equivalent-width of the feature
class spec_analysis.features.FeatureVelocity(wave, flux, bin_flux, rest_frame)[source]

Represents the velocity calculation for a spectroscopic feature

__init__(wave, flux, bin_flux, rest_frame)[source]

Calculates the pEW of a spectroscopic feature

Parameters:
  • wave (ndarray) – The wavelength values of the feature
  • flux (ndarray) – The flux values for each feature
gauss_amplitude

The fitted gaussian amplitude

gauss_avg

The fitted gaussian average

gauss_offset

The fitted gaussian offset

gauss_stddev

The fitted gaussian standard deviation

gaussian_fit()[source]

Evaluate the gaussian fit of the normalized flux for feature wavelengths

Returns:An array of normalized flux values
velocity

Calculate the velocity of a feature

Fit a feature with a negative gaussian and determine the feature’s velocity. Returned value is np.nan if the fit fails.

Returns:The velocity of the feature in km / s
class spec_analysis.features.ObservedFeature(wave, flux, bin_flux, rest_frame)[source]

Represents a spectral observation spanning a single absorption feature

__init__(wave, flux, bin_flux, rest_frame)[source]

Represents a spectral observation spanning a single absorption feature

Parameters:
  • wave (ndarray) – The wavelength values of the feature
  • flux (ndarray) – The flux values for each feature