wdtools.gfp
¶
Module Contents¶
Classes¶
Generative Fitting Pipeline. |
Functions¶
|
Attributes¶
- wdtools.gfp.path¶
- wdtools.gfp.dir_path¶
- wdtools.gfp.interp1d¶
- wdtools.gfp.halpha = 6564.61¶
- wdtools.gfp.hbeta = 4862.68¶
- wdtools.gfp.hgamma = 4341.68¶
- wdtools.gfp.hdelta = 4102.89¶
- wdtools.gfp.planck_h = 6.62607004e-34¶
- wdtools.gfp.speed_light = 299792458¶
- wdtools.gfp.k_B = 1.38064852e-23¶
- wdtools.gfp.find_nearest(array, value)¶
- class wdtools.gfp.GFP(resolution=3, specclass='DA')¶
Generative Fitting Pipeline.
- label_sc(self, label_array)¶
Label scaler to transform Teff and logg to [0,1] interval based on preset bounds.
- Parameters
label_array (array) – Unscaled array with Teff in the first column and logg in the second column
- Returns
Scaled array
- Return type
array
- inv_label_sc(self, label_array)¶
Inverse label scaler to transform Teff and logg from [0,1] to original scale based on preset bounds.
- Parameters
label_array (array) – Scaled array with Teff in the first column and logg in the second column
- Returns
Unscaled array
- Return type
array
- spec_sc(self, spec)¶
- inv_spec_sc(self, spec)¶
- generator(self, H, n_pix)¶
- synth_spectrum_sampler(self, wl, teff, logg, rv, specclass=None)¶
Generates synthetic spectra from labels using the neural network, translated by some radial velocity. These are _not_ interpolated onto the requested wavelength grid; The interpolation is performed only one time after the Gaussian convolution with the instrument resolution in GFP.spectrum_sampler. Use GFP.spectrum_sampler in most cases.
- Parameters
wl (array) – Array of spectral wavelengths (included for completeness, not used by this function)
teff (float) – Effective surface temperature of sampled spectrum
logg (float) – log surface gravity of sampled spectrum (cgs)
rv (float) – Radial velocity (redshift) of sampled spectrum in km/s
specclass (str ['DA', 'DB']) – Whether to use hydrogen-rich (DA) or helium-rich (DB) atmospheric models. If None, uses default.
- Returns
Synthetic spectrum with desired parameters, interpolated onto the supplied wavelength grid.
- Return type
array
- spectrum_sampler(self, wl, teff, logg, *polyargs, specclass=None)¶
Wrapper function that talks to the generative neural network in scaled units, and also performs the Gaussian convolution to instrument resolution.
- Parameters
wl (array) – Array of spectral wavelengths on which to generate the synthetic spectrum
teff (float) – Effective surface temperature of sampled spectrum
logg (float) – log surface gravity of sampled spectrum (cgs)
polyargs (float, optional) – All subsequent positional arguments are assumed to be coefficients for the additive Chebyshev polynomial. If none are provided, no polynomial is added to the model spectrum.
specclass (str, optional) – Whether to use hydrogen-rich (DA) or helium-rich (DB) atmospheric models. If none, reverts to default.
- Returns
Synthetic spectrum with desired parameters, interpolated onto the supplied wavelength grid and convolved with the instrument resolution.
- Return type
array
- spline_norm_DA(self, wl, fl, ivar, kwargs=dict(k=3, sfac=1, niter=3), crop=None)¶
Masks out Balmer lines, fits a smoothing spline to the continuum, and returns a continuum-normalized spectrum
- Parameters
wl (array) – Array of observed spectral wavelengths.
fl (array) – Array of observed spectral fluxes.
ivar (array) – Array of observed inverse-variance.
kwargs (dict, optional) – Keyword arguments that are passed to the spline normalization function
crop (tuple, optional) – Defines a start and end wavelength to crop the spectrum to before continuum-normalization.
- Returns
If crop is None, returns a 2-tuple of (normalized_flux, normalized_ivar). If a crop region is provided, then returns a 3-tuple of (cropped_wavelength, cropped_normalized_flux, cropped_normalized_ivar).
- Return type
tuple
- fit_spectrum(self, wl, fl, ivar=None, prior_teff=None, mcmc=False, fullspec=False, polyorder=0, norm_kw=dict(k=1, sfac=0.5, niter=0), nwalkers=25, burn=25, ndraws=25, threads=1, progress=True, plot_init=False, make_plot=True, plot_corner=False, plot_corner_full=False, plot_trace=False, savename=None, DA=True, crop=(3600, 7500), verbose=True, lines=['alpha', 'beta', 'gamma', 'delta', 'eps', 'h8'], lmfit_kw=dict(method='leastsq', epsfcn=0.1), rv_kw=dict(plot=False, distance=100, nmodel=2, edge=15), nteff=3, rv_line='alpha', corr_3d=False)¶
Main fitting routine, takes a continuum-normalized spectrum and fits it with MCMC to recover steller labels.
- Parameters
wl (array) – Array of observed spectral wavelengths
fl (array) – Array of observed spectral fluxes, continuum-normalized. We recommend using the included normalize_balmer function from wdtools.spectrum to normalize DA spectra, and the generic continuum_normalize function for DB spectra.
ivar (array) – Array of observed inverse-variance for uncertainty estimation. If this is not available, use ivar = None to infer a constant inverse variance mask using a second-order beta-sigma algorithm. In this case, since the errors are approximated, the chi-square likelihood may be inexact - treat returned uncertainties with caution.
prior_teff (tuple, optional) – Tuple of (mean, sigma) to define a Gaussian prior on the effective temperature parameter. This is especially useful if there is strong prior knowledge of temperature from photometry. If not provided, a flat prior is used.
mcmc (bool, optional) – Whether to run MCMC, or simply return the errors estimated by LMFIT
fullspec (bool, optional) – Whether to fit the entire continuum-normalized spectrum, or only the Balmer lines.
polyorder (int, optional) – Order of additive Chebyshev polynomial during the fitting process. Can usually leave this to zero unless the normalization is really bad.
norm_kw (dict, optional) – Dictionary of keyword arguments that are passed to the spline normalization routine.
nwalkers (int, optional) – Number of independent MCMC ‘walkers’ that will explore the parameter space
burn (int, optional) – Number of steps to run and discard at the start of sampling to ‘burn-in’ the posterior parameter distribution. If intitializing from a high-probability point, keep this value high to avoid under-estimating uncertainties.
ndraws (int, optional) – Number of ‘production’ steps after the burn-in. The final number of posterior samples will be nwalkers * ndraws.
threads (int, optional) – Number of threads for distributed sampling.
progress (bool, optional) – Whether to show a progress bar during the MCMC sampling.
plot_init (bool, optional) – Whether to plot the continuum-normalization routine
make_plot (bool, optional) – If True, produces a plot of the best-fit synthetic spectrum over the observed spectrum.
plot_corner (bool, optional) – Makes a corner plot of the fitted stellar labels
plot_corner_full (bool, optional) – Makes a corner plot of all sampled parameters, the stellar labels plus any Chebyshev coefficients if polyorder > 0
plot_trace (bool, optiomal) – If True, plots the trace of posterior samples of each parameter for the production steps. Can be used to visually determine the quality of mixing of the chains, and ascertain if a longer burn-in is required.
savename (str, optional) – If provided, the corner plot and best-fit plot will be saved as PDFs in the working folder.
DA (bool, optional) – Whether the star is a DA white dwarf or not. As of now, this must be set to True.
crop (tuple, optional) – The region to crop the supplied spectrum before proceeding with the fit. Can be used to exclude low-SN regions at the edge of the spectrum.
verbose (bool, optional) – If True, the routine prints several progress statements to the terminal.
lines (array, optional) – List of Balmer lines to utilize in the fit. Defaults to all from H-alpha to H8.
lmfit_kw (dict, optional) – Dictionary of keyword arguments to the LMFIT solver
rv_kw (dict, optional) – Dictionary of keyword arguments to the RV fitting routine
nteff (int, optional) – Number of equidistant temperatures to try as initialization points for the minimization routine.
rv_line (str, optional) – Which Balmer line to use for the radial velocity fit. We recommend ‘alpha’.
corr_3d (bool, optional) – If True, applies 3D corrections from Tremblay et al. (2013) to stellar parameters before returning them.
- Returns
Returns the fitted stellar labels along with a reduced chi-square statistic with the format: [[labels], [e_labels], redchi]. If polyorder > 0, then the returned arrays include the Chebyshev coefficients. The radial velocity (and RV error) are always the last elements in the array, so if polyorder > 0, the label array will have temperature, surface gravity, the Chebyshev coefficients, and then RV.
- Return type
array
- wdtools.gfp.gfp¶