High-level fitting and results#

The package root exposes only the config-driven fitting and result API.

Gaussian-process signal separation for 21-cm observations.

ML-GPR models a visibility cube as the sum of named Gaussian-process components, commonly intrinsic foregrounds, chromatic mode mixing, the 21-cm signal, and measured thermal noise. It fits the covariance hyperparameters and returns posterior realizations of each component rather than one deterministic foreground model.

The package has two deliberately separate API levels. Most analyses should use the configuration-driven interface exposed here:

from ps_eor.ml_gpr import MLGPRConfigFile, MLGPRForegroundFitter

config = MLGPRConfigFile.load_with_defaults('ml_gpr.toml')
fitter = MLGPRForegroundFitter(config)
noise_for_fit = fitter.process_noise_cube(noise_cube)
result = fitter.run(data_cube, noise_for_fit)

ps_eor = result.get_ps_eor(
    ps_gen,
    kbins,
    n_pick=50,
)
ps_eor.get_ps3d().plot()

The result contains a posterior distribution. n_pick selects how many posterior hyperparameter samples are propagated through GP prediction and power-spectrum estimation. The result can also return foreground or residual realizations and can be saved and reloaded.

Advanced users can assemble the model directly from the lower-level submodules:

from ps_eor.ml_gpr.multidata import MultiData
from ps_eor.ml_gpr.kernels import UVScaledKernel
from ps_eor.ml_gpr.regressor import MultiGPRegressor
from ps_eor.ml_gpr.samplers import MCMCSampler

The package root intentionally exposes only MLGPRConfigFile, MLGPRForegroundFitter, MLGPRResult, and MLGPRInjResult. Kernels, regressors, samplers, priors, covariance helpers, and VAE training utilities remain in their corresponding submodules. See the numbered notebook series for complete workflows and validation examples.

Configuration-driven ML-GPR fitting and posterior result products.

class ps_eor.ml_gpr.fitter.MLGPRForegroundFitter(ml_gpr_config: MLGPRConfigFile)[source]#

Bases: AbstractForegroundFitter

Run the configured ML-GPR model on data and noise cubes.

Parameters:

ml_gpr_config – Complete ML-GPR configuration, usually loaded with MLGPRConfigFile.load_with_defaults().

Unlike a deterministic ps_eor.fgfit fitter, run() returns posterior samples. Use MLGPRResult to generate component cubes, residuals, or power-spectrum distributions.

process_noise_cube(noise_cube, sefd_poly_fit_deg=0, sefd_filter_n_bins=0)[source]#

Apply the configured noise preprocessing and simulation steps.

Depending on kern.noise, this may subtract PCA modes, frequency difference the input, estimate and rescale baseline noise, or replace the input by a simulated noise or NoiseStdCube.

Parameters:
  • noise_cube – Noise proxy on the same geometry as the fitted data.

  • sefd_poly_fit_deg – Polynomial degree used when scaling baseline noise from a frequency-dependent SEFD.

  • sefd_filter_n_bins – Number of SEFD bins used to reject anomalous baseline noise.

Returns:

Noise representation used by the fit.

Return type:

ps_eor.datacube.CartDataCube

run(data_cube, data_cube_noise, live_update=False, verbose=False)[source]#

Fit data_cube and return an MLGPRResult.

The sampler and its settings come from the configuration.

Parameters:
  • data_cube – Visibility cube to decompose.

  • data_cube_noise – Noise proxy with matching frequency and UV geometry. Call process_noise_cube() first when the configured preprocessing is required.

  • live_update – Display sampler progress plots when supported.

  • verbose – Print sampler progress and diagnostics.

Returns:

Posterior samples, model configuration, and methods for generating component cubes and power spectra.

Return type:

MLGPRResult

class ps_eor.ml_gpr.fitter.MLGPRResult(sampler_result: SamplerResult, ml_gpr_config: MLGPRConfigFile)[source]#

Bases: object

Posterior samples and derived products from an ML-GPR fit.

config#

Configuration used to construct the model.

sampler_result#

Low-level SamplerResult.

static load(save_dir, save_name, sampler_method=None)[source]#

Load a result saved with save().

The sampler type is inferred when sampler_method is omitted.

Parameters:
  • save_dir – Directory containing the saved run.

  • save_name – Common filename prefix used by save().

  • sampler_method – Optional explicit 'mcmc', 'nested', 'ultranest', 'map', or 'nuts' selection.

Returns:

Reconstructed model and posterior samples.

Return type:

MLGPRResult

save(save_dir, save_name)[source]#

Save input cubes, configuration, samples, and diagnostics.

Parameters:
  • save_dir – Destination directory, created when necessary.

  • save_name – Common filename prefix for the saved products.

get_ps(ps_gen, kbins, kern_name, n_pick=50, subtract_from=None, fill_gaps=False)[source]#

Return posterior power spectra for matching components.

kern_name accepts glob patterns such as 'eor*' and 'fg*'. Each of the n_pick posterior realizations is sent to ps_gen and accumulated in a PsStacker. If subtract_from is given, residual spectra are computed instead. Repeated calls intentionally use new realizations; seed NumPy and Torch before calling for reproducible results.

get_ps_fg(ps_gen, kbins, n_pick=50, fill_gaps=False)[source]#

Return posterior foreground power spectra.

get_ps_eor(ps_gen, kbins, n_pick=50, fill_gaps=False)[source]#

Return posterior EoR power spectra.

get_ps_res(ps_gen, kbins, n_pick=50, fill_gaps=False)[source]#

Return power spectra after subtracting the foreground model.

get_scaled_noise_cube()[source]#

Return the input noise cube scaled by the inferred noise amplitude.

get_noise_cube()[source]#

Return the noise cube used by the fit.

get_data_cube()[source]#

Return the data cube used by the fit.

get_interpolated_i_cube()[source]#

Return the data with missing frequency channels filled by the GP.

get_component_cubes(n_pick, kern_name='eor', subtract_from=None, fill_gaps=False)[source]#

Return posterior cube realizations for matching components.

Repeated calls intentionally produce different realizations. Seed NumPy and Torch before calling for reproducible draws.

get_component_cube(kern_name='eor', subtract_from=None, fill_gaps=False)[source]#

Return one posterior cube realization for matching components.

Repeated calls intentionally produce different realizations. Seed NumPy and Torch before calling for a reproducible draw.

get_residual_cubes(n_pick, fill_gaps=False)[source]#

Yield data-minus-foreground cube realizations.

get_residual_cube(fill_gaps=False)[source]#

Return one data-minus-foreground cube realization.

class ps_eor.ml_gpr.fitter.MLGPRInjResult(sampler_result: SamplerResult, ml_gpr_config: MLGPRConfigFile, data_inj: CartDataCube)[source]#

Bases: MLGPRResult

An MLGPRResult that also retains the injected signal cube.

get_inj_cube()[source]#

Return the injected signal cube.

static load(save_dir, save_name, data_inj, sampler_method=None)[source]#

Load a result and attach its injected signal cube.