snsim

Init file of snsim package.

The snsim module is design to simulate supernovae lightcurve in a survey defined by an observations data base. Moreover the simulation can use a host file to simulate a velocity field.

The package use sncosmo.

Github repository : https://github.com/bcarreres/snsim

Submodules

Classes

Simulator

Simulation class using a config file config.yml.

SimSample

Class to store simulated SN sample.

SurveyObs

This class deals with the observations of the survey.

SnHosts

Class containing the SN Host parameters.

Package Contents

class snsim.Simulator(param_dic, print_config=False)[source]

Simulation class using a config file config.yml.

Parameters:

param_dic (dict / str) – The configuration yaml file / The dictionnary containing all simulation parameters.

Notes

yaml file format :

data :
write_path: ‘/PATH/TO/OUTPUT’
sim_name: ‘NAME OF SIMULATION’
write_format: ‘format’ or [‘format1’,’format2’]
survey_config:
survey_file: ‘/PATH/TO/FILE’
band_dic: {‘r’:’ztfr’,’g’:’ztfg’,’i’:’ztfi’} # Optional -> if bandname in
survey_file doesn’t match sncosmo name
gain: CCD GAIN e-/ADU # Optional, default given by survey file
sub_field: ‘sub_field_key’ # Optional
cdd_noise : sig_ccd_noise # Optional, default is 0 ADU
key_dic: {‘column_name’: ‘new_column_name’, etc} # Optional, to change columns names
add_data: [‘keys1’, ‘keys2’, …] add db file keys to metadata
survey_cut: {‘key1’: [‘conditon1’,’conditon2’,…], ‘key2’: [‘conditon1’]}
start_day: MJD NUMBER or ‘YYYY-MM-DD’ # Optional, default given by survey file
duration: SURVEY DURATION (DAYS) # Optional, default given by survey file
zp: INSTRUMENTAL ZEROPOINT # Optional, default given by survey file
sig_zp: ZEROPOINT ERROR # Optional, default given by survey file
fwhm_psf: GAUSSIAN PSF FWHM # Otional, default given by survey file as FWHMeff
noise_key: [key, type] type can be ‘mlim5’ or ‘skysigADU’
ra_size: RA FIELD SIZE # Optional if there is geo_field_map
dec_size: DEC FIELD SIZE # Optional if there is geo_field_map
field_shape: ‘/PATH/TO/FIELD_SHAPE_FILE’ # Optional if there is geo_field_map
geo_field_map: ‘/PATH/TO/GEO_FIELD_MAP_FILE’ # Optional
sim_par:
randseed: RANDSEED TO REPRODUCE SIMULATION # Optional
z_range: [ZMIN, ZMAX]
nep_cut: [[nep_min1,Tmin,Tmax],[nep_min2,Tmin2,Tmax2,’filter1’],…] EP CUTS
duration_for_rate: FAKE DURATION ONLY USE TO GENERATE N OBJ # Optional
mw_dust:
model: MOD_NAME
r_v: Rv # Optional, default Rv = 3.1
snia_gen:
n_sn: NUMBER OF SN TO GENERATE # Optional
rate: rate of SN/Mpc^3/year # Optional, default=3e-5
Mabs: SN ABSOLUT MAGNITUDE
sigM: SN INTRINSIC COHERENT SCATTERING
sct_model: ‘G10’,’C11_i’ USE WAVELENGHT DEP MODEL FOR SN INT SCATTERING
model_name: ‘THE MODEL NAME’ Example : ‘salt2’
model_dir: ‘/PATH/TO/SALT/MODEL’
alpha: STRETCH CORRECTION = alpha*x1
beta: COLOR CORRECTION = -beta*c
dist_x1: [MEAN X1, SIGMA X1], [MEAN X1, SIGMA_X1_LOW, SIGMA_X1_HIGH] or ‘N21’
dist_c: [MEAN C, SIGMA C] or [SIGMA_C_LOW, SIGMA_C_HIGH]
cosmology:
Om0: MATTER DENSITY
H0: HUBBLE CONSTANT
cmb:
v_cmb: OUR PECULIAR VELOCITY # Optional, default = 620 km/s
l_cmb: GAL L OF CMB DIPOLE # Optional, default = 271.0
b_cmb: GAL B OF CMB DIPOLE # Optional, default = 29.6
vpec_dist:
mean_vpec: MEAN SN PECULIAR VELOCITY
sig_vpec: SIGMA VPEC
hosts: (Optional)
host_file: ‘PATH/TO/HOSTFILE’
distrib: ‘rate’ or ‘random’ # Optional, default = ‘rate’
key_dic: {‘column_name’: ‘new_column_name’, etc} # Optional, to change columns names
dask: # Optional for using dask parallelization
use: True or False
nworkers: NUMBER OF WORKERS # used to adjust work distribution

