kinextract.build_template_matrix_fortran
- kinextract.build_template_matrix_fortran(xg: ndarray, template_paths: list[str]) tuple[ndarray, ndarray, ndarray, ndarray][source]
Build the full (npix, ntemplates) stellar template matrix.
Loads every template listed in template_paths, median-normalizes each to a flux level of approximately 1.0, and interpolates it onto the galaxy wavelength grid xg. The resulting matrix is what
kinextract.numericsconvolves with a trial LOSVD (one column at a time, weighted by a fitted per-template amplitude) to build the model spectrum for chi-squared minimization.Median normalization is required when templates are supplied in physical flux units (e.g. MUSE spectral library
.datfiles in erg cm⁻² s⁻¹ Å⁻¹) so their scale matches the galaxy spectrum, which is itself close to unity after ALS or pre-normalization.- Parameters:
- Returns:
T (ndarray, shape (npix, ntemplates)) – Template matrix on the galaxy grid, each column normalized so its flux values are of order 1.
T_err (ndarray, shape (npix, ntemplates)) – Per-pixel template flux uncertainty, normalized identically to T. Columns are all-zero for templates whose file had no error column.
outside_each (ndarray of bool, shape (npix, ntemplates)) – True where a given template has no wavelength coverage at a given pixel – used to exclude just that template (not the whole pixel) from the per-pixel mixture when template libraries have slightly different native wavelength ranges (the common case for real libraries assembled from more than one source/run).
outside_all (ndarray of bool, shape (npix,)) – True at pixels that fall outside the wavelength coverage of every template in the list; such pixels carry no template information at all and are typically masked out of the fit (
gerrset to BIG).