sheap.SheaProducts.Utils.MoldelSpectraReconstruction module

? This requiere alot of cleaning #TODO the name #TODO region info -> for all the regions ?

class RegionInfo(combined_profile, idx_global)[source]

Bases: object

Lightweight region registry entry.

Parameters:
  • combined_profile (Any)

  • idx_global (jax.numpy.ndarray)

combined_profile: Any
idx_global: jax.numpy.ndarray
class MoldelSpectraReconstruction(sheapspectral_template, *, jit_compile=True, posterior_group='montecarlo', posterior_key='posterior_result', samples_field='samples_phys', draws_field='draws_phys', autoload_posterior=True)[source]

Bases: object

Evaluate fused model + per-region components for best-fit params and posterior samples/draws.

On init, the class tries to automatically load posterior arrays and keep them cached:
  • self.samples : (N_obj, N_samp, N_global) or None

  • self.draws : (N_obj, N_draw, N_global) or None

Defaults

posterior_group = “montecarlo” posterior_key = “posterior_result” samples_field = “samples_phys” draws_field = “draws_phys”

reload_posterior()[source]

Force re-read of samples/draws from result.posterior using current config.

Return type:

None

property region_names: Tuple[str, ...]
get_region_info(region_name)[source]
Parameters:

region_name (str)

Return type:

RegionInfo

eval_bestfit_model(wavelength)[source]
Parameters:

wavelength (float)

Return type:

jax.numpy.ndarray

eval_bestfit_region(region_name, wavelength)[source]
Parameters:
  • region_name (str)

  • wavelength (float)

Return type:

jax.numpy.ndarray

eval_batched_model(wavelength, all_samples=None)[source]
Parameters:
  • wavelength (float)

  • all_samples (jax.numpy.ndarray | None)

Return type:

jax.numpy.ndarray

eval_batched_region(region_name, wavelength, all_samples=None)[source]
Parameters:
  • region_name (str)

  • wavelength (float)

  • all_samples (jax.numpy.ndarray | None)

Return type:

jax.numpy.ndarray

eval_batched_components(wavelength, all_samples=None, *, regions=None, include_model=True)[source]
Parameters:
  • wavelength (float)

  • all_samples (jax.numpy.ndarray | None)

  • regions (Iterable[str] | None)

  • include_model (bool)

Return type:

Dict[str, jax.numpy.ndarray]

stars_cont_ratio(wavelength, all_samples=None, *, host_region='host', subtract_regions=('narrow', 'balmer', 'fe', 'broad'), squeeze=True)[source]
Parameters:
  • wavelength (float)

  • all_samples (jax.numpy.ndarray | None)

  • host_region (str)

  • subtract_regions (Tuple[str, ...])

  • squeeze (bool)

Return type:

jax.numpy.ndarray

stars_Cont_5100(all_samples=None)[source]

Uses cached samples by default.

Example

ra = ResultAnalysis(sheap) stars = ra.stars_Cont_5100 # (N_obj, N_samp) if wl dim=1

stars_cont_ratio_bestfit(wavelength, *, host_region='host', subtract_regions=('narrow', 'balmer', 'fe', 'broad'), squeeze=True)[source]
Best-fit version of:

host / (model - narrow - balmer - fe - broad)

Uses self.obj.result.params (best-fit global params), NOT posterior samples.

Parameters:
  • wavelength (float)

  • host_region (str)

  • subtract_regions (Tuple[str, ...])

  • squeeze (bool)

Return type:

jax.numpy.ndarray

property stars_Cont_5100_bestfit: jax.numpy.ndarray

best-fit stars/cont ratio at 5100 Å.

Type:

Convenience

reproduce_one_object(n_obj, *, x=None, samples=None, draws=None)[source]

Reconstruct (evaluate) the model decomposition for a single object on its wavelength grid.

This returns: - per-region component fluxes (for posterior samples, best-fit, and optionally draws) - per-region parameter vectors (same) - full fused-model flux (same) - a “region_sum_*” flux built by summing all region components (same)

If samples/draws are not provided, it tries to use cached self.samples/self.draws.

Parameters:
  • n_obj (int) – Object index.

  • x (jnp.ndarray, optional) – Wavelength grid to evaluate on. If None, uses self.obj.spectra[n_obj, 0, :].

  • samples (jnp.ndarray, optional) – Posterior samples in global parameter space for this object, shape (N_samp, N_global).

  • draws (jnp.ndarray, optional) – Posterior draws in global parameter space for this object, shape (N_draw, N_global).

Returns:

Keys are named to be explicit about: - what is being evaluated (flux vs params) - which parameter set (samples vs bestfit vs draws) - whether it’s per-region or whole-model

Structure: {

”flux_by_region_samples”: {region: (N_samp, N_wave, …), …}, “flux_by_region_bestfit”: {region: (N_wave, …), …}, “flux_by_region_draws”: {region: (N_draw, N_wave, …), …} or None,

”params_by_region_samples”: {region: (N_samp, N_reg), …}, “params_by_region_bestfit”: {region: (N_reg,), …}, “params_by_region_draws”: {region: (N_draw, N_reg), …} or None,

”flux_full_model_samples”: (N_samp, N_wave, …), “flux_full_model_bestfit”: (N_wave, …), “flux_full_model_draws”: (N_draw, N_wave, …) or None,

”flux_region_sum_samples”: (N_samp, N_wave, …), “flux_region_sum_bestfit”: (N_wave, …), “flux_region_sum_draws”: (N_draw, N_wave, …) or None,

}

Return type:

dict

fe_integrated_flux(*, x_min=2250, x_max=2650, n_grid=2000, region_name='fe', all_samples=None, include_bestfit=True, attach_to_posterior=False, attach_component='broad', attach_key='R_Fe')[source]

Integrate the Fe-region component flux over a wavelength window.

This evaluates the region’s combined_profile on a linear wavelength grid and integrates with a trapezoidal rule:

I_Fe = ∫ F_Fe(λ) dλ

By default, this is computed for posterior samples of all objects:

samples -> shape (N_obj, N_samp)

Optionally, it also computes the best-fit integral:

bestfit -> shape (N_obj,)

Optionally, it can attach the per-object sample integrals into the posterior dict under:

posterior_result[obj_key][“basic_params”][attach_component][“extras”][attach_key]

TODO add a coment on the values from Pan+25 :param x_min: Integration bounds in Å. :type x_min: float :param x_max: Integration bounds in Å. :type x_max: float :param n_grid: Number of wavelength points for the integration grid. :type n_grid: int :param region_name: Name of the region in the registry (default “fe”). :type region_name: str :param all_samples: Posterior samples array (N_obj, N_samp, N_global). If None, uses cached

self.samples.

Parameters:
  • include_bestfit (bool) – Also compute best-fit integral from self.obj.result.params.

  • attach_to_posterior (bool) – If True, store the sample integrals in the posterior dict.

  • attach_component (str) – Which basic_params component to attach to (default “broad”).

  • attach_key (str) – Key name inside extras (default “R_Fe”).

  • x_min (float)

  • x_max (float)

  • n_grid (int)

  • region_name (str)

  • all_samples (jnp.ndarray, optional)

Returns:

{

“wavelength_grid”: (N_wave,), “samples”: (N_obj, N_samp), “bestfit”: (N_obj,) or None,

}

Return type:

dict

Parameters:
  • sheapspectral_template (Any)

  • jit_compile (bool)

  • posterior_group (str)

  • posterior_key (str)

  • samples_field (str)

  • draws_field (str)

  • autoload_posterior (bool)