BYOST.template#

Template retrieval, GPR prediction, and inverse-PCA reconstruction.

BYOST.template.get_Hsiao_template(epoch)[source]#
Input:

epoch: time since B-band maximum, interger within range -19 to 85

Output:

tuple: wave,flux

BYOST.template.get_Lu2023_NIR_template(epoch, sBV, GPR_score_threshold=0.2)[source]#

Return the Lu2023 NIR spectral template at a given epoch and color stretch.

Reads PCA components and ONNX-serialised Gaussian Process Regression models from BYOST/files/NIR_template_buildingblocks.h5. No scikit-learn is required at runtime; only h5py and onnxruntime are used.

The building blocks are loaded once and cached in _Lu2023_NIR_temp_dict for subsequent calls.

Parameters:
  • epoch (float) – Rest-frame days since B-band maximum of the spectrum.

  • sBV (float) – Color stretch of the SN Ia.

  • GPR_score_threshold (float) – Minimum GPR R^2 score to include a PC in the reconstruction. Default 0.2; pass None to keep all PCs.

Returns:

(wavelength, flux)

  • wavelength (np.ndarray): NIR template wavelength in Angstroms.

  • flux (np.ndarray): NIR template flux in arbitrary units.

Return type:

2-tuple

BYOST.template.get_template(df_buildingblocks, condition1, condition2, PC_select_method=['GPR_score_threshold', 0.2], return_template_error=False, error_MC_num=1000, return_MC_spectra=False)[source]#
input:
df_buildingblocks: pandas dataframe contains resulting pca and gpr

** if there is more than 1 wavelength region (df.shape[0]>1), the wavelength must be aranged from blue to red in the dataframe, and has overlap in neighbouring region in order to enable merging **

condition1: input variable 1, scaler condition2: input variable 2, scaler

** method of selecting which pcs to keep for template flux construction ** pc_select_method = [‘method’,value]

‘gpr_score_threshold’: keep pcs that has gpr r^2 >= gpr_score_threshold ‘PCA_variance_pctg_threshold’: keep PCs up to the one that has total_variance >= PCA_variance_pctg_threshold ‘fixed_PC_number’: keep n (n=fixed_PC_number) first PCs

return_template_error: default False; If True, return the template flux error error_MC_num: will be used is return_template_error=True, the number of the

interations to get the template flux error.

return_MC_spectra: default False, if True, return all the possible spectra during the MC.

Output:

tuple: template_wavelength, template_flux (if return_template_error=False) tuple: template_wavelength, template_flux, template_error (if return_template_error=True and return_MC_spectra=False) tuple: template_wavelength, template_flux, template_error, MC_template_flux (if return_template_error=True and return_MC_spectra=True)

BYOST.template.GPR_predict_PC(GPR_output, condition1, condition2)[source]#
Input:

GPR_output: a pandas dataframe of the fitted gp (and gp scores) for each PC condition_1: input variable 1, scaler condition_2: input variable 2, scaler

Output:

pred_PCs: predicted PC projections, list pred_PC_sigmas: predicted PC projection sigmas, list

BYOST.template.get_single_spectrum_template(df_buildingblock, condition1, condition2, GPR_score_threshold=0.2, PCA_variance_pctg_threshold=None, fixed_PC_number=None, return_template_error=False, error_MC_num=1000, return_MC_spectra=False)[source]#
Input:

df_buildingblock: pandas dataframe contains resulting PCA and GPR condition_1: input variable 1, scaler condition_2: input variable 2, scaler

** method of selecting which PCs to keep for template flux construction ** GPR_score_threshold: keep PCs that has GPR R^2 >= GPR_score_threshold PCA_variance_pctg_threshold: keep PCs up to the one that has total_variance >= PCA_variance_pctg_threshold fixed_PC_number: keep n (n=fixed_PC_number) first PCs

return_template_error: default False; If True, return the template flux error error_MC_num: will be used is return_template_error=True, the number of the

interations to get the template flux error.

return_MC_spectra: default False, if True, return all the possible spectra during the MC.

Output:

tuple: template_wavelength, template_flux (if return_template_error=False) tuple: template_wavelength, template_flux, template_error (if return_template_error=True and return_MC_spectra=False) tuple: template_wavelength, template_flux, template_error, MC_template_flux (if return_template_error=True and return_MC_spectra=True)