Initialise Simulator class.

simulate()[source]

Launch the simulation.

Return type:

None

Notes

Simulation routine : 1- Use either _cadence_sim() or _gen_n_sn() to run the simulation 2- Gen all SN parameters inside SNGen class or/and SnHosts class 3- Check if SN pass cuts and then generate the lightcurves. 4- Write LCs to parquet/pkl file(s)

property config

Get the whole configuration dic.

property sim_name

Get sim name.

property vpec_dist

Get vpec option.

property cmb

Get cmb parameters.

property samples

Get the list of simulated sn.

property cosmology

Get astropy cosmological model used in simulation.

property survey

Get the SurveyObs object of the simulation.

property generators

Get the SNGen object of the simulation.

property hosts

Get the SnHosts object of the simulation.

property randseed

Get primary random seed of the simulation.

property z_range

Get z_range.

property nep_cut

Get the list of epochs cuts.

class snsim.SimSample(sample_name, sim_lcs, header, dir_path=None)[source]

Class to store simulated SN sample.

Parameters:
  • sample_name (str) – Name of the sample.

  • sim_lcs (list(astropy.Table)) – The simulated lightcurves.

  • header (dict) – Simulation header.

  • model_dir (str, opt) – The path to the simulation model files.

  • file_path (str, opt) – Path of the sample.

  • class. (Initialize SimSample)

classmethod fromDFlist(sample_name, sim_lcs, header, dir_path=None)[source]

Initialize the class from a list of pandas.DataFrame.

Parameters:
  • cls (SimSample class) – The SimSample class.

  • sim_file (str) – The file to load.

  • model_dir (str, opt) – The directory of the configuration files of the sim model.

  • sample_name (str) – Name of the simulation.

  • sim_lcs (list(pandas.DataFrame)) – The sim lightcurves.

  • header (dict) – Simulation header.

Returns:

A SimSample class with the simulated lcs.

Return type:

SimSample class object

classmethod fromFile(sim_file, engine='pyarrow')[source]

Initialize the class from a fits or pickle file.

Parameters:
  • cls (SimSample class) – The SimSample class.

  • sim_file (str) – The file to load.

  • model_dir (str, opt) – The directory of the configuration files of the sim model.

  • engine (str) – Engine to use to open the file pyarrow or fastparquet.

Returns:

A SimSample class with the simulated lcs.

Return type:

SimSample class object

get_obj_sim_model(obj_ID)[source]

Get th sim model of one obj.

Parameters:

obj_ID (int) – ID of the obj.

Returns:

sncosmo sim model of the obj.

Return type:

sncosmo.Model

set_fit_model(model, model_dir=None, mw_dust=None)[source]

Set the fit with a given SNCosmo Model.

Parameters:
  • model (sncosmo.models.Model or str) – A sncosmo Model or a model name for utils.init_sn_model(model, model_dir).

  • model_dir (str, opt) – In case you want to set your model via utils.init_sn_model(model, model_dir).

  • mw_dust (dict, opt) – Milky Wat dust model to apply. | mw_dust | ├── model : str (model name) | └── rv : float, opt

Returns:

Set the self._fit_model attribute.

Return type:

None

fit_lc(obj_ID=None, **kwargs)[source]

Fit all or just one SN lightcurve(s).

Parameters:

ID (int, default is None) – The SN ID, if not specified all SN are fit.

Returns:

Directly modified the _fit_res attribute.

Return type:

None

Notes

Use snc_fitter from utils

write_mod(formats=['pkl', 'parquet'])[source]

Write a file containing only the modified SN epochs.

Parameters:

formats (list(str) or str, opt) – The output formats, ‘pkl’ or ‘fits’.

Returns:

Just write a file.

Return type:

None

write_fit(fit_model_name, write_path=None)[source]

Write fits results in fits format.

Returns:

Write an output file.

Return type:

None

Notes

Use write_fit from utils.

plot_hist(key, ax=None, **kwargs)[source]

Plot the histogram of the key metadata.

Parameters:
  • key (str) – A key of lightcurves metadata.

  • ax (matplotlib.axis, opt) – ax on which plot the histogram.

  • **kwargs (type) – matplotlib plot options.

Returns:

Description of returned object.

Return type:

type

plot_lc(obj_ID, plot_sim=True, plot_fit=False, **kwargs)[source]

Plot the given SN lightcurve.

Parameters:
  • obj_ID (int) – The Object ID.

  • mag (boolean, default = False) – If True plot the magnitude instead of the flux.

  • zp (float) – Used zeropoint for the plot.

  • plot_sim (boolean, default = True) – If True plot the theorical simulated lightcurve.

  • plot_fit (boolean, default = False) – If True plot the fitted lightcurve.

  • Jy (boolean, default = False) – If True plot in Jansky.

  • mod (boolean, default = False) – If True use the self.modified_lcs rather than self.sim_lcs

