Skip to content

Analysis

DataContainer reads one or more MultiNest runs with their setup metadata, and summarises the posterior on \(\Delta^2_{21}(k)\) in each bin. The plotting functions take a DataContainer and return Matplotlib figures and axes. See posterior analysis for a guide.

from bayeseor_jax import DataContainer
from bayeseor_jax.analyze import plot_power_spectra_and_posteriors

dc = DataContainer(["outputs/multinest"])
fig, (power_ax, posterior_axes) = plot_power_spectra_and_posteriors(dc)

Saving the standard analysis

bayeseor_jax.analyze.plotting.save_analysis

save_analysis(sampler_dir, *, output_dir, label='BayesEoR', metadata_dir=None, expected_ps=None, uplim_inds=None)

Save weighted posterior summaries and the combined analysis PNG.

Parameters:

Name Type Description Default
sampler_dir Path or str

Completed MultiNest output directory. Samples and weights are read only.

required
output_dir Path or str

Destination for posterior_summary.json and the combined PNG. Existing analysis products with these names are replaced, not sampler outputs.

required
label str

Model description included in every figure title and legend.

'BayesEoR'
metadata_dir Path or str

Setup directory containing args.json and k-bin metadata, if separate from the sampler products. Prior shading uses these saved bounds.

None
expected_ps float or array - like

Reference dimensional spectrum in mK² Mpc³, displayed without changing posterior constraints. Omit for observations without a known reference.

None
uplim_inds sequence of bool

True for bins displayed as 95% upper limits instead of central credible intervals. The marginal posterior panels and summaries remain unchanged.

None

Returns:

Type Description
dict

Weighted means, medians, credible intervals and upper limits in mK², together with the representative wavenumbers and sampler path.

Results

bayeseor_jax.analyze.results.DataContainer

Load runs and summarise their weighted Δ²(k) posteriors in mK².

Parameters:

Name Type Description Default
dirnames sequence of str or pathlib.Path

MultiNest output directories containing a weighted chain and k-vals.txt. Optional args.json supplies prior bounds; k-vals-bins.txt supplies edges.

required
labels sequence of str

One plotting label per run; defaults to directory names.

None
metadata_dirs str, pathlib.Path or sequence of paths

Separate setup directory containing k-bin files and args.json. Supply one directory shared by all runs or one per run. Defaults to dirnames; chains and summary.json are always read from the run directories.

None
bins_correspond bool

Explicitly confirm that bins in different runs describe corresponding spherical shells in the same order, despite different mean k values. Required for posterior overlays when differences exceed roundoff. This does not rebin samples or alter the physical k values.

False
cred_intervals float or sequence of float

Central credible intervals in percent, defaulting to 68 and 95.

(68, 95)
uplim_quantile float

One-sided upper-limit quantile, defaulting to 0.95.

0.95
expected_ps float or array - like

Reference P(k) or Δ²(k), respectively. Supply at most one: a scalar or one value per bin. P(k) is converted separately on each run's k grid.

None
expected_dmps float or array - like

Reference P(k) or Δ²(k), respectively. Supply at most one: a scalar or one value per bin. P(k) is converted separately on each run's k grid.

None

Attributes:

Name Type Description
samples, weights, log_likelihoods list of numpy.ndarray

Log10 power samples, normalised posterior weights and log likelihoods from MultiNest columns 2 onward, 0 and -0.5 times column 1, respectively.

k_vals, k_vals_bins list

Physical wavenumbers and optional bin edges for each run, in Mpc⁻¹.

avgs, medians, uplims list of numpy.ndarray

Weighted means, medians and upper limits in linear mK².

cred_intervals list of dict

Per-run interval bounds, indexed by percentage and then 'lo' or 'hi'.

expected_spectra list

Reference Δ²(k) arrays, or None for each run if no reference was given.

args, summaries list of dict

Optional configuration and runner metadata, including evidence values.

Notes

This reader always honours MultiNest weights. It does not classify bins as detections: callers choose which constraints to display as upper limits. Foreground-only analytic runs have no power-spectrum chain; read their summary.json and map_coefficients.npy directly instead.

Plotting

bayeseor_jax.analyze.plotting.plot_power_spectra_and_posteriors

plot_power_spectra_and_posteriors(data, *, cred_interval=68, uplim_inds=None, plot_priors=False, colors=None, bins=31, normalisation='peak')

