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:
AbstractForegroundFitterRun 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.fgfitfitter,run()returns posterior samples. UseMLGPRResultto 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 orNoiseStdCube.- 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:
- run(data_cube, data_cube_noise, live_update=False, verbose=False)[source]#
Fit
data_cubeand return anMLGPRResult.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:
- class ps_eor.ml_gpr.fitter.MLGPRResult(sampler_result: SamplerResult, ml_gpr_config: MLGPRConfigFile)[source]#
Bases:
objectPosterior 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_methodis 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:
- 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_nameaccepts glob patterns such as'eor*'and'fg*'. Each of then_pickposterior realizations is sent tops_genand accumulated in aPsStacker. Ifsubtract_fromis 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_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_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.
- class ps_eor.ml_gpr.fitter.MLGPRInjResult(sampler_result: SamplerResult, ml_gpr_config: MLGPRConfigFile, data_inj: CartDataCube)[source]#
Bases:
MLGPRResultAn
MLGPRResultthat also retains the injected signal cube.