snsim.utils

This module contains usefull function for the simulation.

Classes

CustomRandom

Class to generate random variable on custom dist.

Functions

gauss(mu, sig, x)

Gaussian function.

reshape_prob_data()

function that read DES X1-mass probability file and return

set_cosmo(cosmo_dic)

Load an astropy cosmological model.

init_snc_source(name[, version])

scale_Mabs_cosmology(h, Mabs_to_scale, h_ref)

Compute a value of M0 corresponding the cosmology used in the simulation.

init_astropy_time(date)

Take a date and give a astropy.time.Time object.

compute_z_cdf(z_shell, shell_time_rate)

Compute the cumulative distribution function of redshift.

asym_gauss(mu, sig_low[, sig_high, seed, size])

Generate random parameters using an asymetric Gaussian distribution.

compute_zpcmb(ra, dec, cmb)

Compute the redshifts of a list of objects relative to the CMB.

init_snia_source(name[, model_dir, version])

Initialise a sncosmo source.

norm_flux(flux_table, zp)

Rescale the flux to a given zeropoint.

flux_to_Jansky(zp, band)

Give the factor to convert flux in uJy.

zobs_MinT_MaxT(par, model_t_range)

print_dic(dic[, prefix])

Templatelist_fromsncosmo([source_type])

list names of templates in sncosmo built-in sources catalogue

select_Vincenzi_template(model_list[, corr])

from a given list of sncosmo Template select the ones from Vincenzi et al. 2019

sine_interp(x_new, fun_x, fun_y)

Make a sinus interpolation of a function.

gen_rndchilds(seed[, size])

Create child random seeds.

compute_weight_mass_for_type(mass, sn_type, cosmology)

compute the mass dependent weights for HOST - SN matching

compute_weight_SFR_for_type(SFR, sn_type, cosmology)

compute the SFR dependent weights for HOST - SN matching

compute_weight_mass_sfr_for_type(mass, sfr, sn_type, ...)

compute the SFR dependent weights for HOST - SN matching

Module Contents

snsim.utils.gauss(mu, sig, x)[source]

Gaussian function.

Parameters:
Returns:

G(x).

Return type:

numpy.array(float)

class snsim.utils.CustomRandom(pdf, xmin, xmax, ndiv=10000.0, dx=None)[source]

Class to generate random variable on custom dist.

Parameters:
  • pdf (lambda function) – Function that return the pdf of the vairable x.

  • xmin (float) – Inferior bound of the distribution.

  • xmax (float) – Superior bound of the distribution.

  • ndiv (float, optional) – Number of division used to integrate the pdf.

  • dx (float, optional) – Precision used to integrate the pdf.

Notes

If dx and ndiv are set, only dx will be used. If none of the 2 is set, the default will be ndiv=1e4

Init the CustomRandom class.

x
dx
pdfx
norm
cdf
plot_pdf(ax=None)[source]

Plot the pdf function.

Parameters:

ax (matplotlib axes, optional) – Figure axis, by default None

plot_cdf(ax=None)[source]

Plot the cdf function.

Parameters:

ax (matplotlib axes, optional) – Figure axis, by default None

draw(n, seed=None)[source]

Draw n parameters from the distribution.

Parameters:
  • n (int) – Number of parameters to draw.

  • seed (int, optional) – Random seed, by default None

Returns:

Random parameters following the custom distribution.

Return type:

numpy.array

snsim.utils.reshape_prob_data()[source]

function that read DES X1-mass probability file and return grid values fro interpolation

snsim.utils.set_cosmo(cosmo_dic)[source]

Load an astropy cosmological model.

Parameters:

cosmo_dic (dict) – A dict containing cosmology parameters.

Returns:

An astropy cosmological model.

Return type:

astropy.cosmology.object

snsim.utils.init_snc_source(name, version=None)[source]
snsim.utils.scale_Mabs_cosmology(h, Mabs_to_scale, h_ref)[source]

Compute a value of M0 corresponding the cosmology used in the simulation.

Parameters:
  • h (float) – The H0 / 100 constant to scale M0.

  • M0_art (float) – M0 value to be scaled

  • h_art (float) – the H0/100 constant used in the article to retrive M0_art

