milespy.ssp_library.SSPLibrary
- class milespy.ssp_library.SSPLibrary(*args, **kwargs)
Bases:
SingleStellarPopulationLibraryAlias for SingleStellarPopulationLibrary.
- Attributes:
modelsThe spectra (or spectrum-like) object holding the loaded models.
Methods
closest(age, met[, alpha, imf_slope, mass])Return the nearest library SSP to the requested (age, met, alpha, imf_slope).
from_sfh(sfh)Synthesize a composite spectrum from a star formation history (SFH).
in_list(age, met[, alpha, imf_slope, mass])Return SSP models at the exact grid points specified by the input lists.
in_range(age_lims, met_lims[, alpha_lims, ...])Return all SSP models whose parameters fall within the given limits.
interpolate(age, met[, alpha, imf_slope, ...])Interpolate SSP flux at arbitrary (age, met, alpha, imf_slope) using Delaunay triangulation.
resample(new_wave)Resample all models onto the given wavelength grid.
trim(lower, upper)Restrict the spectral range of all models to [lower, upper].
- __init__(*args, **kwargs)
Load an SSP library for the given source, version, isochrone, and IMF type.
- Parameters:
source (str, optional) – Model source: MILES_SSP, CaT_SSP, EMILES_SSP, sMILES_SSP, or path to an HDF5 file.
version (str, optional) – Version string (e.g. “9.1”).
isochrone (str, optional) – “P” (Padova+00) or “T” (BaSTI).
imf_type (str, optional) – IMF shape: “ch” (Chabrier), “ku” (Kroupa universal), “kb” (Kroupa revised), “un” (unimodal), “bi” (bimodal).
- closest(age, met, alpha=None, imf_slope=None, mass=<Quantity 1. solMass>)
Return the nearest library SSP to the requested (age, met, alpha, imf_slope).
“Closest” is defined by the Delaunay triangulation: the grid point with the largest barycentric weight for the requested point is returned (no flux interpolation).
- Parameters:
- Returns:
The single closest spectrum (or one per input if arrays given).
- Return type:
- Raises:
RuntimeError – If the requested point is outside the library grid.
- from_sfh(sfh)
Synthesize a composite spectrum from a star formation history (SFH).
Interpolates SSPs at each (age, metallicity, [alpha/Fe], IMF) in the SFH, weights by the SFH time-bin mass, and sums to produce one spectrum.
- Parameters:
sfh (StarFormationHistory) – Star formation history with time, SFR, met, alpha, imf (and time_weights).
- Returns:
Single spectrum (mass-weighted sum of interpolated SSPs).
- Return type:
- in_list(age, met, alpha=None, imf_slope=None, mass=None)
Return SSP models at the exact grid points specified by the input lists.
No interpolation is performed; each (age, met, alpha, imf_slope) must match a library grid point. All input lists must have the same length.
- Parameters:
age (array-like) – Ages (Gyr) and metallicities (dex) to extract.
met (array-like) – Ages (Gyr) and metallicities (dex) to extract.
alpha (array-like, optional) – [alpha/Fe] values (required if library has variable alpha).
imf_slope (array-like, optional) – IMF slopes at each point.
mass (Quantity, optional) – Mass per SSP (default 1 Msun per spectrum).
- Return type:
- Raises:
ValueError – If lengths differ or a requested grid point is not in the library.
- in_range(age_lims, met_lims, alpha_lims=None, imf_slope_lims=None, mass=<Quantity 1. solMass>)
Return all SSP models whose parameters fall within the given limits.
- Parameters:
age_lims ((low, high) Quantity) – Age limits (e.g. Gyr).
met_lims ((low, high) Quantity) – Metallicity limits (dex).
alpha_lims ((low, high) Quantity, optional) – [alpha/Fe] limits (ignored if library has fixed alpha).
imf_slope_lims ((low, high), optional) – IMF slope limits (default (0, 5)).
mass (Quantity, optional) – Mass to assign to each SSP (default 1 Msun).
- Returns:
Spectra in the selected parameter ranges.
- Return type:
- Raises:
ValueError – If no SSP matches the ranges.
- interpolate(age, met, alpha=None, imf_slope=None, mass=<Quantity 1. solMass>, closest=False, simplex=False, force_interp=[])
Interpolate SSP flux at arbitrary (age, met, alpha, imf_slope) using Delaunay triangulation.
The library grid is triangulated in parameter space. For each requested point, the enclosing simplex (the set of grid points forming the Delaunay cell that contains the point) is found and flux is computed as a barycentric-weighted sum of the vertex spectra. Optionally return only the closest grid point (closest=True) or the simplex vertex spectra with weights in meta (simplex=True).
- Parameters:
age (Quantity) – Desired age (Gyr) and metallicity (dex).
met (Quantity) – Desired age (Gyr) and metallicity (dex).
alpha (Quantity, optional) – Desired [alpha/Fe] (dex).
imf_slope (Quantity, optional) – Desired IMF slope.
mass (Quantity, optional) – Mass per SSP (default 1 Msun).
closest (bool, optional) – If True, return the nearest grid spectrum instead of interpolating.
simplex (bool, optional) – If True and a single point is requested, return the vertex spectra of the enclosing simplex (with weights in meta).
force_interp (list, optional) – Force interpolation over these dimensions even when the value is on the grid; e.g. [“alpha”, “imf_slope”].
- Returns:
Interpolated spectrum (or closest/simplex spectra if requested).
- Return type:
- Raises:
RuntimeError – If any requested point is outside the grid.
ValueError – If input parameter shapes are inconsistent.
- property models
The spectra (or spectrum-like) object holding the loaded models.