MEModel¶
- class measure_extinction.model.MEModel(modinfo=None, obsdata=None, logf=False)[source]¶
Bases:
objectModel object for the measure_extinction fitting. Includes all parameters and useful functions. Inspired by astropy modeling.
Initialize the object, optionally using the min/max of the input model info to set the value and bounds on the stellar parameters
- Parameters:
- modinfoModelData object
all the information about the model spectra
- obsdataStarData object
observed data for a reddened star
Attributes Summary
Methods Summary
add_exclude_region(exreg)Add an exclude region to the list of such regions.
Check the parameters are within the parameter bounds
dust_extinguished_sed(moddata, sed)Dust extinguished sed given the extinction parameters
fit_minimizer(obsdata, modinfo[, maxiter])Run a minimizer (formally an optimizer) to find the best fit parameters by finding the minimum chisqr solution.
fit_sampler(obsdata, modinfo[, nsteps, ...])Run a samplier (specifically emcee) to find the detailed parameters including uncertainties.
fit_to_parameters(fit_params[, uncs])Set the parameter values based on a vector of the non-fixed values.
fit_weights(obsdata)Compute the weight to be used for fitting.
Get the non-fixed parameter names.
hi_abs_sed(moddata, sed)HI abs sed given the HI columns
lnlike(obsdata, modeldata)Compute the natural log of the likelihood that the data fits the model.
lnprior()Compute the natural log of the priors.
lnprob(obsdata, modeldata)Compute the natural log of the probability
Give all the parameters values in a vector (fixed or not).
Give the non-fixed parameters values in a vector.
plot(obsdata, modinfo[, resid_range, ...])Standard plot showing the data and best fit.
plot_sampler_chains(sampler)Plot the samplier chains.
plot_sampler_corner(flat_samples)Plot the standard corner plot.
Print the parameters with names and values
save_parameters([filename])Save the parameters and uncertainties to a table.
set_initial_norm(obsdata, modeldata)Set the initial normalization that puts the current model at the average level of the observed data.
stellar_sed(moddata)Compute the stellar SED from the model parameters.
Attributes Documentation
- Av = <measure_extinction.model.MEParameter object>¶
- B3 = <measure_extinction.model.MEParameter object>¶
- C2 = <measure_extinction.model.MEParameter object>¶
- C4 = <measure_extinction.model.MEParameter object>¶
- Rv = <measure_extinction.model.MEParameter object>¶
- exclude_regions = <Quantity [[ 8.18, 8.28], [ 8.7 , 10. ], [ 3.55, 3.6 ], [ 3.8 , 3.9 ], [ 4.15, 4.3 ], [ 6.4 , 6.6 ], [ 7.1 , 7.3 ], [ 7.45, 7.55], [ 7.65, 7.75], [ 7.9 , 7.95], [ 8.05, 8.1 ]] 1 / micron>¶
- fore_Av = <measure_extinction.model.MEParameter object>¶
- fore_Rv = <measure_extinction.model.MEParameter object>¶
- fore_sampling = False¶
- g23_all_ext = False¶
- gamma = <measure_extinction.model.MEParameter object>¶
- lnp_bignum = -inf¶
- logHI_MW = <measure_extinction.model.MEParameter object>¶
- logHI_exgal = <measure_extinction.model.MEParameter object>¶
- logTeff = <measure_extinction.model.MEParameter object>¶
- logZ = <measure_extinction.model.MEParameter object>¶
- logg = <measure_extinction.model.MEParameter object>¶
- norm = <measure_extinction.model.MEParameter object>¶
- paramnames = ['logTeff', 'logg', 'logZ', 'vturb', 'velocity', 'windamp', 'windalpha', 'Av', 'Rv', 'C2', 'B3', 'C4', 'xo', 'gamma', 'vel_MW', 'logHI_MW', 'fore_Av', 'fore_Rv', 'vel_exgal', 'logHI_exgal', 'norm']¶
- rng = Generator(PCG64) at 0x72499D65AEA0¶
- vel_MW = <measure_extinction.model.MEParameter object>¶
- vel_exgal = <measure_extinction.model.MEParameter object>¶
- velocity = <measure_extinction.model.MEParameter object>¶
- vturb = <measure_extinction.model.MEParameter object>¶
- windalpha = <measure_extinction.model.MEParameter object>¶
- windamp = <measure_extinction.model.MEParameter object>¶
- xo = <measure_extinction.model.MEParameter object>¶
Methods Documentation
- add_exclude_region(exreg)[source]¶
Add an exclude region to the list of such regions.
- Parameters:
- exreglist
2 element list with min/max given in 1/micron
- dust_extinguished_sed(moddata, sed)[source]¶
Dust extinguished sed given the extinction parameters
- Parameters:
- moddataModelData object
all the information about the model spectra
- seddict
fluxes for each spectral piece
- Returns:
- extinguished seddict
SED with {‘bands’: band_sed, ‘spec’: spec_sed, …}
- fit_minimizer(obsdata, modinfo, maxiter=1000)[source]¶
Run a minimizer (formally an optimizer) to find the best fit parameters by finding the minimum chisqr solution.
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- maxiterint
maximum number of iterations for the minimizer [default=1000]
- Returns:
- fitmod, resultlist
fitmod is a MEModel with the best fit parameters result is the scipy minimizer output
- fit_sampler(obsdata, modinfo, nsteps=1000, burnfrac=0.5, initfrac=0.01, save_samples=None, multiproc=False, resume=False)[source]¶
Run a samplier (specifically emcee) to find the detailed parameters including uncertainties.
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- nstepsint
number of steps for the samplier chains [default=1000]
- burnfracfloat
fraction of nsteps to discard as the burn in [default=0.1]
- initfracfloat
fraction for walker ball around initial position
- save_samplesfilename
name of hd5 file to save the MCMC samples
- multiprocboolean
set to run the emcee in parallel (does not speed up things much) [default=False]
- resumeboolean
resume from previous run (requires save_samples to be an existing emcee hd5 save file)
- Returns:
- fitmod, resultlist
fitmod is a MEModel with the best fit parameters result is the scipy minimizer output
- fit_to_parameters(fit_params, uncs=None)[source]¶
Set the parameter values based on a vector of the non-fixed values. Needed for most fitters/samplers.
- Parameters:
- fit_paramsnp array
non-fixed parameters values
- fit_weights(obsdata)[source]¶
Compute the weight to be used for fitting. Observed data for the base weights 1/unc (expected by fitters). Weights in regions known to have data issues or that the models do not include are set to zero (e.g., stellar wind lines, geocoronal Ly-alpha)
- Parameters:
- obsdataStarData object
observed data for a reddened star
- hi_abs_sed(moddata, sed)[source]¶
HI abs sed given the HI columns
- Parameters:
- moddataModelData object
all the information about the model spectra
- seddict
fluxes for each spectral piece
- Returns:
- hi absorbed seddict
SED with {‘bands’: band_sed, ‘spec’: spec_sed, …}
- lnlike(obsdata, modeldata)[source]¶
Compute the natural log of the likelihood that the data fits the model.
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- Returns:
- lnpfloat
natural log of the likelihood
- lnprior()[source]¶
Compute the natural log of the priors. Only Gaussian priors currently supported.
- Returns:
- lnpfloat
natural log of the prior
- lnprob(obsdata, modeldata)[source]¶
Compute the natural log of the probability
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- parameters()[source]¶
Give all the parameters values in a vector (fixed or not).
- Returns:
- paramsnp array
parameters values
- parameters_to_fit()[source]¶
Give the non-fixed parameters values in a vector. Needed for most fitters/samplers.
- Returns:
- paramsnp array
non-fixed parameters values
- plot(obsdata, modinfo, resid_range=10.0, lyaplot=False, xticks=[0.1, 0.2, 0.3, 0.5, 0.7, 1.0, 2.0])[source]¶
Standard plot showing the data and best fit.
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- resid_rangefloat
percentage value for the +/- range for the residual plot
- lyaplotboolean
set to add two panels giving the Ly-alpha fit and residuals
- xticksvector
set to a vector of floats giving the values for the xticks
- plot_sampler_chains(sampler)[source]¶
Plot the samplier chains.
- Parameters:
- samplerobject
emcee sampler object
- Returns:
- figobject
returns the standard matplotlib fig info
- plot_sampler_corner(flat_samples)[source]¶
Plot the standard corner plot.
- Returns:
- figobject
returns the standard matplotlib fig info
- save_parameters(filename=None)[source]¶
Save the parameters and uncertainties to a table. Include if they were fixed, their bounds, and their priors.
- Parameters:
- filenamestr
name of the file for the saved info
- Returns:
- otabastropy table
table giving the results, often output with the computed extinction curve
- set_initial_norm(obsdata, modeldata)[source]¶
Set the initial normalization that puts the current model at the average level of the observed data. The normalization is a fit parameter, so is included fully in the fitting.
- Parameters:
- obsdataStarData object
observed data for a reddened star
- moddataModelData object
all the information about the model spectra
- stellar_sed(moddata)[source]¶
Compute the stellar SED from the model parameters.
If foreground dust extinction included, then also includes the foreground dust extinction. Including this here results in extinction curves that do not include the foreground extinction.
- Parameters:
- moddataModelData object
all the information about the model spectra
- Returns:
- seddict
SED with {‘bands’: band_sed, ‘spec’: spec_sed, …}