API Reference#

This page lists the various classes and functions that demcmc provides.

Input#

class demcmc.TempBins(edges: Quantity)#

A set of temperature bins.

The bins are defined through the bin edges.

Parameters:
edgesastropy.units.Quantity

Bin edges.

property bin_centers: Quantity#

Centers of the bins.

property bin_widths: Quantity#

Widths of the bins.

property edges: Quantity#

Edges of the temperature bins.

iter_bins() Iterator[Tuple[Quantity, Quantity]]#

Iterate through lower/upper bounds of temperature bins.

Yields:
lower_edgeastropy.units.Quantity

Lower edge of bin.

upper_edgeastropy.units.Quantity

Upper edge of bin.

property max: Quantity#

Upper bound of the temperature bins.

property min: Quantity#

Lower bound of the temperature bins.

demcmc.load_cont_funcs(path: Path) Dict[str, ContFuncDiscrete]#

Load a set of contribution functions from a netCDF file.

The file should contain a 2D array of data, with coordinates named “Temperature” for the temperatures and “Line” for the line names.

Parameters:
pathos.PathLike

Path of the netCDF file.

Returns:
dict[str, ContFuncDiscrete]

Mapping of line name to the loaded contribution function.

class demcmc.ContFuncDiscrete(temps: Quantity, values: Quantity, *, name: str | None = None)#

A pre-computed contribution function defined at temperature values.

Parameters:
tempsu.Quantity

Temperature values of samples.

valuesu.Quantity

Contribution function values.

namestr

Name for the contribution function.

binned(temp_bins: TempBins) Quantity#

Get contribution function.

Parameters:
temp_binsTempBins

Temperature bins to get contribution function at.

Returns:
astropy.units.Quantity

Contribution function at given temperature bins.

property temps: Quantity#

Temperatures of contribution function samples.

property values: Quantity#

Contribution function values.

class demcmc.EmissionLine(cont_func: ContFunc, intensity_obs: float | None = None, sigma_intensity_obs: float | None = None, name: str | None = None)#

A single emission line.

Parameters:
cont_funcContFunc

Contribution function.

intensity_obsfloat

Observed intensity.

sigma_intensity_obsfloat

Uncertainty in observed intensity.

namestr

Emission line name.

I_pred(dem: BinnedDEM) Quantity#

Calculate predicted intensity of a given line.

Parameters:
demBinnedDEM

DEM.

Returns:
astropy.units.Quantity

Predicted intensity.

Running#

demcmc.predict_dem_emcee(lines: Sequence[EmissionLine], temp_bins: TempBins, *, nsteps: int, nwalkers: int, progress: bool = True) DEMOutput#

Estimate DEM from a number of emission lines.

Parameters:
linesSequence[EmissionLine]

Emission lines.

temp_binsTempBins

Temperature bins to predict DEM in.

nstepsint

Total number of steps for the MCMC walkers to take.

nwalkersint

Number of MCMC walkers to use.

progressbool

Whether to show a progress bar for the MCMC walking.

Returns:
DEMOutput

Output container.

Output#

class demcmc.DEMOutput#

Output from running DEM calculation.

This is not intended to be created by users.

iter_binned_dems() Iterator[BinnedDEM]#

Iterate across each final sample, returning a BinnedDEM.

Yields:
BinnedDEM
classmethod load(path: Path) DEMOutput#

Load a computed DEM from a netCDF file.

This will load files saved by the .save() method.

Parameters:
pathpathlib.Path

Path to netCDF file.

Returns:
DEMOutput
property n_samples: int#

Number of walkers used (same as number of final samples).

plot_final_samples(ax: Axes, **kwargs: Any) None#

Plot the final samples of the MCMC walker.

Parameters:
axmatplotlib.axes.Axes

Axes to plot the samples on.

**kwargsdict

Keyword arguments are passed to stairs().

property sampler: EnsembleSampler#

Sampler used by emcee to calculated the DEM.

property samples: Quantity#

Return the last set of samples from the walker.

save(path: Path) None#

Save a computed DEM to a netCDF file.

Parameters:
pathpathlib.Path

Path to save to. Should end in ".nc".

property temp_bins: TempBins#

Temperature bins.

class demcmc.emission.BinnedDEM(temp_bins: TempBins, values: Quantity)#

A DEM binned over a range of temperature values.

Parameters:
temp_binsTempBins

Temperature bins.

valuesastropy.units.Quantity

DEM values.

demcmc.plot_emission_loci(lines: List[EmissionLine], ax: Axes, **kwargs: Any) None#

Plot emission loci for a set of observed emission lines.

Parameters:
lineslist[EmissionLine]

Lines to plot.

axmatplotlib.axes.Axes

Axes to plot on.

**kwargsdict

Keyword arguments are passed to stairs().

Notes

Currently only works with lines that have a ContFuncDiscrete contribution function.