Tool functions
Functions that perform most of the math.
- spookyspec.tools.calc_snr(x, y, ycont, w1, w2)
Calculate SNR
Calculate the signal-to-noise ratio of a spectrum.
- Parameters
x (np.array) – wavelength values of the spectrum
y (np.array) – flux values of the spectrum
ycont (np.array) – flux values of the continuum
w1 (float) – starting wavelength with same units as x
w2 (float) – ending wavelength with same units as x
- Returns
the SNR of the spectrum
- Return type
(float)
- spookyspec.tools.convert_line(x, y, ycont, lam)
change coordinate system so line center is at zero, continuum is zero, and absorption is positive this is to make fitting easier
- spookyspec.tools.ddx(x, y)
Derivative
Numerical derivitive with np.gradient
- Parameters
x (array-like) – x values
y (array-like) – y values
- Returns
x values (np.array): derivative of x and y
- Return type
(np.array)
- spookyspec.tools.equivalent_width(x, y, ycont, w1, w2, unit, plot=False)
Equivalent width
Measure the equivalent width of a region of the spectrum
- Parameters
x (np.array) – wavelength values of the spectrum
y (np.array) – flux values of the spectrum
ycont (np.array) – flux values of the continuum
w1 (float) – starting wavelength
w2 (float) – ending wavelength
unit (astropy.units.Unit) – units of x, w1, and w2
- Keyword Arguments
plot (bool) – whether or not to plot the spectrum
- Returns
equivalent width of region
- Return type
(astropy.Quantity)
- spookyspec.tools.equivalent_width_error(x, y, ycont, W1, W2, unit)
Equivalent width error
Estimate the uncertainty in the equivalent width of a region
- Parameters
x (np.array) – wavelength values of the spectrum
y (np.array) – flux values of the spectrum
ycont (np.array) – flux values of the continuum
W1 (float) – starting wavelength
W2 (float) – ending wavelength
unit (astropy.units.Unit) – units of x, W1, and W2
- Returns
equivalent width uncertainty of region
- Return type
(astropy.Quantity)
- spookyspec.tools.get_continuum(x, y, w1, w2, **kwargs)
Get continuum
Fit the continuum of a spectrum
- Parameters
x –
fit a polynomial f to the continuum and return the array f(x) between the wavelengths w1,w2
- spookyspec.tools.get_continuum_points(x, y, **kwargs)
Get continuum points
Get a boolean array indicating which points are part of the continuum
- Parameters
x (np.array) – wavelength values of the spectrum
y (np.array) – flux values of the spectrum
- Keyword Arguments
pct (float in range [0,1]) – residual cutoff percentile. Default 0.85
box (int) – radius of surrounding points to check. Default 5
degree (int) – fitting degree. Default 1
cutoff (float) – second derivitive cutoff for fitting a model continuum. Default 1e-12
stype (str) – data or model. Type of spectrum to fit continuum. Default data
- Returns
points that part of the spectral continuum
- Return type
(np.array of bool)
- spookyspec.tools.poly_x(x, coeffs)
Polynomial
Transform an array of x values given coefficients of a polynomial function
- Parameters
x (np.array) – values to be transformed
coeffs (array-like) – coefficents of the polynomical function starting with the highest order
- Returns
y values of the polynomial function
- Return type
(np.array)
- spookyspec.tools.redshift(l, v)
Redshift
Get the doppler shifted wavelength of a line given the linecenter wavelength and radial velocity
- Parameters
l (astropy.Quantity) – wavelength to be shifted
v (astropy.Quantity) – radial velocity
- Returns
red/blue shifted wavelength
- Return type
(astropy.Quantity)
- spookyspec.tools.reject(x, y, **kwargs)
Reject Rejection procedure for finding the continuum of a spectrum works best if y has some noise
- Parameters
x (np.array) – wavelength values of the spectrum
y (np.array) – flux values of the spectrum
- Keyword Arguments
pct (float in range [0,1]) – residual cutoff percentile. Default 0.85
box (int) – radius of surrounding points to check. Default 5
degree (int) – fitting degree. Default 1
- Returns
points that part of the spectral continuum
- Return type
(np.array of bool)
- spookyspec.tools.to_air(vac)
To air
Convert from vacuum to air wavelengths
- Parameters
vac (astropy.Quantity) – wavelength(s) to be shifted
- Returns
wavelength(s) in air
- Return type
(astropy.Quantity)
- spookyspec.tools.trap_rule(x, f)
Trapazoid rule
Integrate using Trapizoid rule.
- Parameters
x (array-like) – x values to integrate over
f (array-like) – y values to integrate over
- Returns
(float) integral of f over the domain of x