wdtools.parametric
¶
Module Contents¶
Classes¶
Class to fit Voigt profiles to the Balmer absorption lines of DA white dwarfs, and then infer stellar labels. |
Attributes¶
- wdtools.parametric.path¶
- wdtools.parametric.dir_path¶
- class wdtools.parametric.LineProfiles(verbose=False, plot_profiles=False, n_trees=25, n_bootstrap=25, lines=['alpha', 'beta', 'gamma', 'delta'], optimizer='leastsq')¶
Class to fit Voigt profiles to the Balmer absorption lines of DA white dwarfs, and then infer stellar labels.
Probabilistic prediction uses 100 boostrapped random forest models with 25 trees each, trained on 5326 spectra from the Sloan Digital Sky Survey. Ground truth labels are taken from Tremblay et al. (2019) Line profiles are fit using the LMFIT package via chi^2 minimization.
- linear(self, wl, p1, p2)¶
- chisquare(self, residual)¶
- initialize(self)¶
Initializes the random forest models by training them on the pre-supplied dataset of parameters. This only needs to be done once for each combination of absorption lines. The model is then pickled and saved for future use in the models/ directory.
- fit_line(self, wl, flux, centroid, window=400, edges=200, make_plot=False)¶
Fit a Voigt profile around a specified centroid on the spectrum.
The continuum is normalized at each absorption line via a simple linear polynimial through the edges. Window size and edge size can be modified.
- Parameters
wl (array) – Wavelength array of spectrum
flux (array) – Flux array of spectrum
centroid (float) – The theoretical centroid of the absorption line that is being fitted, in wavelength units.
window (float, optional) – How many Angstroms away from the line centroid are included in the fit (in both directions). This should be large enough to include the absorption line as well as some continuum on either side.
edges (float, optional) – What distance in Angstroms around each line (measured from the line center outwards) to exclude from the continuum-fitting step. This should be large enough to cover most of the absorption line whilst leaving some continuum intact on either side.
make_plot (bool, optional) – Make a plot of the fit.
- Returns
A result instance from the lmfit package, from which fitted parameters and fit statistics can be extracted.
- Return type
lmfit result object
- fit_balmer(self, wl, flux, make_plot=False)¶
Fits Voigt profiles to the first three Balmer lines (H-alpha, H-beta, and H-gamma). Returns all 18 fitted parameters.
- Parameters
wl (array) – Wavelength array of spectrum
flux (array) – Flux array of spectrum
make_plot (bool, optional) – Plot all individual Balmer fits.
- Returns
Array of 18 Balmer parameters, 6 for each line. If the profile fit fails, returns array of 18 np.nan values.
- Return type
array
- train(self, x_data, y_data)¶
Trains ensemble of random forests on the provided data. Does not require scaling. You shouldn’t ever need to use this directly.
- Parameters
x_data (array) – Input data, independent variables
y_data (array) – Output data, dependent variables
- labels_from_parameters(self, balmer_parameters, quantile=0.67)¶
Predicts stellar labels from Balmer line parameters.
- Parameters
balmer_parameters (array) – Array of fitted Balmer parameters from the fit_balmer function.
- Returns
Array of predicted stellar labels with the following format: [Teff, e_Teff, logg, e_logg].
- Return type
array
- save(self, modelname='wd')¶
- load(self, modelname='wd')¶
- labels_from_spectrum(self, wl, flux, make_plot=False, quantile=0.67)¶
Wrapper function that directly predicts stellar labels from a provided spectrum. Performs continuum-normalization, fits Balmer profiles, and uses the bootstrap ensemble of random forests to infer labels.
- Parameters
wl (array) – Array of spectrum wavelengths.
fl (array) – Array of spectrum fluxes. Can be normalized or un-normalized.
make_plot (bool, optional) – Plot all the individual Balmer-Voigt fits.
quantile (float, optional) – Which quantile of the fitted labels to use for the bootstrap error estimation. Defaults to 0.67, which corresponds to a 1-sigma uncertainty.
- Returns
Array of predicted stellar labels with the following format: [Teff, e_Teff, logg, e_logg].
- Return type
array