prospect.plotting#
figuremaker.py - module containing a class with basic plotting functionality and convenience methods for prospector results files.
- class prospect.plotting.figuremaker.FigureMaker(results_file='', show=None, nufnu=False, microns=True, n_seds=-1, prior_samples=10000, **extras)#
A class for making figures from prospector results files. Usually you’ll want to subclass this and add specific plot making methods, But this class contains useful methods for generating and caching posterior SED predictions etc.
- Parameters:
show – list of strings The names of the parameters (or transformed parameters) to show in posterior or corner plots
results_file – string
n_seds – int Number of SED samples to generate. if < 1, generate no SEDs. If 0, only generate the SEDs for the most probably sample
prior_samples – int Number of prior samples to tale when computing the prior probability distributions numerically
nufnu – bool Whether to plot fluxes in nufnu
microns – bool Whether to plot wavelength as mictons
- read_in(results_file)#
Read a prospector results file, cache important components, and do any parameter transformations. The cached attributes are:
obs - The obs dictionary ised for the fit
model - The model used for the fit, if it could be reconstructed.
chain - Structured array of parameter vector samples
weights - Corresponding weights for each sample
ind_best - Index of the sample with the highest posterior probability
- parchain - The chain transformed to the desired derived parameters via
the convert method.
- Parameters:
results_file – string full path of the file with the prospector results.
- convert(chain)#
Can make parameter transormations on the chain with this method, which you will want to subclass for your particular needs. For example, this method could be used to compute the mass-weighted age for every posterior sample and include that in the output structured array as the mwa column.
- Parameters:
chain – structured ndarray of shape (nsample,) The structured ndarray of parameter values, with column names (and datatypes) given by the model free parameters.
- Returns parchain:
structured ndarray of shape (nsample,) The structured ndarray of transformed parameter values.
- make_seds(full=False)#
Generate and cache the best fit model spectrum and photometry. Optionally generate the spectrum and photometry for a number of posterior samples.
Populates the attributes *_best and *_samples where * is: * spec * phot * sed * cal
- Parameters:
full – bool, optional If true, generate the intrinsic spextrum (sed_*) over the entire wavelength range. The (restframe) wavelength vector will be given by self.sps.wavelengths
- draw_seds(n_seds, dummy=None)#
Draw a number of samples from the posterior chain, and generate spectra and photometry for them.
- Parameters:
n_seds – int Number of samples to draw and generate SEDs for
dummy – dict, optional If given, use this dictionary as the obs dictionary when generating the intrinsic SED vector. Useful for generating an SED over a large wavelength range
- build_sps()#
Build the SPS object and assign it to the sps attribute. This can be overridden by subclasses if necessary.
- show_priors(diagonals, spans, smooth=0.05, color='g', peak=0.96, **linekwargs)#
Show priors, either using simple calls or using transformed samples. These will be overplotted on the supplied axes.
- Parameters:
diagonals – ndarray of shape (nshow,) The axes on which to plot prior distributions, same order as show
- plot_all()#
Main plotting function; makes axes, plotting styles, and then a corner plot and an SED (and residual) plot.
- plot_corner(caxes, **extras)#
Example to make a corner plot of the posterior PDFs for the parameters listed in show.
- Parameters:
caxes – ndarray of axes of shape (nshow, nshow)
- plot_sed(sedax, residax=None, normalize=False, nufnu=True, microns=False)#
A very basic plot of the observed photometry and the best fit photometry and spectrum.
- show_transcurves(ax, height=0.2, logify=True, linekwargs={'alpha': 0.7, 'color': '0.3', 'lw': 1.5})#
Overplot transmission curves on an axis. The hight of the curves is computed as a (logarithmic) fraction of the current plot limits.
- restframe_axis(ax, microns=True, fontsize=16, ticksize=12)#
Add a second (top) x-axis with rest-frame wavelength
- make_axes()#
Make a set of axes and assign them to the object.
- styles(colorcycle=['royalblue', 'firebrick', 'indigo', 'darkorange', 'seagreen'])#
Define a set of plotting styles for use throughout the figure.
- make_art()#
Make a dictionary of artists corresponding to the plotting styles that can be used for making legends
prospect.plotting.utils#
- prospect.plotting.utils.sample_prior(model, nsample=1000000.0)#
Generate samples from the prior.
- Parameters:
model – A ProspectorParams instance.
nsample – (int, optional, default: 1000000) Number of samples to take
- Returns samples:
ndarray of shape(nsample, ndim) Samples from the prior
- Returns labels:
list of strings The names of the free parameters.
- prospect.plotting.utils.sample_posterior(chain, weights=None, nsample=10000, start=0, thin=1, extra=None)#
- Parameters:
chain – ndarray of shape (niter, ndim) or (niter, nwalker, ndim)
weights – weights for each sample, of shape (niter,)
nsample – (optional, default: 10000) Number of samples to take
start – (optional, default: 0.) Fraction of the beginning of the chain to throw away, expressed as a float in the range [0,1]
thin – (optional, default: 1.) Thinning to apply to the chain before sampling (why would you do that?)
extra – (optional, default: None) Array of extra values to sample along with the parameters of the chain. ndarray of shape (niter, …)
prospect.plotting.sfh#
- prospect.plotting.sfh.parametric_mwa(tau=4, tage=13.7, power=1)#
Compute Mass-weighted age. This is done analytically
- Parameters:
power – (optional, default: 1) Use 0 for exponential decline, and 1 for te^{-t} (delayed exponential decline)
- prospect.plotting.sfh.parametric_sfr(times=None, tavg=0.001, tage=1, **sfh)#
Return the SFR (Msun/yr) for the given parameters of a parametric SFH, optionally averaging over some timescale.
- Parameters:
times – (optional, ndarray) If given, a set of lookback times where you want to calculate the sfr, same units as tau and tage
tavg – (optional, float, default: 1e-3) If non-zero, average the SFR over the last tavg Gyr. This can help capture bursts. If zero, the instantaneous SFR will be returned.
sfh – optional keywords FSPS parametric SFH parametrs, e.g. sfh, tage, tau, sf_trunc
- Returns sfr:
SFR in M_sun/year either for the lookback times given by times or at lookback time 0 if no times are given. The SFR will either be instaneous or averaged over the last tavg Gyr.
- prospect.plotting.sfh.sfh_quantiles(tvec, bins, sfrs, weights=None, q=[16, 50, 84])#
Compute quantiles of a binned SFH
- Parameters:
tvec – shape (ntime,) Vector of lookback times onto which the SFH will be interpolated.
bins – shape (nsamples, nbin, 2) The age bins, in linear untis, same units as tvec
sfrs – shape (nsamples, nbin) The SFR in each bin
- Returns sfh_q:
shape(ntime, nq) The quantiles of the SFHs at each lookback time in tvec
- prospect.plotting.sfh.nonpar_mwa(logmass, logsfr_ratios, agebins)#
mass-weighted age, vectorized
- prospect.plotting.sfh.nonpar_recent_sfr(logmass, logsfr_ratios, agebins, sfr_period=0.1)#
vectorized
prospect.plotting.corner#
- prospect.plotting.corner.corner(samples, paxes, weights=None, span=None, smooth=0.02, color='black', hist_kwargs={}, hist2d_kwargs={}, upper=False)#
Make a smoothed cornerplot.
- Parameters:
samples – ~numpy.ndarray of shape (ndim, nsample) The samples from which to construct histograms.
paxes – ndarray of pyplot.Axes of shape(ndim, ndim) Axes into which to plot the histograms.
weights – ndarray of shape (nsample,), optional Weights associated with each sample.
span –
iterable with shape (ndim,), optional A list where each element is either a length-2 tuple containing lower and upper bounds or a float from (0., 1.] giving the fraction of (weighted) samples to include. If a fraction is provided, the bounds are chosen to be equal-tailed. An example would be:
span = [(0., 10.), 0.95, (5., 6.)]
Default is 0.999999426697 (5-sigma credible interval).
- :param smoothfloat or iterable with shape (ndim,), optional
The standard deviation (either a single value or a different value for each subplot) for the Gaussian kernel used to smooth the 1-D and 2-D marginalized posteriors, expressed as a fraction of the span. Default is 0.02 (2% smoothing). If an integer is provided instead, this will instead default to a simple (weighted) histogram with bins=smooth.
- Parameters:
color – str or iterable with shape (ndim,), optional A ~matplotlib-style color (either a single color or a different value for each subplot) used when plotting the histograms. Default is ‘black’.
- upperbool, optional (default=False)
Set to true if the supplied axes should be formatted for an upper triangular corner plot.
- Parameters:
hist_kwargs – dict, optional Extra keyword arguments to send to the 1-D (smoothed) histograms.
hist2d_kwargs – dict, optional Extra keyword arguments to send to the 2-D (smoothed) histograms.
- Returns paxes:
- prospect.plotting.corner.marginal(x, ax=None, weights=None, span=None, smooth=0.02, color='black', peak=None, **hist_kwargs)#
Compute a marginalized (weighted) histogram, with smoothing.
- prospect.plotting.corner.quantile(xarr, q, weights=None)#
Compute (weighted) quantiles from an input set of samples.
- Parameters:
x – ~numpy.darray with shape (nvar, nsamples) The input array to compute quantiles of.
q – list of quantiles, from [0., 1.]
weights – shape (nsamples)
- Returns quants:
ndarray of shape (nvar, nq) The quantiles of each varaible.