BayeSN
bayesn.bayesn_model module
BayeSN SED Model. Defines a class which allows you to fit or simulate from the BayeSN Optical+NIR SED model.
- class bayesn.bayesn_model.SEDmodel(num_devices=4, load_model='T21_model', filter_yaml=None, fiducial_cosmology={'H0': 73.24, 'Om0': 0.28})
Bases:
objectBayeSN-SED Model
Class which imports a BayeSN model, and allows one to fit or simulate Type Ia supernovae based on this model.
- Parameters:
- num_devices: int, optional
If running on a CPU, numpyro will by default see it as a single device - this argument will set the number of available cores for numpyro to use e.g. set to 4, you can train 4 chains on 4 cores in parallel. Defaults to 4.
- load_modelstr, optional
Can be either a pre-defined BayeSN model name (see table below), or a path to directory containing a set of .txt files from which a valid model can be constructed. Currently implemented default models are listed below - default is T21.
M20_model: Mandel+20 BayeSN model (arXiv:2008.07538).Covers rest wavelength range of 3000-18500A (BVRIYJH). No treatment of host mass effects. Global RV assumed. Trained on low-z Avelino+19 (ApJ, 887, 106) compilation of CfA, CSP and others.
T21_model: Thorp+21 No-Split BayeSN model (arXiv:2102:05678).Covers rest wavelength range of 3500-9500A (griz). No treatment of host mass effects. Global RV assumed. Trained on Foundation DR1 (Foley+18, Jones+19).
W22_model: Ward+22 No-Split BayeSN model (arXiv:2209.10558).Covers rest wavelength range of 3000-18500A (BVRIYJH). No treatment of host mass effects. Global RV assumed. Trained on Foundation DR1 (Foley+18, Jones+19) and low-z Avelino+19 (ApJ, 887, 106) compilation of CfA, CSP and others.
- fiducial_cosmologydict, optional
Dictionary containg kwargs
{H0, Om0}for initialising anastropy.cosmology.FlatLambdaCDMinstance. Defaults to Riess+16 (ApJ, 826, 56) cosmology:{H0:73.24, "Om0":0.28}.- filter_yaml: str, optional
Path to yaml file containing details on filters and standards to use. If not specified, will look for a file called filters.yaml in directory that BayeSN is called from.
- Returns:
- out: bayesn_model.SEDmodel instance
- Attributes:
- cosmo: `astropy.cosmology.FlatLambdaCDM`
Defines the fiducial cosmology assumed by the model when training
- RV_MW: float
RV value for calculating Milky Way extinction
- sigma_pec: float
Peculiar velocity to be used in calculating redshift uncertainties, set to 150 km/s
- l_knots: array-like
Array of wavelength knots which the model is defined at
- t_knots: array-like
Array of time knots which the model is defined at
- W0: array-like
W0 matrix for loaded model
- W1: array-like
W1 matrix for loaded model
- L_Sigma: array-like
Covariance matrix describing epsilon distribution for loaded model
- M0: float
Reference absolute magnitude for scaling Hsiao template
- sigma0: float
Standard deviation of grey offset parameter for loaded model
- RV: float
Global host extinction value for loaded model
- tauA: float
Global tauA value for exponential AV prior for loaded model
- spectrum_bins: int
Number of wavelength bins used for modelling spectra and calculating photometry. Based on ParSNiP as presented in Boone+21
- hsiao_flux: array-like
Grid of flux value for Hsiao template
- hsiao_t: array-like
Time values corresponding to Hsiao template grid
- hsiao_l: array-like
Wavelength values corresponding to Hsiao template grid
Methods
dust_model:
Defines numpyro model for inferring dust parameters with population level SN parameters fixed based on previously trained model.
dust_redshift_model:
Defines numpyro model for inferring dust parameters with population level SN parameters fixed based on previously trained model, allowing the means of the RV and AV distribution to linearly evolve with redshift
dust_model_split_mag:
Defines numpyro model for inferring dust parameters, splitting the population in two based on host galaxy stellar mass as well as allowing an intrinsic magnitude offset between the bins. Population level SN parameters are fixed based on previously trained model.
dust_model_split_sed:
Defines numpyro model for inferring dust parameters, splitting the population in two based on host galaxy stellar mass as well as allowing an intrinsic SED difference between the bins. Population level SN parameters are fixed based on previously trained model.
fit_model_globalRV:
Defines numpyro model for fitting latent SN parameters including distance, conditioned on fixed population level parameters based on previously trained model. Assumes single global RV across population.
fit_model_popRV:
Defines numpyro model for fitting latent SN parameters including distance, conditioned on fixed population level parameters based on previously trained model. Assumes truncated Gaussian population RV distribution.
get_flux_batch:
Get integrated fluxes for BayeSN SED model across a large number of SNe, phases and bands.
def get_flux_from_chains:
Get model photometry from BayeSN SED model for posterior samples from model fitting chains.
get_mag_batch:
Get magnitudes for BayeSN SED model across a large number of SNe, phases and bands.
get_spectra:
Get spectra for BayeSN SED model across a large number of SNe and phases.
initial_guess:
Defined method used to initialise chains for model training.
parse_yaml_input:
Parse the input yaml file along with any command line arguments to define the job being run.
postprocess:
Postprocess the output of the MCMC run if required and save the chains and summaries.
process_dataset:
Process a set of data for use by the BayeSN model.
run:
Run an inference job using the BayeSN model.
sample_AV:
Sample AV from the population distribution based on a pre-trained model.
sample_del_M:
Sample delta_M from the population distribution based on a pre-trained model.
sample_epsilon:
Sample epsilon from the population distribution based on a pre-trained model.
sample_theta:
Sample theta from the population distribution based on a pre-trained model.
simulate_light_curve:
Simulate a light curve or set of light curves from the BayeSN SED model.
simulate_spectrum:
Simulate a specrum or set of spectra from the BayeSN SED model.
spline_coeffs_irr_step:
Vectorized version of spline coefficient calculations in spline_utils.
train_model_globalRV:
Defines numpyro model to train the BayeSN SED model assuming a truncated Gaussian RV population distribution.
train_model_popRV:
Defines numpyro model to train the BayeSN SED model assuming a single global fixed RV value across the population.
- dust_model(obs, weights)
Numpryo model used to infer dust properties conditioned on fixed SN population parameters from a previously trained model.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
- Returns:
- dust_model_split_mag(obs, weights)
Numpryo model used to infer dust properties conditioned on fixed SN population parameters from a previously trained model, split into different mass bins above and below 10^10 solar masses. This model allows for a constant intrinsic magnitude offset between the two mass bins
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
- dust_model_split_sed(obs, weights)
Numpryo model used to infer dust properties conditioned on fixed SN population parameters from a previously trained model, split into different mass bins above and below 10^10 solar masses. This model allows for a intrinsic difference in baseline SED (independent of light curve stretch) between the two mass bins
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
- dust_redshift_model(obs, weights)
Numpryo model used to infer dust properties conditioned on fixed SN population parameters from a previously trained model, allowing the mean of the RV and AV distributions to linearly evolve with redshift.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
- Returns:
- fit(t, flux, flux_err, filters, z, ebv_mw=0, peak_mjd=None, filt_map={}, print_summary=True, file_prefix=None, drop_bands=[], fix_tmax=False, fix_theta=False, fix_AV=False, RV=False, mu_R=False, sigma_R=False, mag=False)
Method to fit light curve data loaded into memory with BayeSN model
- Parameters:
- t: array-like
Set of MJDs/rest-frame phases for light curve data to be fit. If you pass MJD and also a peak_mjd, values will automatically be converted to rest-frame phases
- flux: array-like
Set of fluxes/mags for light curve data to be fit. Despite the name, you can use mags and if mag=True data will be automatically converted into flux for fitting.
- flux_err: array-like
Set of flux/mag errors for light curve data to be fit. Despite the name, you can use mags and if mag=True data will be automatically converted into flux for fitting.
- filters: array-like
Set of filters that flux/flux_err are measurements for, telling BayeSN which filters to use when fitting data. Must be of same length as flux/flux_err i.e. specify the filter for each data point individually
- z: float
Heliocentric redshift of SN to be used when fitting
- ebv_mw: float, optional
Milky Way E(B-V) value of SN. Defaults to 0.
- peak_mjd: float or Boolean, optional
Fiducial value for maximum MJD of SN, used to convert phases to rest-frame. Note that this value only needs to be rough as BayeSN will fit for the time of maximum. However, if you set fix_tmax=True then this will be fixed as the time of maximum. Defaults to False, meaning that the code will assume phases are already rest-frame rather than MJD and will not do any conversion
- filt_map: dict, optional
Dictionary providing mapping between filter names in file and BayeSN filters. Defaults to empty dictionary
- print_summary: Boolean, optional
Specifies whether to print fit summary
- file_prefix: str, optional
Prefix of name for output files containing summary table and MCMC samples. Default to None, in which case output files will not be saved and only returned for use in script.
- drop_bands: array-like, optional
List of bands to be ignored during fitting. Defaults to empty list
- fix_tmax: Boolean, optional
If True, tmax will not be inferred and fiducial value in file meta will be fixed. Defaults to False.
- fix_theta: float, optional
Value to fix theta at during fitting. Defaults to False, meaning that theta will be inferred during fitting rather than fixed.
- fix_AV: float, optional
Value to fix AV at during fitting. Defaults to False, meaning that AV will be inferred during fitting rather than fixed.
- RV: float, optional
Value to fix RV at during fitting. Defaults to False, meaning that default model RV treatment will be used.
- mu_R: float, optional
Value of mean of RV distribution to be used during fitting. Defaults to False, meaning that default model RV treatment will be used. If specified, sigma_R must also be specified.
- sigma_R: float, optional
Value of standard deviation of RV distribution. Defaults to False, meaning that default model RV treatment will be used.
- mag: Boolean, optional
Specifies whether data is mag or flux. If True, data is assumed to be mag and is automatically converted to flux before fitting.
- Returns:
- samples: dict
Dictionary containing parameter names as keys and MCMC samples as values
- sn_props: tuple
Tuple containing SN redshift and MW E(B-V), which can be useful to have in memory when making plots
- fit_from_file(path, filt_map={}, peak_mjd_key='SEARCH_PEAKMJD', print_summary=True, file_prefix=None, drop_bands=[], fix_tmax=False, fix_theta=False, fix_AV=False, RV=False, mu_R=False, sigma_R=False, mag=False)
Method to fit light curve contained in SNANA-format text file using BayeSN model
- Parameters:
- path: str
Path to SNANA-format text file containing data to be fit
- filt_map: dict, optional
Dictionary providing mapping between filter names in file and BayeSN filters. Defaults to empty dictionary
- peak_mjd_key: str, optional
Key to be used for peak MJD in SNANA text file meta. Defaults to ‘SEARCH_PEAKMJD’
- print_summary: Boolean, optional
Specifies whether to print fit summary
- file_prefix: str, optional
Prefix of name for output files containing summary table and MCMC samples. Default to None, in which case output files will not be saved and only returned for use in script.
- drop_bands: array-like, optional
List of bands to be ignored during fitting. Defaults to empty list
- fix_tmax: Boolean, optional
If True, tmax will not be inferred and fiducial value in file meta will be fixed. Defaults to False.
- fix_theta: float, optional
Value to fix theta at during fitting. Defaults to False, meaning that theta will be inferred during fitting rather than fixed.
- fix_AV: float, optional
Value to fix AV at during fitting. Defaults to False, meaning that AV will be inferred during fitting rather than fixed.
- RV: float, optional
Value to fix RV at during fitting. Defaults to False, meaning that default model RV treatment will be used.
- mu_R: float, optional
Value of mean of RV distribution to be used during fitting. Defaults to False, meaning that default model RV treatment will be used. If specified, sigma_R must also be specified.
- sigma_R: float, optional
Value of standard deviation of RV distribution. Defaults to False, meaning that default model RV treatment will be used.
- mag: Boolean, optional
Specifies whether data is mag or flux. If True, data is assumed to be mag and is automatically converted to flux before fitting.
- Returns:
- samples: dict
Dictionary containing parameter names as keys and MCMC samples as values
- sn_props: tuple
Tuple containing SN redshift and MW E(B-V), which can be useful to have in memory when making plots
- fit_model_globalRV(obs, weights, fix_tmax=False, fix_theta=False, theta_val=0, fix_AV=False, AV_val=0)
Numpyro model used for fitting latent SN properties with single global RV. Will fit for time of maximum as well as theta, epsilon, AV and distance modulus.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band-weights to calculate photometry
- fix_tmax: Boolean, optional
If True, tmax will be fixed to fiducial value and will not be inferred. Defaults to False
- fix_theta: Boolean, optional
If True, theta will be fixed to value specified by theta_val. Defaults to False.
- theta_val: float or array-like, optional
Value to fix theta to, if fix_theta=True. Defaults to 0
- fix_AV: Boolean, optional
If True, AV will be fixed to value specified by theta_AV. Defaults to False.
- AV_val: float or array-like, optional
Value to fix AV to, if fix_AV=True. Defaults to 0
- Returns:
- fit_model_globalRV_vi(obs, weights)
Numpyro model used for fitting SN properties assuming fixed global properties from a trained model. Will fit for tmax as well as theta, epsilon, Av and distance modulus. This model is slightly modified for ZLTN VI.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band-weights to calculate photometry
- fit_model_popRV(obs, weights, fix_tmax=False, fix_theta=False, theta_val=0, fix_AV=False, AV_val=0)
Numpyro model used for fitting latent SN properties with a truncated Gaussian prior on RV. Will fit for time of maximum as well as theta, epsilon, AV, RV and distance modulus.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band-weights to calculate photometry
- fix_tmax: Boolean, optional
If True, tmax will be fixed to fiducial value and will not be inferred. Defaults to False
- fix_theta: Boolean, optional
If True, theta will be fixed to value specified by theta_val. Defaults to False.
- theta_val: float or array-like, optional
Value to fix theta to, if fix_theta=True. Defaults to 0
- fix_AV: Boolean, optional
If True, AV will be fixed to value specified by theta_AV. Defaults to False.
- AV_val: float or array-like, optional
Value to fix AV to, if fix_AV=True. Defaults to 0
- fit_model_popRV_vi(obs, weights)
Numpyro model used for fitting latent SN properties with a truncated Gaussian prior on RV. Will fit for time of maximum as well as theta, epsilon, AV, RV and distance modulus. This model is slightly modified for ZLTN VI.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band-weights to calculate photometry
- fit_model_uniformRV(obs, weights, fix_tmax=False, fix_theta=False, theta_val=0, fix_AV=False, AV_val=0)
Numpyro model used for fitting latent SN properties with single global RV. Will fit for time of maximum as well as theta, epsilon, AV and distance modulus.
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band-weights to calculate photometry
- fix_tmax: Boolean, optional
If True, tmax will be fixed to fiducial value and will not be inferred. Defaults to False
- fix_theta: Boolean, optional
If True, theta will be fixed to value specified by theta_val. Defaults to False.
- theta_val: float or array-like, optional
Value to fix theta to, if fix_theta=True. Defaults to 0
- fix_AV: Boolean, optional
If True, AV will be fixed to value specified by theta_AV. Defaults to False.
- AV_val: float or array-like, optional
Value to fix AV to, if fix_AV=True. Defaults to 0
- Returns:
- get_flux_batch(M0, theta, AV, W0, W1, eps, Ds, RV, band_indices, mask, J_t, hsiao_interp, weights)
Calculates observer-frame fluxes for given parameter values
- Parameters:
- M0: float or array-like
Normalising constant to scale Hsiao template to correct order of magnitude. Typically fixed to -19.5 although can be inferred separately for different bins in a mass split analysis
- theta: array-like
Set of theta values for each SN
- AV: array-like
Set of host extinction values for each SN
- W0: array-like
Global W0 matrix
- W1: array-like
Global W1 matrix
- eps: array-like
Set of epsilon values for each SN, describing residual colour variation
- Ds: array-like
Set of distance moduli for each SN
- RV: float
Global R_V value for host extinction (need to allow this to be variable in future)
- band_indices: array-like
Array containing indices describing which filter each observation is in
- mask: array-like
Array containing mask describing whether observations should contribute to the posterior
- J_t: array-like
Matrix for cubic spline interpolation in time axis for each SN
- hsiao_interp: array-like
Array containing Hsiao template spectra for each t value, comprising model for previous day, next day and t % 1 to allow for linear interpolation
- weights: array_like
Array containing band weights to use for photometry
- Returns:
- model_flux: array-like
Matrix containing model fluxes for all SNe at all time-steps
- get_flux_from_chains(t, bands, chains, zs, ebv_mws, mag=True, num_samples=None, mean=False)
Returns model photometry for posterior samples from BayeSN fits, which can be used to make light curve fit plots.
- Parameters:
- t: array-like
Array of phases to evaluate model photometry at
- bands: array-like
List of bandpasses to evaluate model photometry in. Photometry will be
- chain_path: str
Path to file containing BayeSN fitting posterior samples you wish to obtain photometry for
- zs: array-like
Array of heliocentric redshifts corresponding to the SNe you are obtaining model fit light curves for.
- ebv_mws: array-like
Array containing Milky Way extincion values corresponding to the SNe you are obtaining model fit light curves for.
- mag: Bool, optional
Boolean to specify whether you want magnitude or flux data. If True, magnitudes will be returned. If False, flux densities (f_lambda) will be returned. Default to True i.e. mag data.
- num_samples: int, optional
An optional keyword argument to specify the number of posterior samples you wish to obtain photometry for. Might be useful in testing if you are looking at lots of SNe, as otherwise this function will take a while to generate e.g. photometry for 1000 posterior samples across 1000 SNe. Default to None, meaning that photometry will be calculated for all posterior samples in chains provided.
- Returns:
- flux_grid: jax.numpy.array
Array of shape (number of SNe, number of posterior samples, number of bands, number of phases to evaluate), containing photometry across all SNe, all posterior samples, all bands and at all phases requested.
- get_mag_batch(M0, theta, AV, W0, W1, eps, Ds, RV, band_indices, mask, J_t, hsiao_interp, weights)
Calculates observer-frame magnitudes for given parameter values
- Parameters:
- M0: float or array-like
Normalising constant to scale Hsiao template to correct order of magnitude. Typically fixed to -19.5 although can be inferred separately for different bins in a mass split analysis
- theta: array-like
Set of theta values for each SN
- AV: array-like
Set of host extinction values for each SN
- W0: array-like
Global W0 matrix
- W1: array-like
Global W1 matrix
- eps: array-like
Set of epsilon values for each SN, describing residual colour variation
- Ds: array-like
Set of distance moduli for each SN
- RV: float
Global R_V value for host extinction (need to allow this to be variable in future)
- band_indices: array-like
Array containing indices describing which filter each observation is in
- mask: array-like
Array containing mask describing whether observations should contribute to the posterior
- J_t: array-like
Matrix for cubic spline interpolation in time axis for each SN
- hsiao_interp: array-like
Array containing Hsiao template spectra for each t value, comprising model for previous day, next day and t % 1 to allow for linear interpolation
- weights: array_like
Array containing band weights to use for photometry
- Returns:
- model_mag: array-like
Matrix containing model magnitudes for all SNe at all time-steps
- get_spectra(theta, AV, W0, W1, eps, RV, J_t, hsiao_interp)
Calculates rest-frame spectra for given parameter values
- Parameters:
- theta: array-like
Set of theta values for each SN
- AV: array-like
Set of host extinction values for each SN
- W0: array-like
Global W0 matrix
- W1: array-like
Global W1 matrix
- eps: array-like
Set of epsilon values for each SN, describing residual colour variation
- RV: float
Global R_V value for host extinction (need to allow this to be variable in future)
- J_t: array-like
Matrix for cubic spline interpolation in time axis for each SN
- hsiao_interp: array-like
Array containing Hsiao template spectra for each t value, comprising model for previous day, next day and t % 1 to allow for linear interpolation
- Returns:
- model_spectra: array-like
Matrix containing model spectra for all SNe at all time-steps
- initial_guess(args, reference_model='M20_model')
Sets initialisation for training chains, using some global parameter values from previous models. W0 and W1 matrices are interpolated to match wavelength knots of new model, and set to zero beyond the time range that the reference model is defined for. Note that unlike Stan, in numpyro we cannot set each chain’s initialisation separately.
- Parameters:
- reference_model: str, optional
Previously-trained model to be used to set initialisation, defaults to T21.
- Returns:
- param_init: dict
Dictionary containing initial values to be used
- parse_yaml_input(args, cmd_args)
Method to parse the input yaml file and process data-set
- Parameters:
- args: dict
dictionary of arguments to define model based on input yaml file
- cmd_args: dict
dictionary of command line arguments, which will override yaml file if specified
- ——-
- postprocess(samples, args)
Function to postprocess BayeSN output. Applies transformations to some parameters e.g. ensuring consistency for W1 and theta, as flipping the sign in front of W1 and theta will lead to an identical result. Saves output chains and calculated a fit summary
- Parameters:
- samples: dict
Output of MCMC, dictionary containing posterior samples for each parameter with parameter names as keys
- args: dict
dictionary of arguments to define model based on input yaml file and command line arguments
- Returns:
- process_dataset(args)
Processes a data set to be used by the numpyro model.
This will read in SNANA-format files, either in text or FITS format. This will read through all light curves and work out the maximum number of data points for a single object - all others will then be padded to match this size. This is required because to benefit from the GPU, we need to have a fixed array structure allowing us to calculate flux integrals from parameter values across the whole sample in a single tensor operation. A mask is applied in the model to ensure that these padded values do not contribute to the likelihood.
Generated data set is saved to the SEDmodel.data attribute, while the J_t matrices used to interpolate the W0, W1 and epsilon matrices are also calculated and saved to the SEDmodel.J_t attribute. Observer-frame band weights, including the effect of Milky Way extinction, are also calculated for the data set and saved to the SEDmodel.band_weights attribute.
- Parameters:
- args: dict
Combination of arguments from input yaml file and command line overrides, defines model wavelength range and data set to load
- run(args, cmd_args)
Main method to run BayeSN. Can be used for either model training, fitting or dust inference with fixed population SN parameters, depending on input yaml file.
- Parameters:
- args: dict
dictionary of arguments to define model based on input yaml file
- cmd_args: dict
dictionary of command line arguments, which will override yaml file if specified
- ——-
- sample_AV(N)
Samples AV from model prior
- Parameters:
- N: int
Number of objects to sample for
- Returns:
- AV: array-like
Sampled AV values
- sample_del_M(N)
Samples grey offset del_M from model prior
- Parameters:
- N: int
Number of objects to sample for
- Returns:
- del_M: array-like
Sampled del_M values
- sample_epsilon(N)
Samples epsilon from model prior
- Parameters:
- N: int
Number of objects to sample for
- Returns:
- eps_full: array-like
Sampled epsilon values
- sample_theta(N)
Samples theta from model prior
- Parameters:
- N: int
Number of objects to sample for
- Returns:
- theta: array-like
Sampled theta values
- simulate_light_curve(t, N, bands, yerr=0, err_type='mag', z=0, zerr=0.0001, mu=0, ebv_mw=0, RV=None, logM=None, tmax=0, del_M=None, AV=None, theta=None, eps=None, mag=True, write_to_files=False, output_dir=None)
Simulates light curves from the BayeSN model in either mag or flux space. and saves them to SNANA-format text files if requested
- Parameters:
- t: array-like
Set of t values to simulate spectra at. If len(t) == len(bands), will assume that the t values correspond to the bands. Otherwise, will simulate photometry at each value of t for each band.
- N: int
Number of separate objects to simulate spectra for
- bands: array-like
List of bands in which to simulate photometry. If len(t) == len(bands), will assume that the t values correspond to the bands. Otherwise, will simulate photometry at each value of t for each band.
- yerr: float or array-like, optional
Uncertainties for each data point, simulated light curves will be randomised assuming a Gaussian uncertainty around the true values. Can be either a float, meaning that the same value will be used for each data point, a 1d array of length equal to each light curve, meaning that these values will be used for each simulated light curve, or a 2d array of shape (N, light curve length) allowing you to specify each individual error. Defaults to 0, meaning that exact model photometry will be returned.
- err_type: str
Specifies which type of error you are passing, either ‘mag’ or ‘flux’. Defaults to ‘mag’, meaning that this is in mag units. If you want to simulate fluxes and pass a mag error, it will be converted to a flux error.
- z: float or array-like, optional
Redshift to simulate spectra at, affecting observer-frame wavelengths and reducing spectra by factor of (1+z). Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same redshift will be used for all objects.
- zerr: float, optional
Error on spectroscopic redshifts, only needed when saving to SNANA-format light curve files
- mu: float, array-like or str, optional
Distance modulus to simulate spectra at. Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. If set to ‘z’, distance moduli corresponding to the redshift values passed in the default model cosmology will be used. Technically these are heliocentric redshifts rather than Hubble diagram redshifts so won’t be perfect, but can be useful sometimes.
- ebv_mw: float or array-like, optional
Milky Way E(B-V) values for simulated spectra. Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects.
- RV: float or array-like, optional
RV values for host extinction curves for simulated spectra. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the global RV value for the BayeSN model loaded when initialising SEDmodel will be used.
- logM: float or array-like, optional
Currently unused, will be implemented when split models are included
- tmax: float or array-like, optional
Time of maximum in rest-frame days, useful for plotting light curve fits with free tmax. Defaults to 0, i.e. the simulated time of maximum will be at 0 days. If a float is passed, the same value will be used for all objects.
- del_M: float or array-like, optional
Grey offset del_M value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- AV: float or array-like, optional
Host extinction RV value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- theta: float or array-like, optional
Theta value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- eps: array-like or int, optional
Epsilon values to be used for each SN. If passing a 2d array, this must be of shape (l_knots, tau_knots) and will be used for each SN generated. If passing a 3d array, this must be of shape (N, l_knots, tau_knots) and provide an epsilon value for each generated SN. You can also pass 0, in which case an array of zeros of shape (N, l_knots, tau_knots) will be used and epsilon is effectively turned off. Defaults to None, in which case the prior distribution will be sampled for each object.
- mag: Bool, optional
Determines whether returned values are mags or fluxes
- write_to_files: Bool, optional
Determines whether to save simulated light curves to SNANA-format light curve files, defaults to False
- output_dir: str, optional
Path to output directory to save simulated SNANA-format files, onl required if write_to_files=True
- Returns:
- data: array-like
Array containing simulated flux or mag values
- yerr: array-like
Aray containing corresponding errors for each data point
- param_dict: dict
Dictionary of corresponding parameter values for each simulated object
- simulate_spectrum(t, N, dl=10, z=0, mu=0, ebv_mw=0, RV=None, logM=None, del_M=None, AV=None, theta=None, eps=None)
Simulates spectra for given parameter values in the observer-frame. If parameter values are not set, model priors will be sampled.
- Parameters:
- t: array-like
Set of t values to simulate spectra at
- N: int
Number of separate objects to simulate spectra for
- dl: float, optional
Wavelength spacing for simulated spectra in rest-frame. Default is 10 AA
- z: float or array-like, optional
Redshift to simulate spectra at, affecting observer-frame wavelengths and reducing spectra by factor of (1+z). Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same redshift will be used for all objects.
- mu: float, array-like or str, optional
Distance modulus to simulate spectra at. Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. If set to ‘z’, distance moduli corresponding to the redshift values passed in the default model cosmology will be used.
- ebv_mw: float or array-like, optional
Milky Way E(B-V) values for simulated spectra. Defaults to 0. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects.
- RV: float or array-like, optional
RV values for host extinction curves for simulated spectra. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the global RV value for the BayeSN model loaded when initialising SEDmodel will be used.
- logM: float or array-like, optional
Currently unused, will be implemented when split models are included
- del_M: float or array-like, optional
Grey offset del_M value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- AV: float or array-like, optional
Host extinction RV value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- theta: float or array-like, optional
Theta value to be used for each SN. If passing an array-like object, there must be a corresponding value for each of the N simulated objects. If a float is passed, the same value will be used for all objects. Defaults to None, in which case the prior distribution will be sampled for each object.
- eps: array-like or int, optional
Epsilon values to be used for each SN. If passing a 2d array, this must be of shape (l_knots, tau_knots) and will be used for each SN generated. If passing a 3d array, this must be of shape (N, l_knots, tau_knots) and provide an epsilon value for each generated SN. You can also pass 0, in which case an array of zeros of shape (N, l_knots, tau_knots) will be used and epsilon is effectively turned off. Defaults to None, in which case the prior distribution will be sampled for each object.
- Returns:
- l_o: array-like
Array of observer-frame wavelength values
- spectra: array-like
Array of simulated spectra
- param_dict: dict
Dictionary of corresponding parameter values for each simulated object
- static spline_coeffs_irr_step(x_now, x, invkd)
Vectorized version of cubic spline coefficient calculator found in spline_utils
- Parameters:
- x_now: array-like
Current x location to calculate spline knots for
- x: array-like
Numpy array containing the locations of the spline knots.
- invkd: array-like
Precomputed matrix for generating second derivatives. Can be obtained from the output of
spline_utils.invKD_irr.
- Returns:
- X: Set of spline coefficients for each x knot
- train_model_globalRV(obs, weights)
Numpyro model used for training to learn global parameters, assuming a single global RV
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
- train_model_popRV(obs, weights)
Numpyro model used for training to learn global parameters with a truncated Gaussian RV distribution
- Parameters:
- obs: array-like
Data to fit, from output of process_dataset
- weights: array-like
Band weights based on filter responses and MW extinction curves for numerical flux integrals
bayesn.spline_utils module
BayeSN Spline Utilities. Defines a set of functions which carry out the 2D spline operations essential to BayeSN.
- bayesn.spline_utils.cartesian_prod(x, y)
Compute cartesian product of two vectors.
- Parameters:
- x
numpy.array First vector.
- x
numpy.array Second vector.
- x
- Returns:
- z
numpy.array Cartesian product of x and y.
- z
- bayesn.spline_utils.invKD_irr(x)
Compute K^{-1}D for a set of spline knots.
For knots y at locations x, the vector, y’’ of non-zero second derivatives is constructed from y’’ = K^{-1}Dy, where K^{-1}D is independent of y, meaning it can be precomputed and reused for arbitrary y to compute the second derivatives of y.
- Parameters:
- x
numpy.array Numpy array containing the locations of the cubic spline knots.
- x
- Returns:
- KD
numpy.array y independednt matrix whose product can be taken with y to obtain a vector of second derivatives of y.
- KD
- bayesn.spline_utils.spline_coeffs_irr(x_int, x, invkd, allow_extrap=True)
Compute a matrix of spline coefficients.
Given a set of knots at x, with values y, compute a matrix, J, which can be multiplied into y to evaluate the cubic spline at points x_int.
- Parameters:
- x_int
numpy.array Numpy array containing the locations which the output matrix will interpolate the spline to.
- x
numpy.array Numpy array containing the locations of the spline knots.
- invkd
numpy.array Precomputed matrix for generating second derivatives. Can be obtained from the output of
invKD_irr.- allow_extrapbool
Flag permitting extrapolation. If True, the returned matrix will be configured to extrapolate linearly beyond the outer knots. If False, values which fall out of bounds will raise ValueError.
- x_int
- Returns:
- J
numpy.array y independednt matrix whose product can be taken with y to evaluate the spline at x_int.
- J
- bayesn.spline_utils.spline_coeffs_irr_step(x_now, x, invkd)
bayesn.bayesn_io module
BayeSN I/O Utilities. Currently defines function for writing output SNANA-format light curves for simulated light curves
- bayesn.bayesn_io.write_snana_lcfile(output_dir, snname, mjd, flt, mag, magerr, tmax, z_helio, z_cmb, z_cmb_err, ebv_mw, ra=None, dec=None, author='anonymous', survey=None, paper=None, filename=None)
Write user data to an SNANA-like light curve file
- Parameters:
- output_dirstr
Path to a directory where the file will be written. A default filename will be used, but you can specify your own with the filename argument. Default name format is snname[_survey][_paper].snana.dat, with the survey and/or paper being appended to the name if provided.
- snnamestr
Name of the supernova
- mjdlist or
numpy.array Modified Julian Dates of observations
- fltlist or
numpy.arrayof str Filter idenitifiers of observations
- maglist or
numpy.array Magnitudes of observations
- magerrlist or
numpy.array Magnitude errors of observations
- tmaxfloat
Estimated time of maximum
- z_heliofloat
Heliocentric redshift
- z_cmbfloat
CMB-frame redshift
- z_cmb_errfloat
Error on CMB-frame redshift (excluding peculiar velocity uncertainty contribution)
- ebv_mwfloat
E(B-V) reddening due to the Milky Way
- rafloat, optional
Right Ascension, to be writen to the header if desired
- decfloat, optional
Declination, to be written into the header if desired
- authorstr, optional
Who is creating this file? Will be printed into the header’s preamble, if desired
- surveystr, optional
Optional argumanet specifying the survey the data came from. Will be written into the header and filename if provided.
- paperstr, optional
Optional argument specifying the paper the data came from. Will be written into the filename if provided.
- filenamestr, optional
Custom filename to save as within output_dir. If not provided, a default format will be used. Do not provide an extension, as this will be added automatically.
- Returns:
- pathstr
Full path to the generated light curve file.
Notes
This will write a user’s data to the SNANA-like file format readable by out I/O routines. It will write the provided metadata into the file header, so this will be read in and used correctly by BayeSN. All vital metadata are required as inputs to this function.