kinextract.compute_weighted_template_spectrum

kinextract.compute_weighted_template_spectrum(st: FitState, w: ndarray) ndarray[source]

Compute the weighted mixture of stellar templates for given weights.

Forms the (unconvolved, pre-LOSVD) weighted combination of the template library st.t using weights w, i.e. the same template-mixing step performed inside evaluate_model_gp() before LOSVD convolution. Used to reconstruct the best-fit “input” template spectrum for plotting or output, without having to re-run the full forward model.

Parameters:
  • st (FitState) – Fit state holding the template matrix st.t (shape (npix, nt)) and the outside_tpl coverage mask.

  • w (ndarray) – Template weights, length nt (as fit by the optimizer).

Returns:

Weighted template spectrum, length npix. If the weights sum to a non-positive or non-finite value, returns an array of ones (a flat fallback spectrum) rather than dividing by zero.

Return type:

ndarray

Notes

When st.fortran_template_mixture is False, pixels outside any template’s coverage are excluded from the weighted sum via st.outside_tpl, matching the corresponding logic in evaluate_model_gp().