Recipes for common science cases

plot recipes gallery
/tengri/src/tengri/forward/sed_model.py:8580: WildcardPartialFreeWarning: 'all_params: FREE' freed 2 of 3 parameters in group 'dust'. These have no declared prior, only Fixed defaults, so they stay pinned:
  dust_f_obscuration
The fit will run with that physics held constant. Pass explicit priors for the ones you meant to vary, e.g. dust={'f_obscuration': Uniform(lo, hi)}, or filter WildcardPartialFreeWarning if this is deliberate.
  spec = parse_groups(**groups)
/tengri/src/tengri/forward/orchestrator.py:951: SFHBeforeBigBangWarning: Star formation history forms 5% of its stellar mass before the Big Bang at z=5.18 (cosmic age 1.12 Gyr). That mass is truncated, so the prediction does not reflect the requested SFH — bound the SFH age parameter or the redshift to keep star formation within cosmic time.
  state = component.apply(state, sliced, ssp_data=ssp_data, template_data=template_data)
/tengri/src/tengri/forward/sed_model.py:8580: WildcardPartialFreeWarning: 'all_params: FREE' freed 2 of 3 parameters in group 'sfh'. These have no declared prior, only Fixed defaults, so they stay pinned:
  sfh_dexp_start_gyr
The fit will run with that physics held constant. Pass explicit priors for the ones you meant to vary, e.g. sfh={'dexp_start_gyr': Uniform(lo, hi)}, or filter WildcardPartialFreeWarning if this is deliberate.
  spec = parse_groups(**groups)
/tengri/src/tengri/forward/sed_model.py:8580: WildcardPartialFreeWarning: 'all_params: FREE' freed 2 of 3 parameters in group 'dust'. These have no declared prior, only Fixed defaults, so they stay pinned:
  dust_f_obscuration
The fit will run with that physics held constant. Pass explicit priors for the ones you meant to vary, e.g. dust={'f_obscuration': Uniform(lo, hi)}, or filter WildcardPartialFreeWarning if this is deliberate.
  spec = parse_groups(**groups)
/tengri/src/tengri/forward/orchestrator.py:951: SFHBeforeBigBangWarning: Star formation history forms 5% of its stellar mass before the Big Bang at z=5.18 (cosmic age 1.12 Gyr). That mass is truncated, so the prediction does not reflect the requested SFH — bound the SFH age parameter or the redshift to keep star formation within cosmic time.
  state = component.apply(state, sliced, ssp_data=ssp_data, template_data=template_data)
/tengri/src/tengri/forward/sed_model.py:8580: WildcardPartialFreeWarning: 'all_params: FREE' freed 2 of 3 parameters in group 'dust'. These have no declared prior, only Fixed defaults, so they stay pinned:
  dust_f_obscuration
The fit will run with that physics held constant. Pass explicit priors for the ones you meant to vary, e.g. dust={'f_obscuration': Uniform(lo, hi)}, or filter WildcardPartialFreeWarning if this is deliberate.
  spec = parse_groups(**groups)
/tengri/src/tengri/forward/orchestrator.py:951: SFHBeforeBigBangWarning: Star formation history forms 38% of its stellar mass before the Big Bang at z=10.43 (cosmic age 0.45 Gyr). That mass is truncated, so the prediction does not reflect the requested SFH — bound the SFH age parameter or the redshift to keep star formation within cosmic time.
  state = component.apply(state, sliced, ssp_data=ssp_data, template_data=template_data)

import os

os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"  # suppress XLA/PjRt C++ INFO+WARNING logs

import warnings

import jax
import matplotlib.pyplot as plt
import numpy as np

import tengri
from tengri import recipes
from tengri.plot import setup_style

setup_style()
warnings.filterwarnings("ignore", message=".*BakedInBackend.*")
warnings.filterwarnings("ignore", message=".*wNE.*")

C_AA_PER_S = 2.998e18

# Load bare-stellar SSP (required by Cue nebular backend in 4 of 5 recipes)
BARE = tengri.load_ssp("fsps_prsc_miles_chabrier")

# Recipe configurations with display colors
RECIPES = [
    ("star_forming_photometry", recipes.star_forming_photometry, "#1f77b4"),
    ("quiescent_z0", recipes.quiescent_z0, "#d62728"),
    ("agn_panchromatic", recipes.agn_panchromatic, "#9467bd"),
    ("stochastic_sfh_jwst", recipes.stochastic_sfh_jwst, "#2ca02c"),
    ("mock_recovery_minimal", recipes.mock_recovery_minimal, "#ff7f0e"),
]

fig, ax = plt.subplots(figsize=(8, 5.2))

plotted = 0
first_failure: Exception | None = None

for name, recipe_fn, color in RECIPES:
    try:
        # Build model from recipe
        model = tengri.SEDModel.build(ssp_data=BARE, **recipe_fn())
    except Exception as e:
        # One recipe needing an SSP flavor BARE does not carry is a real skip;
        # all of them failing is a broken build path — see the guard below.
        if first_failure is None:
            first_failure = e
        continue

    # Sample at prior medians for canonical SED shape
    params = dict(model.spec.sample(jax.random.PRNGKey(0)))
    out = model.predict(params)

    # Convert to νL_ν for perceptual SED display
    wave = np.asarray(model.wavelengths)
    nu_l_nu = C_AA_PER_S / wave * np.asarray(out.rest_sed())

    ax.loglog(wave, nu_l_nu, color=color, lw=1.6, label=name)
    plotted += 1

if plotted == 0:
    raise RuntimeError(
        f"none of the {len(RECIPES)} recipes built, so this gallery is empty. "
        f"First failure: {type(first_failure).__name__}: {first_failure}"
    ) from first_failure

ax.set(
    xlim=(500, 1e7),
    ylim=(1e37, 1e46),
    xlabel=r"Rest-frame wavelength $\lambda$ [$\mathrm{\AA}$]",
    ylabel=r"$\nu L_\nu$ [erg s$^{-1}$]",
)
ax.legend(frameon=False, fontsize=8.5, loc="lower right")

fig.tight_layout()
plt.savefig("plot_recipes_gallery.png", dpi=150, bbox_inches="tight")

Total running time of the script: (0 minutes 6.355 seconds)

Gallery generated by Sphinx-Gallery