jwspecmcmc.result

MCMC result containers.

MCMCResult holds the full posterior chains and derived quantities. MCMCResult.to_fit_result() converts the median posterior to a jwspecfit.fitter.FitResult for compatibility with jwspecfit.plotting.plot_fit().

MCMCBroadFitResult wraps an MCMCResult with BIC model-selection metadata for broad Balmer component fitting.

Classes

MCMCBroadFitResult(mcmc_result, ...[, ...])

MCMC result with BIC-based broad Balmer component selection.

MCMCLineResult(name, rest_wave_A, amplitude, ...)

MCMC posterior summary for a single emission line.

MCMCResult(lines, flat_chains, ...[, ...])

Container for a complete MCMC fitting result.

class jwspecmcmc.result.MCMCBroadFitResult(mcmc_result, selected_model, bic_narrow, bic_broad1, bic_broad2, bic_both, oiii_selected='off', bic_oiii_off=nan, bic_oiii_broad1=nan, bic_oiii_broad2=nan, bic_oiii_both=nan, hei_selected='off', bic_hei_off=nan, bic_hei_broad1=nan, bic_hei_broad2=nan, bic_hei_both=nan)[source]

Bases: object

MCMC result with BIC-based broad Balmer component selection.

Wraps an MCMCResult (full MCMC posteriors on the winning model) together with BIC model-selection metadata.

Parameters:
  • mcmc_result (MCMCResult) – Full MCMC posteriors for the selected model.

  • selected_model (str) – Model name: "narrow", "broad1", "broad2", or "both".

  • bic_narrow (float) – BIC for narrow-only model.

  • bic_broad1 (float) – BIC for narrow + intermediate broad model (NaN if not attempted).

  • bic_broad2 (float) – BIC for narrow + very broad model (NaN if not attempted).

  • bic_both (float) – BIC for narrow + both broad components (NaN if not attempted).

  • oiii_selected (str)

  • bic_oiii_off (float)

  • bic_oiii_broad1 (float)

  • bic_oiii_broad2 (float)

  • bic_oiii_both (float)

  • hei_selected (str)

  • bic_hei_off (float)

  • bic_hei_broad1 (float)

  • bic_hei_broad2 (float)

  • bic_hei_both (float)

bic_both: float
bic_broad1: float
bic_broad2: float
bic_hei_both: float = nan
bic_hei_broad1: float = nan
bic_hei_broad2: float = nan
bic_hei_off: float = nan
bic_narrow: float
bic_oiii_both: float = nan
bic_oiii_broad1: float = nan
bic_oiii_broad2: float = nan
bic_oiii_off: float = nan
property chains: ndarray | None

Raw walker chains (emcee) or None (nautilus).

property constraints: ConstraintSet | None

Applied constraints.

property continuum: ndarray

Continuum estimate.

property convergence: dict[str, Any]

Convergence diagnostics.

doublet_flux_posterior(line_a, line_b)[source]

Combined flux posterior for a doublet.

Delegates to MCMCResult.doublet_flux_posterior().

Return type:

ndarray

Parameters:
doublet_snr(line_a, line_b)[source]

SNR of a combined doublet flux.

Delegates to MCMCResult.doublet_snr().

Return type:

float

Parameters:
property flat_chains: ndarray

Flattened posterior samples (full parameter space).

property flat_chains_free: ndarray

Flattened posterior samples (free parameter space).

property flat_log_prob: ndarray

Log-posterior for each sample.

flux_ratio_posterior(line_a, line_b)[source]

Compute the posterior distribution of a flux ratio.

Delegates to MCMCResult.flux_ratio_posterior().

Parameters:
  • line_a (str) – Numerator line name.

  • line_b (str) – Denominator line name.

Returns:

Posterior samples of flux(line_a) / flux(line_b).

Return type:

np.ndarray

flux_upper_limit(line_name, n_sigma=3.0)[source]

Noise-based flux upper limit for a line.

Delegates to MCMCResult.flux_upper_limit().

Return type:

float | None

Parameters:
flux_upper_limits(line_names=None, n_sigma=3.0, snr_threshold=3.0)[source]

Noise-based upper limits for low-SNR lines.

Delegates to MCMCResult.flux_upper_limits().

Return type:

dict[str, float]

Parameters:
property hei_broad_selected: bool

True if any HeI broad component was selected.

Type:

Convenience

hei_selected: str = 'off'
property line_names: list[str]

Ordered line names.

property lines: dict[str, MCMCLineResult]

Per-line posterior summaries.

mcmc_result: MCMCResult
property model_flux: ndarray

Median model flux (continuum-subtracted).

property oiii_broad_selected: bool

True if any OIII broad component was selected.

Type:

Convenience

oiii_selected: str = 'off'
property params: ndarray

Median posterior in the full parameter space.

property sampler_meta: dict[str, Any]

Additional sampler metadata.

property sampler_name: str

Name of the sampler used.

selected_model: str
property spectrum: Spectrum

Input spectrum.

to_fit_result()[source]

Convert to a jwspecfit.fitter.FitResult.

Delegates to MCMCResult.to_fit_result().

Return type:

FitResult

class jwspecmcmc.result.MCMCLineResult(name, rest_wave_A, amplitude, amplitude_err, centroid_A, centroid_err, sigma_A, sigma_err, flux, flux_err, flux_posterior, ew_A, snr)[source]

Bases: object

MCMC posterior summary for a single emission line.

