Results¶
Output parsing: parameter tables, spectra tables, and FITS HDU lists.
These functions transform raw posterior samples + ModelArgs
into user-friendly Table objects and FITS files.
- unite.results.count_parameters(model_fn, model_args)[source]¶
Count the number of free scalar parameters (degrees of freedom) in the model.
Traces the model with a dummy PRNG key and counts every latent (non-observed) sample site, summing the sizes of all their shapes. This gives the total number of unconstrained scalar parameters — i.e. the model degrees of freedom.
- Return type:
- Parameters:
- Returns:
- int
Total number of free scalar parameters.
Examples
>>> model_fn, model_args = builder.build() >>> print(f'Free parameters: {count_parameters(model_fn, model_args)}') Free parameters: 14
- unite.results.make_parameter_table(samples, args, *, percentiles=None)[source]¶
Build an Astropy table of posterior parameter samples in physical units.
- Return type:
- Parameters:
- samplesdict of str to ndarray
Posterior samples in physical space. When using
ModelBuilder.fit(), samples are already transformed. When callingmcmc.get_samples()directly, first pass throughtransform_reparam_samples()to convert any reparameterized (unit-space) parameters back to physical values.- argsModelArgs
Model arguments from
ModelBuilder.build().- percentilesndarray of float or None
Array of percentile values in range (0, 1), e.g.
[0.16, 0.5, 0.84]. If provided, returns one row per percentile with percentile values. IfNone(default), returns one row per posterior sample.
- Returns:
- astropy.table.QTable
If
percentilesisNone: one row per posterior sample. Ifpercentilesis provided: one row per percentile with apercentilecolumn and one column per parameter. Columns carry physical units where known:Line flux parameters —
flux_unit * canonical_wl_unitFWHM parameters — km/s
Continuum
scaleparameters —flux_unitContinuum
slope/ polynomial coefficients —flux_unit / wl_unit^nShape / index parameters (
beta,temperature, …) — raw valuesRest equivalent width columns (
rew_{line_label}) —canonical_wl_unit. One column per line whose rest-frame wavelength falls within a continuum region. Appended after all model parameters when a continuum is present.
- Parameters:
Notes
For absorption lines, the rest equivalent width is computed by numerically integrating the absorbed flux profile over the spectrum with the finest pixel grid covering the line. Use absorption REW values with caution when the covering spectrum does not fully resolve the absorption profile.
- unite.results.make_spectra_tables(samples, args, *, insert_nan=False, percentiles=None, return_hdul=False)[source]¶
- Overloads:
samples (dict[str, np.ndarray]), args (ModelArgs), insert_nan (bool), percentiles (np.ndarray | None), return_hdul (Literal[False]) → dict[str, Table]
samples (dict[str, np.ndarray]), args (ModelArgs), insert_nan (bool), percentiles (np.ndarray | None), return_hdul (Literal[True]) → fits.HDUList
- Parameters:
- Return type:
Build per-spectrum tables of model decompositions.
- Parameters:
- samplesdict of str to ndarray
Posterior samples.
- argsModelArgs
Model arguments from
ModelBuilder.build().- insert_nanbool
If
True, insert one NaN row at the midpoint wavelength between each pair of consecutive continuum regions. DefaultFalse.- percentilesndarray of float or None
Array of percentile values in range (0, 1), e.g.
[0.16, 0.5, 0.84]. If provided, collapses the sample dimension to those percentiles (shape(n_percentiles, n_pixels)). IfNone(default), returns all samples (shape(n_samples, n_pixels)).- return_hdulbool
If
True, wrap the per-spectrum tables in anHDUListand return that instead of a dict. HDU 0 is an emptyPrimaryHDU; subsequent HDUs areBinTableHDUentries whose extension names are the spectrum names (upper-cased for FITS compatibility). DefaultFalse.
- Returns:
- dict of str to astropy.table.QTable, or astropy.io.fits.HDUList
When
return_hdul=False(default): a dict keyed by spectrum name, one table per spectrum. Whenreturn_hdul=True: anHDUListwith HDU 0 empty and oneBinTableHDUper spectrum. In both cases columns carry physical units whereflux_unitwas set on the spectrum.
- Parameters:
- Return type:
- unite.results.make_hdul(samples, args, *, insert_nan=False, percentiles=None)[source]¶
Build a FITS HDU list from posterior samples.
- Return type:
- Parameters:
- samplesdict of str to ndarray
Posterior samples.
- argsModelArgs
Model arguments from
ModelBuilder.build().- insert_nanbool
Insert NaN rows between continuum regions. Default
False.- percentilesndarray of float or None
Array of percentile values in range (0, 1). If provided, output tables contain percentile rows/columns. If
None(default), output tables contain all samples.
- Returns:
- astropy.io.fits.HDUList
HDU 0: PrimaryHDU (empty, metadata in header). HDU 1: BinTableHDU from parameter table. HDU 2+: BinTableHDU per spectrum.
- Parameters:
Model evaluator: decompose posterior predictions into per-line and per-region contributions.
Given posterior samples and ModelArgs, this module
reconstructs the full model prediction for each spectrum, broken down into
individual line and continuum-region contributions in original flux units.
- class unite.compute.SpectrumPrediction(wavelength, total, lines, continuum_regions)[source]¶
Bases:
objectDecomposed model prediction for a single spectrum.
All arrays are in original (un-normalized) flux units.
For emission lines, each entry in
linesis the intrinsic (un-attenuated) flux profile:flux * profile. This equals the observed contribution when no absorption is present, and ensures thatsum(pred.lines.values()) + sum(pred.continuum_regions.values()) == pred.totalholds exactly for single-absorber models.For absorption lines, each entry in
linesis the flux removed by that absorber (negative):total - total_without_j.- Parameters:
- unite.compute.evaluate_model(samples, args)[source]¶
Evaluate the model for each posterior sample and decompose contributions.
Uses
jax.vmap()to evaluate all samples in a single vectorised XLA kernel launch rather than a Python loop, giving a large speed-up when the number of posterior samples is large.- Return type:
- Parameters:
- samplesdict of str to ndarray
Posterior samples as returned by
mcmc.get_samples()orPredictive. Each value has shape(n_samples,)or(n_samples, ...).- argsModelArgs
Pre-built data bundle from
ModelBuilder.build().
- Returns:
- list of SpectrumPrediction
One prediction per spectrum in
args.spectra.
- Parameters: