Understanding model structure through parameter provenance tags

plot model summary walkthrough
/tengri/src/tengri/forward/sed_model.py:13777: WildcardPartialFreeWarning: sfh={'all_params': FREE} no longer frees metallicity parameters when there is no explicit met block. Before this change, met_logzsol (and other met_* params) were freed by the sfh wildcard.

To free metallicity parameters explicitly, pass either:
  met={'all_params': FREE}
or:
  met={'logzsol': Uniform(-2, 0.2)}

Issue #1796
  spec = parse_groups(ssp_data=ssp_data, **groups)
/tengri/src/tengri/forward/sed_model.py:13777: WildcardPartialFreeWarning: 'all_params: FREE' freed 5 of 6 parameters in group 'sfh'. These have no declared prior, only Fixed defaults, so they stay pinned:
  sfh_tsnorm_peak_lbt_gyr
The fit will run with that physics held constant. Pass explicit priors for the ones you meant to vary, e.g. sfh={'tsnorm_peak_lbt_gyr': Uniform(lo, hi)}, or filter WildcardPartialFreeWarning if this is deliberate.
  spec = parse_groups(ssp_data=ssp_data, **groups)
/tengri/examples/quickstart/plot_model_summary_walkthrough.py:31: DefaultFixedParametersWarning: Group 'neb' states no 'all_params' disposition, so its remaining 8 parameters were fixed at declared defaults:
  neb_dig_delta_logU=-1, neb_dig_frac=0, neb_eline_sigma_kms=100, neb_fdust_frac=0, neb_fesc=0, neb_fesc_lya=1, neb_logU=-3, neb_logZ_gas=-0.3

To fit them, pass 'all_params': FREE:
  neb={'all_params': FREE, ...}
To keep them fixed and silence this warning, say so explicitly:
  neb={'all_params': Fixed(DEFAULT), ...}
  model = tengri.SEDModel.build(
/tengri/src/tengri/forward/sed_model.py:13787: SFHBeyondOldestTemplateWarning: The SSP grid's oldest template is 12.589 Gyr but the universe is 13.090 Gyr old at redshift 0.05. Stars formed in that gap are older than every template, so both age kernels assign them to the oldest one: the formed mass is conserved, and those stars carry the colors of a 12.589 Gyr population. Use a grid whose oldest template reaches 13.090 Gyr (e.g. MIST) to remove the approximation.
  return cls(
/tengri/src/tengri/components/nebular/ionizing_spectrum.py:350: 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:362: 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:364: 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:364: RuntimeWarning: invalid value encountered in scalar subtract
  d_logQ_dα = (x_max_alpha * ln_xmax - x_min_alpha * ln_xmin) / denom - 1.0 / alpha

import os

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

import warnings

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

import tengri
from tengri.plot import setup_style

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

# Load bare-stellar SSP via the public loader (Cue requires a bare SSP).
ssp = tengri.load_ssp("fsps_prsc_miles_chabrier")

# Build a model with deliberately mixed provenance sources.
# - sfh: tsnorm with FREE wildcards except one fixed param
# - dust: two-component with a Fixed(DEFAULT) wildcard but a user override on tau_bc
# - neb: all defaults (no wildcard)
# - redshift: explicit user value
model = tengri.SEDModel.build(
    ssp,
    sfh={
        "type": "tsnorm",
        "all_params": tengri.FREE,
        "logzsol": tengri.Fixed(-0.1),  # [user] override on a FREE wildcard
    },
    dust_attenuation={
        "type": "two_component",
        "law": "calzetti",
        "all_params": tengri.Fixed(tengri.DEFAULT),
        "tau_bc": 0.5,  # [user] override on a Fixed(DEFAULT) wildcard
    },
    neb={"type": "cue"},  # All defaults
    redshift=tengri.Fixed(0.05),  # [user]
)

# Capture the summary() output as a string
summary_out = model.spec.summary_str()

# Create a sample parameter dict for the SED prediction
key = jax.random.PRNGKey(0)
params = dict(model.spec.sample(key))
# Override a few to show variability. The peak is sampled as a fraction of the age of
# the universe at the model redshift, so a peak 3 Gyr ago is 3 / age(z) of it.
age_z = float(tengri.cosmology.age_at_z(0.05))  # Gyr
params["sfh_tsnorm_log_total_mass"] = jnp.float64(11.5)
params["sfh_tsnorm_peak_lbt_frac"] = jnp.float64(3.0 / age_z)
params["sfh_tsnorm_skew"] = jnp.float64(-0.2)

# Predict rest-frame SED
sed = model.predict(params)
wave = np.asarray(model.wavelengths)
nu = 2.998e18 / wave  # Å/s -> Hz
nu_l_nu = nu * np.asarray(sed.rest_sed())

# Create a 2-panel figure:
# LEFT: text rendering of summary (monospace, annotated)
# RIGHT: the predicted SED
fig, (ax_text, ax_sed) = plt.subplots(
    1, 2, figsize=(13.5, 5.0), gridspec_kw={"width_ratios": [1.3, 1]}
)

# LEFT panel: render the summary text in monospace
ax_text.axis("off")
ax_text.set_xlim(0, 1)
ax_text.set_ylim(0, 1)

# Render the summary in monospace font, aligned top-left
y_pos = 0.98
lines = summary_out.split("\n")
for line in lines:
    ax_text.text(
        0.02,
        y_pos,
        line,
        fontfamily="monospace",
        fontsize=8,
        verticalalignment="top",
        transform=ax_text.transAxes,
    )
    y_pos -= 0.035

# RIGHT panel: rest-frame SED
ax_sed.loglog(wave, nu_l_nu, lw=1.8, color="C0")
ax_sed.set_xlim(800, 3e4)
ax_sed.set_ylim(1e40, 5e43)
ax_sed.set_xlabel(r"Rest-frame wavelength $\lambda$ [$\mathrm{\AA}$]")
ax_sed.set_ylabel(r"$\nu L_\nu$  [erg s$^{-1}$]")
ax_sed.grid(True, alpha=0.2, which="both")

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

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

Gallery generated by Sphinx-Gallery