Recipe introspection and SED morphology comparison

Call tengri.list_recipes() to see the shipped menu with SSP requirements (bare-stellar, wNE, or any) and tengri.describe_recipe(name) to fetch a recipe’s docstring. Three models showcase the morphological diversity: star-forming (DPL+Cue nebular, free z to 6), quiescent at z=0.05 (dexp, lower dust ceiling), and AGN-panchromatic (full composite, z to 6). All require bare-stellar SSP (Cue backend).

Each SED is normalized to its rest-frame value at 5500 Å to overlay the spectral shapes and highlight morphological differences across recipe types.

plot recipe introspection tour
=== Available Recipes ===
name                     short_doc                                                                ssp_requirement                                                                   data
───────────────────────  ───────────────────────────────────────────────────────────────────────  ────────────────────────────────────────────────────────────────────────────────  ──────────────────────────────────────────────────────────────────────
agn_panchromatic         Recipe for AGN-dominated galaxies with multi-wavelength data.            bare-stellar (Cue nebular backend; see star_forming_photometry for details).      ready
composable_agn           Fully composable AGN — all slots switchable on committed data.           bare-stellar (Cue nebular backend; see star_forming_photometry for details).      ready
dust_demo                Recipe for forward-only dust attenuation gallery sweeps.                 wNE (with-nebular-emission), i.e. load_ssp("prsc_miles_chabrier_wNE"). Uses t...  ready
high_z                   Recipe for high-redshift galaxies (z > 3.5, young starburst).            with-nebular-emission (wNE) SSP grids — the ssp nebular backend reads line an...  ready
mock_recovery_minimal    Recipe for mock data recovery and benchmarking (minimal model).          any. Nebular emission is disabled, so this recipe works with both bare-stella...  ready
photoz                   Recipe for photometric-redshift fits (redshift-unconstrained surveys).   any (nebular emission is off).                                                    ready
quiescent_z0             Recipe for quiescent galaxies at low redshift (z ~ 0.05).                bare-stellar (Cue nebular backend; see star_forming_photometry for details).      ready
star_forming_photometry  Recipe for star-forming galaxies with broadband photometry (0 < z < 6).  bare-stellar (e.g., fsps_prsc_miles_chabrier.h5, fsps_mist_c3k_a_chabrier.h5)...  ready
stochastic_sfh_jwst      Recipe for JWST high-redshift galaxies with stochastic SFH.              bare-stellar (Cue nebular backend; see star_forming_photometry for details).      ready
unified_agn              Synthesizer UnifiedAGN reproduction (disc + NLR/BLR grids).              bare-stellar (Cue nebular backend; see star_forming_photometry for details). ...  needs Synthesizer AGN NLR grid (synthesizer-download --agn-test-grids)
[10 results — recipe]
  Use:  tengri.describe('agn_panchromatic')  →  recipes.agn_panchromatic() → SEDModel.build(ssp_data=ssp, **recipe)


/tengri/src/tengri/forward/sed_model.py:8666: 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:8666: 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:8666: 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)

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 for Cue nebular backend in all recipes)
ssp = tengri.load_ssp("fsps_prsc_miles_chabrier")

# Print the recipe menu to stdout for documentation
print("\n=== Available Recipes ===")
recipe_table = tengri.list_recipes()
print(recipe_table)
print("\n")

# Define the three recipes to showcase
RECIPE_CONFIGS = [
    ("star_forming_photometry", recipes.star_forming_photometry, "#3377cc"),
    ("quiescent_z0", recipes.quiescent_z0, "#cc3333"),
    ("agn_panchromatic", recipes.agn_panchromatic, "#9933aa"),
]

# Compute and plot rest-frame SEDs
fig, ax_seds = plt.subplots(figsize=(8, 5.5))

plotted = 0
first_failure: Exception | None = None

for name, recipe_fn, color in RECIPE_CONFIGS:
    try:
        model = tengri.SEDModel.build(ssp_data=ssp, **recipe_fn())
    except Exception as e:
        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())

    # Normalize to the value at 5500 Å rest to show morphology shapes
    i_norm = int(np.argmin(np.abs(wave - 5500.0)))
    if nu_l_nu[i_norm] > 0:
        nu_l_nu_norm = nu_l_nu / nu_l_nu[i_norm]
    else:
        nu_l_nu_norm = nu_l_nu

    ax_seds.semilogx(wave, nu_l_nu_norm, color=color, lw=1.4, label=name)
    plotted += 1

# Error check: ensure at least one recipe built
if plotted == 0:
    raise RuntimeError(
        f"none of the {len(RECIPE_CONFIGS)} recipes built, so the SED panel is "
        f"empty. First failure: {type(first_failure).__name__}: {first_failure}"
    ) from first_failure

ax_seds.set(
    xlim=(700, 5e6),
    xlabel=r"Rest-frame wavelength $\lambda$ [$\mathrm{\AA}$]",
    ylabel=r"$\nu L_\nu$ / $\nu L_\nu(5500\,\mathrm{\AA})$ (normalized shape)",
)
ax_seds.legend(frameon=False, fontsize=10, loc="lower left")
ax_seds.grid(True, alpha=0.2, which="both")

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

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

Gallery generated by Sphinx-Gallery