Returns:

Just plot the SN lightcurve !

Return type:

None

Notes

Use plot_lc from utils.

plot_ra_dec(plot_vpec=False, field_dic=None, field_size=None, **kwarg)[source]

Plot a mollweide map of ra, dec.

Parameters:
  • plot_vpec (boolean) – If True plot a vpec colormap.

  • field_dic (dict(int : dict(str : float))) – Dict of fields coordinates -> Field_ID : {‘RA’, ‘Dec’}

  • field_size (list(float, float)) – The size of the field [RA, Dec]

Returns:

Just plot the map.

Return type:

None

get(key, mod=False)[source]

Get an array of sim_lc metadata.

Parameters:

key (str) – The metadata to access.

Returns:

The array of the key metadata for all SN.

Return type:

numpy.ndarray

get_peakmags(band, magsys='ab')[source]

Get peak apparent magnitude in any band.

Parameters:
  • band (str) – The band, the name has to be in sncosmo registry

  • magsys (str) – The magnitude system, default: ab.

Returns:

The array of the peak apparent magnitude for all SN.

Return type:

numpy.ndarray

property name

Get sample name.

property header

Get header.

property n_obj

Get SN number.

property sim_lcs

Get sim_lcs.

property meta

Get lcs meta dict.

property sim_model

Get sim model.

property fit_model

Get fit model.

property fit_res

Get fit results list.

class snsim.SurveyObs(survey_config)[source]

This class deals with the observations of the survey.

Parameters:
  • survey_config (|) – It contains all the survey configuration.

  • survey_config

  • FILE (| ├── survey_file PATH TO SURVEY)

  • float (| ├── dec_size DEC FIELD SIZE IN DEG ->)

  • str (SUBFIELD KEY ->)

  • opt

  • str

  • opt

  • float

  • opt

  • float

  • opt

  • survey_cut (| ├──)

  • dict (CUT ON OBS FILE ->)

  • opt

  • add_data (| ├──)

  • list(str) (LIST OF KEY TO ADD METADATA ->)

  • opt

  • float

  • geo_field_map (opt if)

  • float

  • geo_field_map

  • str

  • opt

  • field_map (| ├──)

  • str

  • opt

  • sub_field_key (| └──)

  • str

  • opt

  • class. (Initialize SurveyObs)

compute_geo_field_map()[source]

Compute the GeoFieldMap and writte it for future use

Returns:

GeoDataFrame

Return type:

GeoFieldMap

get_observations(params, phase_cut=None, nep_cut=None, IDmin=0, use_dask=False, npartitions=None)[source]

Give the epochs of observations of a given SN.

Parameters:
Returns:

pandas dataframe containing the observations.

Return type:

pandas.DataFrame()

show_map(ax=None)[source]

Plot a representation of sub-fields.

property config

Survey configuration.

property band_dic

band_sncosmo.

Type:

Get the dic band_survey

property obs_table

Table of the observations.

property gain

Get CCD gain in e-/ADU.

property zp

Get zero point and it’s uncertainty.

property fwhm_psf

Get PSF width.

property duration

Get the survey duration in days.

property start_end_days

Get the survey start and ending days.

property field_size_rad

Get field size ra, dec in radians.

class snsim.SnHosts(config, z_range=None, geometry=None)[source]

Class containing the SN Host parameters.

Parameters:
  • config (str) –

    Configuration of host.

    config
    ├── host_file, ‘PATH/TO/HOSTFILE’
    ├── distrib, str, Optional, default = ‘rate’, options given by self._dist_options
    ├── reweight_vol, bool, Optional, default = False, reweight input host distrib to volumetric
    └── key_dic: {‘column_name’: ‘new_column_name’, etc}, Optional, only use to change columns names

  • z_range (list(float), opt) – The redshift range.

  • class. (Initialize SnHost)

property config

Get the configuration dic of host.

property max_dz

Get the maximum redshift gap.

property df

Get pandas Dataframe of host.

compute_weights(rate=None, sn_type=None, cosmology=None)[source]

Compute the weights for random choice.

Parameters:

rate (function, optional) – rate function of z, by default None.

Returns:

weigths for the random draw.

Return type:

numpy.ndarray(float)

random_choice(n, seed=None, rate=None, sn_type=None, cosmology=None)[source]

Randomly select hosts.

Parameters:
  • n (int) – Number of hosts to select.

  • seed (int, opt) – Random seed.

Returns:

Dataframe with selected hosts properties.

Return type:

pandas.Dataframe