API

sesamme.mcmc

sesamme.models

sesamme.vis

Statistical machinery (sesamme.mcmc)

sesamme.mcmc.log_likelihood(y, yerr, y_model, mask)

Evaluate the likelihood function by comparing the data and chosen model at every wavelength bin.

Parameters:
  • y (array-like) – Flux array

  • yerr (array-like) – Flux uncertainty array

  • y_model (array-like) – Model flux array

  • mask (array-like) – Marks which wavelength bins to ignore during fitting

  • theta (list or np.ndarray) – Array containing, in order, a log(age) logt, a log(metallicity) logZ, an E(B-V) value ebv, and an amplitude ampl.

Returns:

resid – -1 * log(likelihood), where log(n) means the natural logarithm

Return type:

float

sesamme.mcmc.log_posterior(theta, x, y, yerr, model_cube, ion_table, mask, add_nebular)

Calculates the (log of the) posterior probability as log(Ppos) = log(Pprior) + log(likelihood).

Parameters:
  • theta (list or np.ndarray) – Array containing, in order, a log(age) logt, a log(metallicity) logZ, an E(B-V) value ebv, and an amplitude log(ampl).

  • x (array-like) – Wavelength array

  • y (array-like) – Flux array

  • yerr (array-like) – Flux uncertainty array

  • model_cube (FITS) – Multi-extension FITS cube containing SSP models

  • ion_table (astropy Table) – Table object containing ionizing fluxes per SSP

  • mask (array-like) – Marks which wavelength bins to ignore during fitting

  • add_nebular (Boolean) – Determines whether to add nebular continuum emission to a model

Returns:

lp_ll – Sum of ln(prior) and ln(likelihood)

Return type:

float

sesamme.mcmc.log_prior(theta)

Calculate a flat prior probability within the bounds prescribed below.

Parameters:

theta (list or np.ndarray) – Array containing, in order, a log(age) logt, a log(metallicity) logZ, an E(B-V) value ebv, and an amplitude ampl.

Returns:

0 if parameters in theta are within allowed ranges, or -inf otherwise

Return type:

float

sesamme.mcmc.run_sesamme(filename, runname, x, y, yerr, model_cube, ion_table, mask, add_nebular=True)

Initiate an MCMC procedure and write the results to a file/extension name.

Parameters:
  • filename (str) – Name of *.H5 file to write results to

  • runname (str) – Extension/run name within the file; can store multiple runs in a single *.H5 file

  • x (array-like) – Wavelength array

  • y (array-like) – Flux array

  • yerr (array-like) – Flux uncertainty array

  • model_cube (FITS) – Multi-extension FITS cube containing SSP models

  • ion_table (astropy Table) – Table object containing ionizing fluxes per SSP

  • mask (array-like) – Marks which wavelength bins to ignore during fitting

  • add_nebular (Boolean) – Determines whether to add nebular continuum emission to a model

sesamme.mcmc.set_chain_size(m)

Updates the number of steps (chain length) of the MCMC run. Default value is 10000.

Parameters:

m (int) – Number of steps in chain

sesamme.mcmc.set_initial_positions(centers)

Updates the initial positions of the walker ensemble.

Creates a ball of walker positions with a small spread around specified values.

Parameters:

center (list or np.ndarray) – Must contain, in order, a value for log(age), log(Z), E(B-V), and log(ampl).

sesamme.mcmc.set_prior_bounds(prior_dict, prior_lowbounds, prior_highbounds)

Set boundaries on the priors for an MCMC run.

Parameters:
  • prior_dict (dict) – Global dictionary that specifies the boundaries of the four parameters. Initially empty.

  • prior_lowbounds (list or np.ndarray) – Gives lower boundaries for the priors. Must contain, in order, a value for log(age), log(Z), E(B-V), and log(ampl).

  • prior_highbounds (list or np.ndarray) – Gives upper boundaries for the priors. Must contain, in order, a value for log(age), log(Z), E(B-V), and log(ampl).

Raises:

ValueError – If boundaries are not increasing from the first column (expected lower) to the second (higher).

sesamme.mcmc.set_walker_size(m)

Updates the size of the walker ensemble. Default value of nwalkers = 128.

Parameters:

m (int) – Number of walkers in emcee ensemble

Model generation (sesamme.models)

sesamme.models.apply_ext_law(x, ebv, y_model)

Redden a model spectrum for comparison with the data.

Parameters:
  • x (array-like) – Wavelength array

  • ebv (float) – Value of E(B-V) by which to redden the model

  • y_model (np.ndarray) – Flux array of the model spectrum; may be purely stellar or stellar + nebular continuum

Returns:

red_model – Extinguished SSP or SSP+nebular model

Return type:

array-like

Raises:

ValueError – String use_ext_law is not in the list of allowable values

sesamme.models.get_mask(windowlist, x)