Returns:

Scaled SN Absolute Magnitude.

Return type:

float

snsim.utils.init_astropy_time(date)[source]

Take a date and give a astropy.time.Time object.

Parameters:

date (int, float or str) – The date in MJD number or YYYY-MM-DD string.

Returns:

An astropy.time Time object of the given date.

Return type:

astropy.time.Time

snsim.utils.compute_z_cdf(z_shell, shell_time_rate)[source]

Compute the cumulative distribution function of redshift.

Parameters:
Returns:

redshift, CDF(redshift).

Return type:

list(numpy.ndarray(float), numpy.ndarray(float))

snsim.utils.asym_gauss(mu, sig_low, sig_high=None, seed=None, size=1)[source]

Generate random parameters using an asymetric Gaussian distribution.

Parameters:
  • mean (float) – The central value of the Gaussian.

  • sig_low (float) – The low sigma.

  • sig_high (float) – The high sigma.

  • seed (int, optional) – Random seed.

  • size (int) – Number of numbers to generate

Returns:

Random(s) variable(s).

Return type:

numpy.ndarray(float)

snsim.utils.compute_zpcmb(ra, dec, cmb)[source]

Compute the redshifts of a list of objects relative to the CMB.

Parameters:
  • ra (np.ndarray(float)) – Right Ascension of the objects.

  • dec (np.ndarray(float)) – Declinaison of the objects.

  • cmb (dict) – Dict containing cmb coords and velocity.

Returns:

Redshifts relative to cmb.

Return type:

np.ndarray(float)

snsim.utils.init_snia_source(name, model_dir=None, version=None)[source]

Initialise a sncosmo source.

Parameters:
  • name (str) – Name of the model.

  • model_dir (str) – Path to the model files.

Returns:

sncosmo Model corresponding to input configuration.

Return type:

sncosmo.Model

snsim.utils.norm_flux(flux_table, zp)[source]

Rescale the flux to a given zeropoint.

Parameters:
  • flux_table (astropy.Table) – A table containing at least flux and fluxerr.

  • zp (float) – The zeropoint to rescale the flux.

Returns:

Rescaled flux and fluxerr arry.

Return type:

np.ndarray(float), np.ndarray(float)

snsim.utils.flux_to_Jansky(zp, band)[source]

Give the factor to convert flux in uJy.

Parameters:
  • zp (float) – The actual zeropoint of flux.

  • band (str) – The sncosmo band in which compute the factor.

Returns:

The conversion factor.

Return type:

float

snsim.utils.zobs_MinT_MaxT(par, model_t_range)[source]
snsim.utils.print_dic(dic, prefix='')[source]
snsim.utils.Templatelist_fromsncosmo(source_type=None)[source]

list names of templates in sncosmo built-in sources catalogue :param source_type: type of sources could be snii,sniipl,sniib,sniin,snib/c,snic,snib or snic-bl :type source_type: str

Return type:

list on names of sources with the given source_type from snscomo catalogue

snsim.utils.select_Vincenzi_template(model_list, corr=None)[source]
from a given list of sncosmo Template select the ones from Vincenzi et al. 2019
model_listlist

starting list of templates

corrbool

If True select templates that have been corrected for the host galaxy dust

list of template names

snsim.utils.sine_interp(x_new, fun_x, fun_y)[source]

Make a sinus interpolation of a function.

Parameters:
Returns:

Values of the function at x_new.

Return type:

numpy.ndarray(float)

Raises:
snsim.utils.gen_rndchilds(seed, size=1)[source]

Create child random seeds.

Parameters:
Returns:

The desired number of child random seeds

Return type:

tuple(numpy.random.SeedSequence)

snsim.utils.compute_weight_mass_for_type(mass, sn_type, cosmology)[source]

compute the mass dependent weights for HOST - SN matching

snsim.utils.compute_weight_SFR_for_type(SFR, sn_type, cosmology)[source]

compute the SFR dependent weights for HOST - SN matching

snsim.utils.compute_weight_mass_sfr_for_type(mass, sfr, sn_type, cosmology)[source]

compute the SFR dependent weights for HOST - SN matching