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¶
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 insurvey_file doesn’t match sncosmo namegain: CCD GAIN e-/ADU # Optional, default given by survey filesub_field: ‘sub_field_key’ # Optionalcdd_noise : sig_ccd_noise # Optional, default is 0 ADUkey_dic: {‘column_name’: ‘new_column_name’, etc} # Optional, to change columns namesadd_data: [‘keys1’, ‘keys2’, …] add db file keys to metadatasurvey_cut: {‘key1’: [‘conditon1’,’conditon2’,…], ‘key2’: [‘conditon1’]}start_day: MJD NUMBER or ‘YYYY-MM-DD’ # Optional, default given by survey fileduration: SURVEY DURATION (DAYS) # Optional, default given by survey filezp: INSTRUMENTAL ZEROPOINT # Optional, default given by survey filesig_zp: ZEROPOINT ERROR # Optional, default given by survey filefwhm_psf: GAUSSIAN PSF FWHM # Otional, default given by survey file as FWHMeffnoise_key: [key, type] type can be ‘mlim5’ or ‘skysigADU’ra_size: RA FIELD SIZE # Optional if there is geo_field_mapdec_size: DEC FIELD SIZE # Optional if there is geo_field_mapfield_shape: ‘/PATH/TO/FIELD_SHAPE_FILE’ # Optional if there is geo_field_mapgeo_field_map: ‘/PATH/TO/GEO_FIELD_MAP_FILE’ # Optionalsim_par:randseed: RANDSEED TO REPRODUCE SIMULATION # Optionalz_range: [ZMIN, ZMAX]nep_cut: [[nep_min1,Tmin,Tmax],[nep_min2,Tmin2,Tmax2,’filter1’],…] EP CUTSduration_for_rate: FAKE DURATION ONLY USE TO GENERATE N OBJ # Optionalmw_dust:model: MOD_NAMEr_v: Rv # Optional, default Rv = 3.1snia_gen:n_sn: NUMBER OF SN TO GENERATE # Optionalrate: rate of SN/Mpc^3/year # Optional, default=3e-5Mabs: SN ABSOLUT MAGNITUDEsigM: SN INTRINSIC COHERENT SCATTERINGsct_model: ‘G10’,’C11_i’ USE WAVELENGHT DEP MODEL FOR SN INT SCATTERINGmodel_name: ‘THE MODEL NAME’ Example : ‘salt2’model_dir: ‘/PATH/TO/SALT/MODEL’alpha: STRETCH CORRECTION = alpha*x1beta: COLOR CORRECTION = -beta*cdist_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 DENSITYH0: HUBBLE CONSTANTcmb:v_cmb: OUR PECULIAR VELOCITY # Optional, default = 620 km/sl_cmb: GAL L OF CMB DIPOLE # Optional, default = 271.0b_cmb: GAL B OF CMB DIPOLE # Optional, default = 29.6vpec_dist:mean_vpec: MEAN SN PECULIAR VELOCITYsig_vpec: SIGMA VPEChosts: (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 namesdask: # Optional for using dask parallelizationuse: True or Falsenworkers: NUMBER OF WORKERS # used to adjust work distributionInitialise 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:
- classmethod fromDFlist(sample_name, sim_lcs, header, dir_path=None)[source]¶
Initialize the class from a list of pandas.DataFrame.
- Parameters:
- 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:
- 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:
- 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_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_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.
- 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:
- get_peakmags(band, magsys='ab')[source]¶
Get peak apparent magnitude in any band.
- Parameters:
- Returns:
The array of the peak apparent magnitude for all SN.
- Return type:
- 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:
ra (numpy.ndarray(float) or float) – Obj ra coord [rad].
dec (numpy.ndarray(float) or float) – Obj dec coord [rad].
t0 (numpy.ndarray(float) or float) – Obj sncosmo model peak time.
MinT (numpy.ndarray(float) or float) – Obj sncosmo model mintime.
MaxT (numpy.ndarray(float) or float) – Obj sncosmo model maxtime.
nep_cut (list(list(int, float, float, str)), opt) – The cut [nep, mintime, maxtime, band].
IDmin (int, opt) – ID of the first object.
- Returns:
pandas dataframe containing the observations.
- Return type:
- 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 namesclass. (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.