snsim ===== .. py:module:: snsim .. autoapi-nested-parse:: 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 ---------- .. toctree:: :maxdepth: 1 /autoapi/snsim/astrobj/index /autoapi/snsim/constants/index /autoapi/snsim/dust_utils/index /autoapi/snsim/generators/index /autoapi/snsim/geo_utils/index /autoapi/snsim/hosts/index /autoapi/snsim/io_utils/index /autoapi/snsim/nb_fun/index /autoapi/snsim/plasticc_model/index /autoapi/snsim/plot_utils/index /autoapi/snsim/post_sim_tools/index /autoapi/snsim/salt_utils/index /autoapi/snsim/sample/index /autoapi/snsim/scatter/index /autoapi/snsim/simu/index /autoapi/snsim/survey/index /autoapi/snsim/tests/index /autoapi/snsim/utils/index Classes ------- .. autoapisummary:: snsim.Simulator snsim.SimSample snsim.SurveyObs snsim.SnHosts Package Contents ---------------- .. py:class:: Simulator(param_dic, print_config=False) Simulation class using a config file config.yml. :param param_dic: The configuration yaml file / The dictionnary containing all simulation parameters. :type param_dic: dict / str .. rubric:: 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 | 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 | sig_psf: GAUSSIAN PSF SIGMA # Otional, default given by survey file as FWHMeff | noise_key: [key, type] type can be 'mlim5' or 'skysigADU' | ra_size: RA FIELD SIZE | dec_size: DEC FIELD SIZE | gain: CCD GAIN e-/ADU (Optional, default given by survey file) | sub_field: ['sub_field_file', 'sub_field_key'] | cdd_noise : sig_ccd_noise # Optional, default is 0 ADU | 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 | M0: 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. .. py:method:: simulate() Launch the simulation. :rtype: None .. rubric:: 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) .. py:property:: config Get the whole configuration dic. .. py:property:: sim_name Get sim name. .. py:property:: vpec_dist Get vpec option. .. py:property:: cmb Get cmb parameters. .. py:property:: samples Get the list of simulated sn. .. py:property:: cosmology Get astropy cosmological model used in simulation. .. py:property:: survey Get the SurveyObs object of the simulation. .. py:property:: generators Get the SNGen object of the simulation. .. py:property:: hosts Get the SnHosts object of the simulation. .. py:property:: randseed Get primary random seed of the simulation. .. py:property:: z_range Get z_range. .. py:property:: nep_cut Get the list of epochs cuts. .. py:class:: SimSample(sample_name, sim_lcs, header, dir_path=None) Class to store simulated SN sample. :param sample_name: Name of the sample. :type sample_name: str :param sim_lcs: The simulated lightcurves. :type sim_lcs: list(astropy.Table) :param header: Simulation header. :type header: dict :param model_dir: The path to the simulation model files. :type model_dir: str, opt :param file_path: Path of the sample. :type file_path: str, opt :param Initialize SimSample class.: .. py:method:: fromDFlist(sample_name, sim_lcs, header, dir_path=None) :classmethod: Initialize the class from a list of pandas.DataFrame. :param cls: The SimSample class. :type cls: SimSample class :param sim_file: The file to load. :type sim_file: str :param model_dir: The directory of the configuration files of the sim model. :type model_dir: str, opt :param sample_name: Name of the simulation. :type sample_name: str :param sim_lcs: The sim lightcurves. :type sim_lcs: list(pandas.DataFrame) :param header: Simulation header. :type header: dict :returns: A SimSample class with the simulated lcs. :rtype: SimSample class object .. py:method:: fromFile(sim_file, engine='pyarrow') :classmethod: Initialize the class from a fits or pickle file. :param cls: The SimSample class. :type cls: SimSample class :param sim_file: The file to load. :type sim_file: str :param model_dir: The directory of the configuration files of the sim model. :type model_dir: str, opt :param engine: Engine to use to open the file pyarrow or fastparquet. :type engine: str :returns: A SimSample class with the simulated lcs. :rtype: SimSample class object .. py:method:: get_obj_sim_model(obj_ID) Get th sim model of one obj. :param obj_ID: ID of the obj. :type obj_ID: int :returns: sncosmo sim model of the obj. :rtype: sncosmo.Model .. py:method:: set_fit_model(model, model_dir=None, mw_dust=None) Set the fit with a given SNCosmo Model. :param model: A sncosmo Model or a model name for utils.init_sn_model(model, model_dir). :type model: sncosmo.models.Model or str :param model_dir: In case you want to set your model via utils.init_sn_model(model, model_dir). :type model_dir: str, opt :param mw_dust: Milky Wat dust model to apply. | mw_dust | ├── model : str (model name) | └── rv : float, opt :type mw_dust: dict, opt :returns: Set the self._fit_model attribute. :rtype: None .. py:method:: fit_lc(obj_ID=None, **kwargs) Fit all or just one SN lightcurve(s). :param ID: The SN ID, if not specified all SN are fit. :type ID: int, default is None :returns: Directly modified the _fit_res attribute. :rtype: None .. rubric:: Notes Use snc_fitter from utils .. py:method:: write_mod(formats=['pkl', 'parquet']) Write a file containing only the modified SN epochs. :param formats: The output formats, 'pkl' or 'fits'. :type formats: list(str) or str, opt :returns: Just write a file. :rtype: None .. py:method:: write_fit(fit_model_name, write_path=None) Write fits results in fits format. :returns: Write an output file. :rtype: None .. rubric:: Notes Use write_fit from utils. .. py:method:: plot_hist(key, ax=None, **kwargs) Plot the histogram of the key metadata. :param key: A key of lightcurves metadata. :type key: str :param ax: ax on which plot the histogram. :type ax: matplotlib.axis, opt :param \*\*kwargs: matplotlib plot options. :type \*\*kwargs: type :returns: Description of returned object. :rtype: type .. py:method:: plot_lc(obj_ID, plot_sim=True, plot_fit=False, **kwargs) Plot the given SN lightcurve. :param obj_ID: The Object ID. :type obj_ID: int :param mag: If True plot the magnitude instead of the flux. :type mag: boolean, default = False :param zp: Used zeropoint for the plot. :type zp: float :param plot_sim: If True plot the theorical simulated lightcurve. :type plot_sim: boolean, default = True :param plot_fit: If True plot the fitted lightcurve. :type plot_fit: boolean, default = False :param Jy: If True plot in Jansky. :type Jy: boolean, default = False :param mod: If True use the self.modified_lcs rather than self.sim_lcs :type mod: boolean, default = False :returns: Just plot the SN lightcurve ! :rtype: None .. rubric:: Notes Use plot_lc from utils. .. py:method:: plot_ra_dec(plot_vpec=False, field_dic=None, field_size=None, **kwarg) Plot a mollweide map of ra, dec. :param plot_vpec: If True plot a vpec colormap. :type plot_vpec: boolean :param field_dic: Dict of fields coordinates -> Field_ID : {'RA', 'Dec'} :type field_dic: dict(int : dict(str : float)) :param field_size: The size of the field [RA, Dec] :type field_size: list(float, float) :returns: Just plot the map. :rtype: None .. py:method:: get(key, mod=False) Get an array of sim_lc metadata. :param key: The metadata to access. :type key: str :returns: The array of the key metadata for all SN. :rtype: numpy.ndarray .. py:method:: get_peakmags(band, magsys='ab') Get peak apparent magnitude in any band. :param band: The band, the name has to be in sncosmo registry :type band: str :param magsys: The magnitude system, default: ab. :type magsys: str :returns: The array of the peak apparent magnitude for all SN. :rtype: numpy.ndarray .. py:property:: name Get sample name. .. py:property:: header Get header. .. py:property:: n_obj Get SN number. .. py:property:: sim_lcs Get sim_lcs. .. py:property:: meta Get lcs meta dict. .. py:property:: sim_model Get sim model. .. py:property:: fit_model Get fit model. .. py:property:: fit_res Get fit results list. .. py:class:: SurveyObs(survey_config) This class deals with the observations of the survey. :param survey_config: It contains all the survey configuration. :type survey_config: dic :param | survey_config: :param | ├── survey_file PATH TO SURVEY FILE: :param | ├── ra_size RA FIELD SIZE IN DEG -> float: :param | ├── dec_size DEC FIELD SIZE IN DEG -> float: :param | ├── gain CCD GAIN e-/ADU -> float: :param | ├── start_day STARTING DAY -> float or str: :param opt: :param | ├── end_day ENDING DAY -> float or str: :param opt: :param | ├── duration SURVEY DURATION -> float: :param opt: :param | ├── zp FIXED ZEROPOINT -> float: :param opt: :param | ├── survey_cut: :param CUT ON OBS FILE -> dict: :param opt: :param | ├── add_data: :param LIST OF KEY TO ADD METADATA -> list(str): :param opt: :param | ├── field_map: :param PATH TO SUBFIELD MAP FILE -> str: :param opt: :param | └── sub_field: :param SUBFIELD KEY -> str: :param opt: :param Initialize SurveyObs class.: .. py:method:: get_observations(params, phase_cut=None, nep_cut=None, IDmin=0, use_dask=False, npartitions=None) Give the epochs of observations of a given SN. :param ra: Obj ra coord [rad]. :type ra: numpy.ndarray(float) or float :param dec: Obj dec coord [rad]. :type dec: numpy.ndarray(float) or float :param t0: Obj sncosmo model peak time. :type t0: numpy.ndarray(float) or float :param MinT: Obj sncosmo model mintime. :type MinT: numpy.ndarray(float) or float :param MaxT: Obj sncosmo model maxtime. :type MaxT: numpy.ndarray(float) or float :param nep_cut: The cut [nep, mintime, maxtime, band]. :type nep_cut: list(list(int, float, float, str)), opt :param IDmin: ID of the first object. :type IDmin: int, opt :returns: pandas dataframe containing the observations. :rtype: pandas.DataFrame() .. py:method:: show_map(ax=None) Plot a representation of subfields. .. py:property:: config Survey configuration. .. py:property:: band_dic band_sncosmo. :type: Get the dic band_survey .. py:property:: obs_table Table of the observations. .. py:property:: gain Get CCD gain in e-/ADU. .. py:property:: zp Get zero point and it's uncertainty. .. py:property:: fwhm_psf Get PSF width. .. py:property:: duration Get the survey duration in days. .. py:property:: start_end_days Get the survey start and ending days. .. py:property:: field_size_rad Get field size ra, dec in radians. .. py:class:: SnHosts(config, z_range=None, geometry=None) Class containing the SN Host parameters. :param config: 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 :type config: str :param z_range: The redshift range. :type z_range: list(float), opt :param Initialize SnHost class.: .. py:property:: config Get the configuration dic of host. .. py:property:: max_dz Get the maximum redshift gap. .. py:property:: df Get pandas Dataframe of host. .. py:method:: compute_weights(rate=None, sn_type=None, cosmology=None) Compute the weights for random choice. :param rate: rate function of z, by default None. :type rate: function, optional :returns: weigths for the random draw. :rtype: numpy.ndarray(float) .. py:method:: random_choice(n, seed=None, rate=None, sn_type=None, cosmology=None) Randomly select hosts. :param n: Number of hosts to select. :type n: int :param seed: Random seed. :type seed: int, opt :returns: Dataframe with selected hosts properties. :rtype: pandas.Dataframe