jwspecmcmc
jwspecmcmc — MCMC emission-line fitting for JWST NIRSpec spectra.
A companion to jwspecfit that replaces bootstrap uncertainties with
full Bayesian posterior sampling via emcee, nautilus, or NUTS.
By default, fit_lines() runs a narrow-only MCMC fit. Two
independent BIC-based broad component selections can be opted in:
fit_balmer_broad=True— Balmer broad (narrow vs. intermediate / very-broad / both, on Balmer pixels).fit_oiii_broad=True— [OIII] outflow broad (on OIII pixels).
Either or both can be enabled.
Example
>>> import jwspecfit, jwspecmcmc
>>> spec = jwspecfit.read_fits("spectrum.fits")
>>> result = jwspecmcmc.fit_lines(spec, z=6.0, sampler="nuts")
>>> result.selected_model # "narrow" | "broad1" | "broad2" | "both"
>>> result.oiii_broad_selected # bool — independent of selected_model
>>> result.lines["OIII_5007"].flux_err # asymmetric 68% CI
>>> ratio = result.flux_ratio_posterior("OIII_5007", "HBETA")
Functions
|
Fit emission lines using MCMC sampling. |
|
Fit emission lines with BIC-based broad selection, then MCMC. |
|
Corner plot of posterior samples. |
|
Flux posterior histogram for a single line. |
|
Trace plots of MCMC chains. |
- class jwspecmcmc.GaussianPrior(mean, std, lo=-inf, hi=inf)[source]
Bases:
PriorTruncated Gaussian prior.
- Parameters:
- sample(rng, size=1)[source]
Draw random samples from the prior.
- Parameters:
rng (numpy.random.Generator) – Random number generator.
size (int) – Number of samples.
- Returns:
Samples of shape
(size,).- Return type:
np.ndarray
- class jwspecmcmc.LogUniformPrior(lo, hi)[source]
Bases:
PriorLog-uniform (Jeffreys) prior on
[lo, hi]withlo > 0.- sample(rng, size=1)[source]
Draw random samples from the prior.
- Parameters:
rng (numpy.random.Generator) – Random number generator.
size (int) – Number of samples.
- Returns:
Samples of shape
(size,).- Return type:
np.ndarray
- class jwspecmcmc.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:
objectMCMC 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)
- property constraints: ConstraintSet | None
Applied constraints.
- doublet_flux_posterior(line_a, line_b)[source]
Combined flux posterior for a doublet.
Delegates to
MCMCResult.doublet_flux_posterior().
- doublet_snr(line_a, line_b)[source]
SNR of a combined doublet flux.
Delegates to
MCMCResult.doublet_snr().
- flux_ratio_posterior(line_a, line_b)[source]
Compute the posterior distribution of a flux ratio.
Delegates to
MCMCResult.flux_ratio_posterior().
- flux_upper_limit(line_name, n_sigma=3.0)[source]
Noise-based flux upper limit for a line.
Delegates to
MCMCResult.flux_upper_limit().
- 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().
- property lines: dict[str, MCMCLineResult]
Per-line posterior summaries.
- mcmc_result: MCMCResult
- property oiii_broad_selected: bool
True if any OIII broad component was selected.
- Type:
Convenience
- to_fit_result()[source]
Convert to a
jwspecfit.fitter.FitResult.Delegates to
MCMCResult.to_fit_result().- Return type:
- class jwspecmcmc.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:
objectMCMC 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).
- class jwspecmcmc.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:
objectContainer 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) orNone(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.
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)
- constraints: ConstraintSet | None = None
- 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).
- 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.
- 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).
- 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:
- Returns:
dict of {str –
{line_name: flux_upper_limit}for each line below the SNR threshold.- Return type:
float}
- lines: dict[str, MCMCLineResult]
- 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:
- class jwspecmcmc.PriorSet(priors=<factory>)[source]
Bases:
objectCollection of priors indexed by free-parameter position.
- log_prior(p_free)[source]
Evaluate the total log-prior for a free-parameter vector.
- Parameters:
p_free (np.ndarray) – Free parameter values (length
n_dim).- Returns:
Sum of individual log-priors (
-infif any parameter is outside its support).- Return type:
- sample(rng)[source]
Draw one sample from the joint prior.
- Parameters:
rng (numpy.random.Generator) – Random number generator.
- Returns:
Sample of shape
(n_dim,).- Return type:
np.ndarray
- class jwspecmcmc.UniformPrior(lo, hi)[source]
Bases:
PriorUniform (flat) prior on
[lo, hi].- sample(rng, size=1)[source]
Draw random samples from the prior.
- Parameters:
rng (numpy.random.Generator) – Random number generator.
size (int) – Number of samples.
- Returns:
Samples of shape
(size,).- Return type:
np.ndarray
- jwspecmcmc.fit_lines(spectrum, z, *, sampler='nuts', grating=None, R=None, lines=None, wave_range_A=None, deg=2, clip_sigma=2.5, init_from_mle=True, prior_overrides=None, n_walkers='auto', n_steps=2000, n_burn=None, n_live=2000, n_eff=10000, n_warmup=500, n_samples_nuts=2000, n_chains=6, target_accept_prob=0.8, max_tree_depth=10, progress=True, seed=42, fit_balmer_broad=False, fit_oiii_broad=False, fit_hei_broad=False, n_boot_bic=100, n_jobs=-1, snr_threshold=5.0, oiii_snr_threshold=5.0, hei_snr_threshold=5.0, bic_delta=6.0, sigma_factor=1.0, centroid_vmax=500.0, centroid_max_sigma=1.0, moving_average=False, tie_balmer_to_oiii=True, tie_uv_doublets=True, tie_uv_centroids=True, tie_uv_widths=True, sigma_overrides=None, centroid_overrides=None, niv_doublet_ratio=None, ciii_doublet_ratio=None)[source]
Fit emission lines using MCMC sampling.
Narrow-only MCMC fit by default. Three independent BIC-based broad component tests can be opted in to:
fit_balmer_broad=True— Balmer broad selection.fit_oiii_broad=True— [OIII] outflow selection.fit_hei_broad=True— He I broad selection (shared kinematics across all observable HeI lines).
Any combination can be enabled.
A grouped, tabular version of every argument below is available in the user guide: jwspecmcmc — Bayesian MCMC fitting.
- Parameters:
spectrum (Spectrum) – Input spectrum (observed wavelength, flux, and error arrays).
z (float) – Source redshift. Sets each observed line position via
lambda_obs = lambda_rest * (1 + z).sampler (str) – Posterior-sampling backend:
"nuts"(default; NumPyro Hamiltonian Monte Carlo),"emcee"(affine-invariant ensemble), or"nautilus"(importance nested sampling, which also returns the Bayesian evidence).grating (str, optional) – NIRSpec grating name (e.g.
"G395H"), used to set the resolution curve. IfNone, estimated from the pixel spacing.R (float or callable, optional) – Resolving power as a scalar or a callable
R(lambda_um). Overrides grating when given; ifNoneit is taken from grating or the pixel spacing.lines (list of str, optional) – Names of emission lines to fit (keys of
jwspecfit.lines.REST_LINES_A). IfNone, the lines that fall inside the spectrum at redshift z are auto-selected.wave_range_A (tuple of float, optional) –
(lo, hi)observed-frame wavelength window in Angstrom to restrict the fit to. IfNone, the full spectrum is used.deg (int) – Degree of the polynomial continuum (default 2).
clip_sigma (float) – Sigma-clip threshold used when fitting the continuum (default 2.5).
moving_average (bool or int) – Continuum model.
False(default) fits a polynomial of degree deg;Trueuses a 75-pixel running-median filter; anintuses a running-median filter of that window size.init_from_mle (bool) – If
True(default), seed the sampler from a fast least-squares MLE (viajwspecfit.fit_lines()). Strongly recommended; it speeds convergence and reduces stuck chains.n_warmup (int) – NUTS only. Warm-up (tuning) iterations per chain before samples are kept; adapts the step size and mass matrix (default 500).
n_samples_nuts (int) – NUTS only. Posterior draws kept per chain after warm-up; the total number of samples is
n_chains * n_samples_nuts(default 2000).n_chains (int) – NUTS only. Number of independent chains run in parallel; enables the Gelman-Rubin R-hat diagnostic (default 6).
target_accept_prob (float) – NUTS only. Target acceptance probability for step-size adaptation. Raise toward 0.95 if the sampler reports divergences (default 0.8).
max_tree_depth (int) – NUTS only. Maximum NUTS binary-tree depth, capping the leapfrog steps per iteration at
2 ** max_tree_depth(default 10).n_walkers (int or str) – emcee only. Number of ensemble walkers;
"auto"(default) chooses a value from the parameter count and CPU cores (must be at least2 * n_dim).n_steps (int) – emcee only. Number of steps per walker (default 2000).
n_burn (int or None) – emcee only. Burn-in steps discarded; if
None(default) it is estimated automatically from the integrated autocorrelation time.n_live (int) – nautilus only. Number of live points (default 2000).
n_eff (int) – nautilus only. Target effective posterior sample size (default 10000).
fit_balmer_broad (bool) – If
True, run BIC selection for a broad Balmer component (narrow vs. intermediate vs. very-broad vs. both), gated by the Hα SNR. DefaultFalse(narrow-only).fit_oiii_broad (bool) – If
True, run an independent BIC test for a broad component on [OIII] 4959/5007 (an outflow signature), gated by the [OIII] 5007 SNR. DefaultFalse.fit_hei_broad (bool) – If
True, run an independent BIC test for a broad He I component shared (with common kinematics per tier) across all observable He I lines, gated by the best narrow He I SNR. DefaultFalse.n_boot_bic (int) – Bootstrap iterations for the BIC model selection;
0uses a single-point BIC. Only used when a broad flag is set (default 100).n_jobs (int) – Number of parallel workers for the BIC bootstrap;
-1uses all cores (default -1).snr_threshold (float) – Minimum Hα SNR required to attempt Balmer broad fitting (default 5.0).
oiii_snr_threshold (float) – Minimum [OIII] 5007 SNR required to attempt [OIII] broad fitting (default 5.0).
hei_snr_threshold (float) – Minimum He I SNR (of the best narrow He I line) required to attempt He I broad fitting (default 5.0).
bic_delta (float) – Minimum ΔBIC by which a more complex model must beat the simpler one to be selected (default 6.0).
tie_balmer_to_oiii (bool) – If
True(default), tie the narrow Balmer (and [NII]) line widths and centroids to [OIII] 5007 in velocity space.tie_uv_doublets (bool) – If
True(default), tie UV doublet kinematics and fix resonance-line flux ratios. Recommended for stacked or poorly resolved spectra.tie_uv_centroids (bool) – When tie_uv_doublets is on, tie each UV doublet’s secondary centroid to its primary in velocity space; if
Falsethe secondary centroids are free (defaultTrue).tie_uv_widths (bool) – If
True(default), tie the widths of the UV intercombination lines (CIII], NIV, NIII, SiIII) to a single shared velocity dispersion.niv_doublet_ratio (float or None) – If given, fix the N IV] flux ratio
F(1483) / F(1486)to this value;None(default) leaves the two amplitudes free.ciii_doublet_ratio (float or None) – If given, fix the C III] flux ratio
F(1909) / F(1907)to this value;None(default) leaves the two amplitudes free.sigma_overrides (dict, optional) – Per-line width bounds
{line_name: (sigma_lo, sigma_hi)}in Angstrom, overriding the automatic grating-based bounds.centroid_overrides (dict, optional) – Per-line centroid bounds
{line_name: (mu_lo, mu_hi)}in Angstrom, overriding the automatic velocity-based bounds.sigma_factor (float) – Multiplier applied to the upper line-width bound; use values > 1 for stacked spectra whose lines are broadened (default 1.0).
centroid_vmax (float) – Maximum centroid offset, in km/s, allowed for each line (default 500.0).
centroid_max_sigma (float) – Extra resolution-aware cap on narrow-line centroid offsets: the margin is
min(centroid_vmax-based, centroid_max_sigma * sigma_instrument)(default 1.0).prior_overrides (dict, optional) – Per-parameter prior overrides keyed by parameter name, e.g.
{"A_OIII_5007": GaussianPrior(1e-17, 1e-18, 0, 1e-15)}. Keys follow theA_<line>/mu_<line>/sigma_<line>convention; values arePriorinstances.progress (bool) – Show a progress bar during sampling (default
True).seed (int) – Random seed for initialisation and sampling (default 42).
- Return type:
- Returns:
MCMCBroadFitResult – When at least one broad flag is
True. Delegates allMCMCResultattributes via properties.MCMCResult – When all broad flags are
False.
- jwspecmcmc.fit_with_broad(spectrum, z, *, sampler='nuts', grating=None, R=None, lines=None, wave_range_A=None, deg=2, clip_sigma=2.5, fit_balmer_broad=False, fit_oiii_broad=False, fit_hei_broad=False, n_boot_bic=100, n_jobs=-1, snr_threshold=5.0, oiii_snr_threshold=5.0, hei_snr_threshold=5.0, bic_delta=6.0, prior_overrides=None, n_walkers='auto', n_steps=2000, n_burn=None, n_live=2000, n_eff=10000, n_warmup=500, n_samples_nuts=2000, n_chains=6, target_accept_prob=0.8, max_tree_depth=10, progress=True, seed=42, sigma_factor=1.0, centroid_vmax=500.0, centroid_max_sigma=1.0, moving_average=False, tie_balmer_to_oiii=True, tie_uv_doublets=True, tie_uv_centroids=True, tie_uv_widths=True, sigma_overrides=None, centroid_overrides=None, niv_doublet_ratio=None, ciii_doublet_ratio=None)[source]
Fit emission lines with BIC-based broad selection, then MCMC.
Phase 1 uses
jwspecfit.fit_with_broad()(fast least-squares) for BIC model selection. Phase 2 runs MCMC on the winning model.Unlike
fit_lines(), this entry point always performs the BIC broad-selection step, so the broad flags below are its primary controls. Every other argument (samplers, continuum, kinematic ties, doublet ratios, line-bound overrides, priors) is identical tofit_lines(); see that function’s docstring or the grouped tables in jwspecmcmc — Bayesian MCMC fitting for the full reference.- Parameters:
spectrum (Spectrum) – Input spectrum (observed wavelength, flux, and error arrays).
z (float) – Source redshift.
fit_balmer_broad (bool) – If
True, run BIC selection for a broad Balmer component (narrow vs. intermediate vs. very-broad vs. both), gated by the Hα SNR. DefaultFalse.fit_oiii_broad (bool) – If
True, run an independent BIC test for a broad [OIII] 4959/5007 component (outflow signature), gated by the [OIII] 5007 SNR. DefaultFalse.fit_hei_broad (bool) – If
True, run an independent BIC test for a broad He I component shared across all observable He I lines, gated by the best narrow He I SNR. DefaultFalse.n_boot_bic (int) – Bootstrap iterations for the BIC model selection;
0uses a single-point BIC (default 100).n_jobs (int) – Parallel workers for the BIC bootstrap;
-1uses all cores (default -1).snr_threshold (float) – Minimum Hα SNR to attempt Balmer broad fitting (default 5.0).
oiii_snr_threshold (float) – Minimum [OIII] 5007 SNR to attempt [OIII] broad fitting (default 5.0).
hei_snr_threshold (float) – Minimum He I SNR to attempt He I broad fitting (default 5.0).
bic_delta (float) – Minimum ΔBIC by which a more complex model must beat the simpler one to be selected (default 6.0).
sampler (
str) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)grating (
str|None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)R (
Union[float,Callable,None]) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)lines (
list[str] |None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)wave_range_A (
tuple[float,float] |None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)deg (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)clip_sigma (
float) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)moving_average (
bool|int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_walkers (
int|str) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_steps (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_burn (
int|None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_live (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_eff (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_warmup (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_samples_nuts (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)n_chains (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)target_accept_prob (
float) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)max_tree_depth (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)tie_balmer_to_oiii (
bool) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)tie_uv_doublets (
bool) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)tie_uv_centroids (
bool) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)tie_uv_widths (
bool) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)niv_doublet_ratio (
float|None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)ciii_doublet_ratio (
float|None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)sigma_overrides (
dict[str,tuple[float,float]] |None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)centroid_overrides (
dict[str,tuple[float,float]] |None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)sigma_factor (
float) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)centroid_vmax (
float) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)centroid_max_sigma (
float) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)prior_overrides (
dict[str,Any] |None) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)progress (
bool) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)seed (
int) – Identical to the corresponding arguments offit_lines(); see that function or the grouped tables in jwspecmcmc — Bayesian MCMC fitting. (init_from_mleis not exposed here because Phase 2 always initialises from the Phase 1 fit.)
- Return type:
- jwspecmcmc.load_mcmc_result(path)[source]
Load an MCMC result from a
.npzfile.- Parameters:
path (str or Path) – Path to the
.npzfile saved bysave_mcmc_result().- Returns:
Reconstructed result with full posterior chains.
- Return type:
- jwspecmcmc.plot_corner(*args, **kwargs)[source]
Corner plot of posterior samples.
See
jwspecmcmc.plotting.plot_corner()for full documentation.
- jwspecmcmc.plot_flux_posterior(*args, **kwargs)[source]
Flux posterior histogram for a single line.
See
jwspecmcmc.plotting.plot_flux_posterior()for full documentation.
- jwspecmcmc.plot_traces(*args, **kwargs)[source]
Trace plots of MCMC chains.
See
jwspecmcmc.plotting.plot_traces()for full documentation.
- jwspecmcmc.priors_from_bounds(lb_free, ub_free, overrides=None)[source]
Build a
PriorSetfrom parameter bounds.- Parameters:
lb_free (np.ndarray) – Lower bounds for free parameters.
ub_free (np.ndarray) – Upper bounds for free parameters.
overrides (dict mapping int to Prior, optional) – Per-index prior overrides.
- Return type:
- jwspecmcmc.save_mcmc_result(result, path)[source]
Save an MCMC result to a compressed
.npzfile.- Parameters:
result (MCMCResult or MCMCBroadFitResult) – MCMC fitting result to save.
path (str or Path) – Output file path (should end in
.npz).
- Return type:
Modules
MCMC convergence diagnostics. |
|
Save and load MCMC fitting results. |
|
JAX-accelerated likelihood for NUTS/HMC sampling. |
|
Log-likelihood and log-probability for MCMC sampling. |
|
Diagnostic plots for MCMC results. |
|
Prior distributions for MCMC sampling. |
|
MCMC result containers. |
|
MCMC sampler wrappers for emcee, nautilus, and NumPyro NUTS. |