Place the power-spectrum constraints beside their marginal posteriors.

Parameters:

Name Type Description Default
data DataContainer

Runs with matching grids or explicitly confirmed corresponding bins.

required
cred_interval float

Central credible interval in percent.

68
uplim_inds sequence

Upper-limit masks, as accepted by plot_power_spectra.

None
plot_priors bool

Shade the stored prior bounds in both panels.

False
colors sequence of colors

One color per run, shared by both panels. Defaults to blue for 21-cm-only models and red for joint 21-cm + foreground models.

None
bins int

Number of logarithmic histogram bins per marginal posterior.

31
normalisation (peak, density)

Histogram normalisation, as accepted by plot_posteriors.

"peak"

Returns:

Type Description
fig, axes : matplotlib.figure.Figure, tuple

Figure and (power-spectrum axis, posterior axes array).

bayeseor_jax.analyze.plotting.plot_power_spectra

plot_power_spectra(data, *, cred_interval=68, uplim_inds=None, plot_priors=False, colors=None, ax=None)

Plot Δ²(k) medians, credible intervals and selected upper limits.

Parameters:

Name Type Description Default
data DataContainer

Weighted posterior results, optionally including reference spectra.

required
cred_interval float

Stored central interval to display, in percent.

68
uplim_inds sequence of bool or sequence of sequences

True for bins displayed as upper limits. Supply one shared mask or one mask per run. By default all bins display central credible intervals.

None
plot_priors bool

Shade the prior support, requiring prior bounds and physical bin edges.

False
colors sequence of colors

One Matplotlib color per run. Defaults to blue for 21-cm-only models and red for joint 21-cm + foreground models.

None
ax Axes

Existing axes; otherwise create a new figure.

None

Returns:

Type Description
fig, ax : matplotlib.figure.Figure, matplotlib.axes.Axes

Plot objects for subsequent layout and styling changes.

Notes

Compared runs receive small display-only horizontal offsets to separate error bars. Physical k values and calculated constraints remain unchanged.

bayeseor_jax.analyze.plotting.plot_posteriors

plot_posteriors(data, *, bins=31, plot_priors=False, colors=None, axes=None, normalisation='peak')

Plot compact, stacked marginal posteriors on a shared logarithmic axis.

Parameters:

Name Type Description Default
data DataContainer

Runs with matching grids or explicitly confirmed corresponding bins.

required
bins int

Number of equal-width log10-power histogram bins. Compared runs use the same edges within each k bin, spanning priors when shaded and all positive-weight samples. Curves are peak-normalised by default.

31
plot_priors bool

Shade each run's prior support from args.json.

False
colors sequence of colors

One Matplotlib color per run. Defaults to blue for 21-cm-only models and red for joint 21-cm + foreground models.

None
axes sequence of matplotlib.axes.Axes

One existing axis per k bin; otherwise create a vertical stack.

None
normalisation (peak, density)

Peak normalisation compares posterior shapes, not probability heights. Choose density for a unit-integral density per dex. Neither changes the weighted samples or the reported constraints.

"peak"

Returns:

Type Description
fig, axes : matplotlib.figure.Figure, numpy.ndarray

Figure and a one-dimensional axes array, including for a single k bin.

Unit conversions

Convert between \(P(k)\), in mK² Mpc³, and \(\Delta^2(k) = k^3 P(k)/2\pi^2\), in mK².

bayeseor_jax.analyze.results.ps_to_dmps

ps_to_dmps(power, k)

Convert P(k) in mK² Mpc³ to Δ²(k) in mK² at k in Mpc⁻¹.

Parameters:

Name Type Description Default
power array - like

Power and wavenumbers with broadcast-compatible shapes.

required
k array - like

Power and wavenumbers with broadcast-compatible shapes.

required

Returns:

Type Description
ndarray

Dimensionless power, P(k) k³ / (2π²).

bayeseor_jax.analyze.results.dmps_to_ps

dmps_to_ps(power, k)

Convert Δ²(k) in mK² to P(k) in mK² Mpc³ at k in Mpc⁻¹.

Parameters:

Name Type Description Default
power array - like

Power and wavenumbers with broadcast-compatible shapes.

required
k array - like

Power and wavenumbers with broadcast-compatible shapes.

required

Returns:

Type Description
ndarray

Dimensional power, Δ²(k) 2π² / k³.