Note
Go to the end to download the full example code.
What each shipped tengri recipe produces¶
Six curated recipes span galaxy populations: star-forming at 0–6 (bare-stellar
SSP), quiescent at z ≈ 0.05 (bare-stellar, τ_diff-free to trace dust),
AGN panchromatic (bare-stellar, full AGN composite with disc+torus+radio+xray),
stochastic JWST high-z with burstiness (bare-stellar, DPL+field at 0.5–12),
mock-recovery minimal (any SSP, 4–5 free params for benchmarking), and
dust-demo (wNE only — baked nebular emission visualized). All use WavePrecomp()
except photoz (ztable does not cover z > 12). Use load_ssp("*.wNE") only
for dust_demo; others silently under-predict if fed wNE.

/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/components/nebular/ionizing_spectrum.py:295: RuntimeWarning: invalid value encountered in scalar divide
log_Q_pred = b - _LOG_H + np.log10(np.abs((x_max_alpha - x_min_alpha) / alpha))
/tengri/src/tengri/components/nebular/ionizing_spectrum.py:307: RuntimeWarning: invalid value encountered in scalar divide
term_Q = b + np.log10(np.abs(denom / alpha)) - log_Q - _LOG_H
/tengri/src/tengri/components/nebular/ionizing_spectrum.py:309: RuntimeWarning: divide by zero encountered in scalar divide
d_logQ_dα = (x_max_alpha * ln_xmax - x_min_alpha * ln_xmin) / denom - 1.0 / alpha
/tengri/src/tengri/components/nebular/ionizing_spectrum.py:309: RuntimeWarning: invalid value encountered in scalar subtract
d_logQ_dα = (x_max_alpha * ln_xmax - x_min_alpha * ln_xmin) / denom - 1.0 / alpha
/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
BARE = tengri.load_ssp("fsps_prsc_miles_chabrier")
SSPS = {
"star_forming_photometry": BARE,
"quiescent_z0": BARE,
"agn_panchromatic": BARE,
"stochastic_sfh_jwst": BARE,
"mock_recovery_minimal": BARE,
"dust_demo": BARE,
}
RECIPE_FNS = [
("star_forming_photometry", recipes.star_forming_photometry, "#3377cc"),
("quiescent_z0", recipes.quiescent_z0, "#cc3333"),
("agn_panchromatic", recipes.agn_panchromatic, "#9933aa"),
("stochastic_sfh_jwst", recipes.stochastic_sfh_jwst, "#33aa55"),
("mock_recovery_minimal", recipes.mock_recovery_minimal, "#aa8833"),
("dust_demo", recipes.dust_demo, "#666666"),
]
fig, ax = plt.subplots(figsize=(7.4, 4.8))
plotted = 0
first_failure: Exception | None = None
for name, recipe_fn, color in RECIPE_FNS:
try:
model = tengri.SEDModel.build(ssp_data=SSPS[name], **recipe_fn())
except Exception as e:
# A recipe that needs an SSP flavor this box does not have is a real
# skip. Every recipe failing is not — see the guard below.
if first_failure is None:
first_failure = e
continue
p = dict(model.spec.sample(jax.random.PRNGKey(0)))
out = model.predict(p)
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.4, label=name)
plotted += 1
# Without this, a build break in every recipe renders an empty axes and the
# gallery runner reports the example as passing -- the exact hole the runner
# exists to close (#1145). Swallowing per-recipe is fine; swallowing all of
# them means the figure shows nothing it claims to compare.
if plotted == 0:
raise RuntimeError(
f"none of the {len(RECIPE_FNS)} recipes built, so this comparison is "
f"empty. First failure: {type(first_failure).__name__}: {first_failure}"
) from first_failure
ax.set(
xlim=(700, 5e6),
ylim=(1e38, 5e45),
xlabel=r"Rest-frame wavelength $\lambda$ [$\mathrm{\AA}$]",
ylabel=r"$\nu L_\nu$ [erg s$^{-1}$]",
)
ax.legend(frameon=False, fontsize=8, loc="lower right")
fig.tight_layout()
plt.savefig("plot_recipe_compare.png", dpi=150, bbox_inches="tight")
Total running time of the script: (0 minutes 30.159 seconds)