Parameters:
  • name (str) – Line name.

  • rest_wave_A (float) – Rest-frame wavelength (Angstrom).

  • amplitude (float) – Median posterior amplitude.

  • amplitude_err (tuple of float) – (lower, upper) 68% credible interval half-widths on amplitude.

  • centroid_A (float) – Median posterior centroid (Angstrom).

  • centroid_err (tuple of float) – (lower, upper) 68% CI half-widths on centroid.

  • sigma_A (float) – Median posterior sigma (Angstrom).

  • sigma_err (tuple of float) – (lower, upper) 68% CI half-widths on sigma.

  • flux (float) – Median integrated flux (= amplitude for area-normalised Gaussians).

  • flux_err (tuple of float) – (lower, upper) 68% CI half-widths on flux.

  • flux_posterior (np.ndarray) – Full flux posterior samples.

  • ew_A (float) – Median rest-frame equivalent width (Angstrom).

  • snr (float) – Signal-to-noise ratio (flux / mean of flux_err tuple).

amplitude: float
amplitude_err: tuple[float, float]
centroid_A: float
centroid_err: tuple[float, float]
ew_A: float
flux: float
flux_err: tuple[float, float]
flux_posterior: ndarray
name: str
rest_wave_A: float
sigma_A: float
sigma_err: tuple[float, float]
snr: float
class jwspecmcmc.result.MCMCResult(lines, flat_chains, flat_chains_free, flat_log_prob, chains, params, model_flux, continuum, spectrum, line_names=<factory>, constraints=None, convergence=<factory>, sampler_name='', sampler_meta=<factory>, lya_params=None)[source]

Bases: object

Container for a complete MCMC fitting result.

Parameters:
  • lines (dict of MCMCLineResult) – Per-line posterior summaries, keyed by line name.

  • flat_chains (np.ndarray) – Flattened posterior samples in the full parameter space, shape (n_samples, 3 * n_lines).

  • flat_chains_free (np.ndarray) – Flattened posterior samples in the free parameter space, shape (n_samples, n_free).

  • flat_log_prob (np.ndarray) – Log-posterior for each sample.

  • chains (np.ndarray or None) – Raw chains of shape (n_walkers, n_steps, n_free) (emcee) or None (nautilus).

  • params (np.ndarray) – Median posterior in the full parameter space.

  • model_flux (np.ndarray) – Median model flux (µJy, continuum-subtracted).

  • continuum (np.ndarray) – Continuum estimate (µJy).

  • spectrum (Spectrum) – Input spectrum.

  • line_names (list of str) – Ordered line names.

  • constraints (ConstraintSet) – Applied constraints.

  • convergence (dict) – Convergence diagnostics (R-hat, ESS).

  • sampler_name (str) – Name of the sampler used ("emcee" or "nautilus").

  • sampler_meta (dict) – Additional sampler metadata (n_walkers, n_steps, etc.).

  • lya_params (ndarray | None)

chains: ndarray | None
constraints: ConstraintSet | None = None
continuum: ndarray
convergence: dict[str, Any]
doublet_flux_posterior(line_a, line_b)[source]

Compute the combined flux posterior for a doublet.

Sums the flux posteriors sample-by-sample, giving the correct combined distribution even when individual members are degenerate (e.g. blended CIII] 1907+1909).

Parameters:
  • line_a (str) – First doublet member.

  • line_b (str) – Second doublet member.

Returns:

Posterior samples of flux(line_a) + flux(line_b).

Return type:

np.ndarray

doublet_snr(line_a, line_b)[source]

Compute the SNR of a combined doublet flux.

Uses the summed flux posterior to get a single SNR that is not degraded by the amplitude degeneracy between blended members.

Parameters:
  • line_a (str) – First doublet member.

  • line_b (str) – Second doublet member.

Returns:

SNR of the combined doublet.

Return type:

float

flat_chains: ndarray
flat_chains_free: ndarray
flat_log_prob: ndarray
flux_ratio_posterior(line_a, line_b)[source]

Compute the posterior distribution of a flux ratio.

Parameters:
  • line_a (str) – Numerator line name.

  • line_b (str) – Denominator line name.

Returns:

Posterior samples of flux(line_a) / flux(line_b).

Return type:

np.ndarray

Raises:

KeyError – If either line is not in the result.

flux_upper_limit(line_name, n_sigma=3.0)[source]

Compute a noise-based flux upper limit for a line.

Uses the local RMS of the continuum-and-model-subtracted residuals near the line, multiplied by the line width and n_sigma. This is the standard approach for non-detections and is independent of the posterior (which may be prior- dominated for weak lines).

Parameters:
  • line_name (str) – Line name.

  • n_sigma (float) – Number of sigma for the upper limit (default 3).

Returns:

Integrated flux upper limit in f_lam units, or None if there are insufficient pixels near the line.

Return type:

float or None

flux_upper_limits(line_names=None, n_sigma=3.0, snr_threshold=3.0)[source]

Compute noise-based upper limits for low-SNR lines.

Parameters:
  • line_names (list of str, optional) – Lines to check. If None, checks all fitted lines.

  • n_sigma (float) – Number of sigma for the upper limit (default 3).

  • snr_threshold (float) – Only compute upper limits for lines with SNR below this (default 3.0). Lines above this threshold are detections.

Returns:

dict of {str{line_name: flux_upper_limit} for each line below the SNR threshold.

Return type:

float}

line_names: list[str]
lines: dict[str, MCMCLineResult]
lya_params: ndarray | None = None
model_flux: ndarray
params: ndarray
sampler_meta: dict[str, Any]
sampler_name: str = ''
spectrum: Spectrum
to_fit_result()[source]

Convert to a jwspecfit.fitter.FitResult.

Uses the median posterior as the best fit and the mean of the asymmetric 68% CI as the symmetric flux error.

Return type:

FitResult