LineDetect.continuum_finder
Created on Wed Apr 1 10:14:10 2023
@author: daniel
Module Contents
Classes
Generates the continuum and continuun error. |
Functions
|
Fits a Legendre polynomial to a given spectrum so as to estimate the continuum. |
|
Calculates the F-test result for two chi-square values and degrees of freedom. |
|
Calculates a linear combination of Legendre Polynomials up to a given degree. |
|
Calculates the chi-squared error between two fits. |
- class LineDetect.continuum_finder.Continuum(Lambda, flux, flux_err, halfWindow=25, region_size=150, resolution_element=3, savgol_window_size=100, savgol_poly_order=5, N_sig_limits=0.5, N_sig_line2=3)[source]
Generates the continuum and continuun error.
- Parameters:
Lambda (np.ndarray) – Array of wavelengths.
flux (np.ndarray) – Array of self.flux values.
flux_err (np.ndarray) – Array of uncertainties in the self.flux values.
halfWindow (int) – The half-window size to use for the smoothing procedure. If this is a list/array of integers, then the continuum will be calculated as the median curve across the fits across all half-window sizes in the list/array. Defaults to 25.
N_sig_line2 (int) – Defaults to 3.
region_size (int) – The size of the region to apply the polynomial fitting. Defaults to 150 pixels.
resolution_element (int) – Defaults to 3.
savgol_window_size (int) – Defaults to 100. Can be set to 0 to skip the final savgol filtering.
savgol_poly_order (int) – Defaults to 5. Only applicable if savgol_window_size is greater than 0.
- estimate(fit_legendre=True)[source]
Fits the spectra continuum using a robust moving median followed by a Legendre polynomial fit.
- Parameters:
fit_legendre (bool) – Whether to fit with Legendre polynomials for a more robust estimate. Defaults to True.
- Returns:
Generates the continuum and continuum_err class attributes.
- median_filter()[source]
Smooths out the flux array with a robust median-based filter
- Returns:
Creates the continuum and continuum_err attributes.
- legendreContinuum(max_order, p_threshold)[source]
Fits a Legendre polynomial to a spectrum to locate absorption and/or emission features.
The function identifies absorption or emission features in the input spectrum using the featureFinder function, then extends thefl spectrum on both sides to avoid running out of bounds. For each feature, it selects a region of size region_size pixels around it and fits a Legendre polynomial to this region. If there are two features less than region_size pixels apart, the function computes the gap between them and includes the pixels between the features in the fitting array. The function returns an array of the fitted continuum values.
- Parameters:
- Returns:
Updates the existing continuum and continuum_err class attributes.
- LineDetect.continuum_finder.legendreFit(indices, Lambda, flux, sigFlux, region_size, max_order, p_threshold)[source]
Fits a Legendre polynomial to a given spectrum so as to estimate the continuum.
- Parameters:
indices (np.ndarray) – The x-values of the spectrum to be fit.
Lambda (np.ndarray) – The x-values of the extended spectrum.
flux (np.ndarray) – The y-values of the spectrum to be fit.
sigFlux (np.ndarray) – The uncertainties in the y-values.
region_size (int) – The number of points on either side of a given point to use in the fit.
max_order (int) – The maximum order of the Legendre polynomial to fit. Defaults to 20.
p_threshold (float) – The p-value threshold for the F-test. If the p-value is greater than this threshold, the fit is considered acceptable and the continuum level is returned. Defaults to 0.05.
- Returns:
The continuum level of the spectrum.
- LineDetect.continuum_finder.FTest(chiSq1: float, chiSq2: float, df: int) float[source]
Calculates the F-test result for two chi-square values and degrees of freedom.
- LineDetect.continuum_finder.legendreLinCom(coeff: numpy.ndarray, x: numpy.ndarray) numpy.ndarray[source]
Calculates a linear combination of Legendre Polynomials up to a given degree.
- Parameters:
coeff (np.ndarray) – Coefficients of the Legendre Polynomials.
x (np.ndarray) – Array of x values at which to evaluate the polynomial.
- Returns:
Values of the polynomial at the given x values.
- LineDetect.continuum_finder.legendreChiSq(coeff: numpy.ndarray, x: numpy.ndarray, y: numpy.ndarray, sigy: numpy.ndarray) float[source]
Calculates the chi-squared error between two fits.
This function works by looping through each element of the x-values (derived from the wavelength) in the window and performing the following steps for each element:
- Finding the continuum, which is a linear combination of Legendre polynomials up to a certain degree M. This
is done in an inner loop.
Using the continuum and the y-values and uncertainties (I, sig I) to calculate the chi-squared error.
Repeating these steps for the next x-value.
- Parameters:
coeff (np.ndarray) – The coefficients of the Legendre polynomial fit.
x (np.ndarray) – The x-values of the data (the wavelength in this context).
y (np.ndarray) – The y-values of the data (the flux in this context).
sigy (np.ndarray) – The uncertainties in the y-values.
- Returns:
The chi-squared error.