WDmodel.viz module¶
Routines to visualize the DA White Dwarf model atmosphere fit
-
WDmodel.viz.
plot_mcmc_line_fit
(spec, linedata, model, cont_model, draws, balmer=None)[source]¶ Plot a comparison of the normalized hydrogen Balmer lines of the spectrum and model
Note that we fit the full spectrum, not just the lines. The lines are extracted using a coarse continuum fit in
WDmodel.fit.pre_process_spectrum()
. This fit is purely cosmetic and in no way contributes to the likelihood. It’s particularly useful to detect small velocity offsets or wavelength calibration errors.- Parameters
spec (
numpy.recarray
) – The spectrum. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
linedata (
numpy.recarray
) – The observations of the spectrum corresponding to the hydrogen Balmer lines. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8'), ('line_mask', 'i4'), ('line_ind', 'i4')]
model (
WDmodel.WDmodel.WDmodel
instance) – The DA White Dwarf SED model generatorcont_model (
numpy.recarray
) – The continuuum model. Must have the same structure asspec
Produced byWDmodel.fit.pre_process_spectrum()
draws (array-like) – produced by
plot_mcmc_spectrum_fit()
- see notes for content.balmer (array-like, optional) – list of Balmer lines to plot - elements must be in range
[1, 6]
These correspond to the lines defined inWDmodel.WDmodel.WDmodel._lines
. Default isrange(1, 7)
- Returns
fig (
matplotlib.figure.Figure
instance) – The output figure containing the line profile plotfig2 (
matplotlib.figure.Figure
instance) – The output figure containing histograms of the line residuals
See also
-
WDmodel.viz.
plot_mcmc_model
(spec, phot, linedata, scale_factor, phot_dispersion, objname, outdir, specfile, model, covmodel, cont_model, pbs, params, param_names, samples, samples_lnprob, covtype='Matern32', balmer=None, ndraws=21, everyn=1, savefig=False)[source]¶ Make all the plots to visualize the full fit of the DA White Dwarf data
Wraps
plot_mcmc_spectrum_fit()
,plot_mcmc_photometry_res()
,plot_mcmc_spectrum_nogp_fit()
,plot_mcmc_line_fit()
andcorner.corner()
and saves all the plots to a combined PDF, and optionally individual PDFs.- Parameters
spec (
numpy.recarray
) – The spectrum. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
phot (None or
numpy.recarray
) – The photometry. Must havedtype=[('pb', 'str'), ('mag', '<f8'), ('mag_err', '<f8')]
linedata (
numpy.recarray
) – The observations of the spectrum corresponding to the hydrogen Balmer lines. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8'), ('line_mask', 'i4'), ('line_ind', 'i4')]
scale_factor (float) – factor by which the flux was scaled for y-axis label
phot_dispersion (float, optional) – Excess photometric dispersion to add in quadrature with the photometric uncertainties
phot.mag_err
. Use if the errors are grossly underestimated. Default is0.
objname (str) – object name - used to title plots
outdir (str) – controls where the plot is written out if
savefig=True
specfile (str) – Used in the title, and to set the name of the
outfile
ifsavefig=True
model (
WDmodel.WDmodel.WDmodel
instance) – The DA White Dwarf SED model generatorcovmodel (
WDmodel.covariance.WDmodel_CovModel
instance) – The parametrized model for the covariance of the spectrumspec
cont_model (
numpy.recarray
) – The continuuum model. Must have the same structure asspec
Produced byWDmodel.fit.pre_process_spectrum()
pbs (dict) – Passband dictionary containing the passbands corresponding to
phot.pb
and generated byWDmodel.passband.get_pbmodel()
.params (dict) – dictionary of parameters with keywords
value
,fixed
,scale
,bounds
for each. Same format as returned fromWDmodel.io.read_params()
param_names (array-like) – Ordered list of free parameter names
samples (array-like) – Samples from the flattened Markov Chain with shape
(N, len(param_names))
samples_lnprob (array-like) – Log Posterior corresponding to
samples
from the flattened Markov Chain with shape(N,)
covtype (
{'Matern32', 'SHO', 'Exp', 'White'}
) – stationary kernel type used to parametrize the covariance inWDmodel.covariance.WDmodel_CovModel
balmer (array-like, optional) – list of Balmer lines to plot - elements must be in range
[1, 6]
These correspond to the lines defined inWDmodel.WDmodel.WDmodel._lines
. Default isrange(1, 7)
ndraws (int, optional) – Number of draws to make from the Markov Chain to overplot. Higher numbers provide a better sense of the uncertainty in the model at the cost of speed and a larger, slower to render output plot.
everyn (int, optional) – If the posterior function was evaluated using only every nth observation from the data, this should be specified to visually indicate the observations used.
savefig (bool) – if True, save the individual figures
- Returns
model_spec (
numpy.recarray
) – The model spectrum. Hasdtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8'), ('norm_flux', '<f8')]
and same shape as inputspec
. Thenorm_flux
attribute has the model flux without the Gaussian process prediction applied.SED_model (
numpy.recarray
) – The SED model spectrum. Hasdtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
model_mags (None or
numpy.recarray
) – If there is observed photometry, this contains the model magnitudes. Hasdtype=[('pb', 'str'), ('mag', '<f8')]
-
WDmodel.viz.
plot_mcmc_photometry_res
(objname, phot, phot_dispersion, model, pbs, draws)[source]¶ Plot the observed DA white dwarf photometry as well as the “best-fit” model magnitudes
- Parameters
objname (str) – object name - used to title plots
phot (None or
numpy.recarray
) – The photometry. Must havedtype=[('pb', 'str'), ('mag', '<f8'), ('mag_err', '<f8')]
phot_dispersion (float, optional) – Excess photometric dispersion to add in quadrature with the photometric uncertainties
phot.mag_err
. Use if the errors are grossly underestimated. Default is0.
model (
WDmodel.WDmodel.WDmodel
instance) – The DA White Dwarf SED model generatorpbs (dict) – Passband dictionary containing the passbands corresponding to
phot.pb
and generated byWDmodel.passband.get_pbmodel()
.draws (array-like) – produced by
plot_mcmc_spectrum_fit()
- see notes for content.
- Returns
fig (
matplotlib.figure.Figure
instance) – The output figuremag_draws (array-like) – The magnitudes corresponding to the parameters
draws
from the Markov Chain used infig
Notes
- Each element of
mag_draws
contains wres
- the difference between the observed and synthetic magnitudesmodel_mags
- the model magnitudes corresponding to the current model parametersmu
- the flux normalization parameter that must be added to themodel_mags
See also
-
WDmodel.viz.
plot_mcmc_spectrum_fit
(spec, objname, specfile, scale_factor, model, covmodel, result, param_names, samples, ndraws=21, everyn=1)[source]¶ Plot the spectrum of the DA White Dwarf and the “best fit” model
The full fit parametrizes the covariance model using a stationary Gaussian process as defined by
WDmodel.covariance.WDmodel_CovModel
. The posterior function constructed inWDmodel.likelihood.WDmodel_Posterior
is evaluated by the sampler in theWDmodel.fit.fit_model()
method. The median value is reported as the best-fit value for each of the fit parameters inWDmodel.likelihood.WDmodel_Likelihood.parameter_names
.- Parameters
spec (
numpy.recarray
) – The spectrum. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
objname (str) – object name - used to title plots
outdir (str) – controls where the plot is written out if
save=True
specfile (str) – Used in the title, and to set the name of the
outfile
ifsave=True
scale_factor (float) – factor by which the flux was scaled for y-axis label
model (
WDmodel.WDmodel.WDmodel
instance) – The DA White Dwarf SED model generatorcovmodel (
WDmodel.covariance.WDmodel_CovModel
instance) – The parametrized model for the covariance of the spectrumspec
result (dict) – dictionary of parameters with keywords
value
,fixed
,scale
,bounds
for each. Same format as returned fromWDmodel.io.read_params()
param_names (array-like) – Ordered list of free parameter names
samples (array-like) – Samples from the flattened Markov Chain with shape
(N, len(param_names))
ndraws (int, optional) – Number of draws to make from the Markov Chain to overplot. Higher numbers provide a better sense of the uncertainty in the model at the cost of speed and a larger, slower to render output plot.
everyn (int, optional) – If the posterior function was evaluated using only every nth observation from the data, this should be specified to visually indicate the observations used.
- Returns
fig (
matplotlib.figure.Figure
instance) – The output figuredraws (array-like) – The actual draws from the Markov Chain used in
fig
Notes
It’s faster to draw samples from the posterior in one location, and pass along the same samples to all the methods in
WDmodel.viz
.Consequently, most require
draws
as an input. This makes all the plots connected, and none will return if an error is thrown here, but this is the correct behavior as all of them are visualizing one aspect of the same fit.- Each element of
draws
contains smoothedmod
- the model spectrumwres
- the prediction from the Gaussian processwres_err
- the diagonal of the covariance matrix for the prediction from the Gaussian processfull_mod
- the full model SED, in order to compute the synthetic photometryout_draw
- the dictionary of model parameters from this draw. Same format asresult
.
-
WDmodel.viz.
plot_mcmc_spectrum_nogp_fit
(spec, objname, specfile, scale_factor, cont_model, draws, covtype='Matern32', everyn=1)[source]¶ Plot the spectrum of the DA White Dwarf and the “best fit” model without the Gaussian process
Unlike
plot_mcmc_spectrum_fit()
this version does not apply the prediction from the Gaussian process to the spectrum model to match the observed spectrum. This visualization is useful to indicate if the Gaussian process - i.e. the kernel choicecovtype
used to parametrize the covariance is - is appropriate.- Parameters
spec (
numpy.recarray
) – The spectrum. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
objname (str) – object name - used to title plots
outdir (str) – controls where the plot is written out if
save=True
specfile (str) – Used in the title, and to set the name of the outfile if
save=True
scale_factor (float) – factor by which the flux was scaled for y-axis label
cont_model (
numpy.recarray
) – The continuuum model. Must have the same structure asspec
Produced byWDmodel.fit.pre_process_spectrum()
draws (array-like) – produced by
plot_mcmc_spectrum_fit()
- see notes for content.covtype (
{'Matern32', 'SHO', 'Exp', 'White'}
) – stationary kernel type used to parametrize the covariance inWDmodel.covariance.WDmodel_CovModel
everyn (int, optional) – If the posterior function was evaluated using only every nth observation from the data, this should be specified to visually indicate the observations used.
- Returns
fig – The output figure
- Return type
matplotlib.figure.Figure
instance
See also
-
WDmodel.viz.
plot_minuit_spectrum_fit
(spec, objname, outdir, specfile, scale_factor, model, result, save=True)[source]¶ Plot the MLE fit of the spectrum with the model, assuming uncorrelated noise.
- Parameters
spec (
numpy.recarray
) – The spectrum. Must havedtype=[('wave', '<f8'), ('flux', '<f8'), ('flux_err', '<f8')]
objname (str) – object name - used to title plots
outdir (str) – controls where the plot is written out if
save=True
specfile (str) – Used in the title, and to set the name of the
outfile
ifsave=True
scale_factor (float) – factor by which the flux was scaled for y-axis label
model (
WDmodel.WDmodel.WDmodel
instance) – The DA White Dwarf SED model generatorresult (dict) – dictionary of parameters with keywords
value
,fixed
,scale
,bounds
for each. Same format as returned fromWDmodel.io.read_params()
save (bool) – if True, save the file
- Returns
fig
- Return type
matplotlib.figure.Figure
instance
Notes
The MLE fit uses
iminuit.Minuit.migrad()
to fit the spectrum with the model. This fit doesn’t try to account for the covariance in the data, and is not expected to be great - just fast, and capable of setting a reasonable initial guess. If it is apparent from the plot that this fit is very far off, refine the initial guess to the fitter.