Define one or more subsets of wavelength space to ignore when performing the data-model comparison (e.g., sky or geocoronal lines, ISM features).

Each row in the input windowlist specifies a wavelength window where weight = 0 during the fitting, and the first and second columns respectively give the approximate lower and upper bounds of the window(s). The actual bounds will be chosen from the nearest values in the wavelength array.

Parameters:
  • windowlist (np.ndarray) – N x 2 array.

  • x (array-like) – Wavelength array

Returns:

mask_array – Array of bools (1 = use in fit, 0 = do not use)

Return type:

np.ndarray

sesamme.models.get_model(theta, x, model_cube, ion_table, add_nebular=True)

Construct a model star cluster spectrum with values of metallicity, age, extinction, and normalization randomly chosen (within bounds).

Choose the model nearest to the age and metallicity parameters Z and t, rescale by ampl, then redden by the extinction parameter ebv. If add_nebular is set to True, this is added before rescaling and extinction.

Parameters:
  • theta (list or np.ndarray) – Array containing, in order, a log(age) logt, a log(metallicity) logZ, an E(B-V) value ebv, and an amplitude log(ampl).

  • model_cube (FITS) – Multi-extension FITS cube containing SSP models

  • ion_table (astropy Table) – Table object containing ionizing fluxes per SSP

  • add_nebular (Boolean) – Determines whether to add nebular continuum emission to a model

Returns:

red_nearest_model – Extinguished and rescaled SSP or SSP+nebular model spectrum with age and metallicity values nearest to the inputs.

Return type:

array-like

sesamme.models.load_ionization_table(file_name)

Loads in the table of ionizing photon outputs per SSP associated with a model cube.

Parameters:

file_name (str) – File path and name

Returns:

ion_table – Table object containing ionizing fluxes per SSP

Return type:

astropy Table

sesamme.models.load_ssp_cube(file_name)

Loads in the SSP model cube. Implicitly alters the model grid to be sampled with emcee through _ingest_model_grid().

Parameters:

file_name (str) – File path and name

Returns:

model_cube – Multi-extension FITS cube containing SSP models

Return type:

FITS

sesamme.models.nebular_continuum(x, theta, ion_table)

Python equivalent of the Starburst99 function CONTINUUM, for computing the approximate nebular continuum.

Variable ‘gamma’ contains emission coeffs for HI (including free-free, bound-free, and 2-photon emission) and HeI (assuming He/H = 0.1). Values from Aller (1984) and Ferland (1980). All computations assume typical Case B conditions (T = 1e4 K, f_esc = 0).

Parameters:
  • x (array-like) – Wavelength array

  • theta (list or np.ndarray) – Array containing, in order, a log(age) logt, a log(metallicity) logZ, an E(B-V) value ebv, and an amplitude log(ampl).

  • ion_table (astropy Table) – Table object containing ionizing fluxes per SSP

Returns:

interp_nebcont – Approximate rescaled nebular continuum spectrum in Solar luminosities per A.

Return type:

np.ndarray

sesamme.models.set_ext_law(ext_curve)

Sets the curve used to extinguish model spectra.

Currently implemented options for extinction curves include 5 Milky Way-like curves (CCM, Fitzpatrick99, ODonnell, FitzMassa07, Gordon23), a starburst galaxy curve (Calzetti), an LMC-like curve (LMC), and an SMC-like curve (SMC).

Parameters:

ext_curve (str) – Name of extinction curve. Must match an implemented option in SESAMME’s library.

Raises:

ValueError – String ext_curve is not in the list of allowable values

Data visualization (sesamme.vis)

sesamme.vis.plot_samples(x, y, windowlist, flat_samples, add_nebular=True, plot_median=False, median_params=[7.0, -2.0, 0.0, 0.0], plot_random_draws=True, title=None, savefile=False, savefile_name='example_fit')

A plotting function for examining the goodness-of-fit for models in the final sampler object after the MCMC run.

Parameters:
  • x (array-like) – Wavelength array

  • y (array-like) – Flux array

  • windowlist (list or array) – List of regions to mask

  • flat_samples (np.ndarray) – Flattened MCMC chain

  • add_nebular (Boolean) – Determines whether to include nebular continuum emission in plotted models; optional.

  • plot_median (Boolean) – Determines whether to plot a single model as a “best fit”, usually with posterior medians; optional.

  • median_params (list or array) – Model parameters for plot_median; optional.

  • plot_random_draws (Boolean) – Generates and plots 50 random curves sampled from the flattened MCMC chain; optional.

  • title (str) – Set figure title; optional

  • savefile (Boolean) – Determines whether to save figure to file; optional

  • savefile_name (str) – Output file name if savefile set to True; optional

sesamme.vis.print_stats(flat_samples)

Computes 16th, 50th, and 84th percentile values for the 4 variables and prints them in a friendly way.

Parameters:

flat_samples (numpy.ndarray) – Flattened MCMC chain flat_samples.