snsim.utils =========== .. py:module:: snsim.utils .. autoapi-nested-parse:: This module contains usefull function for the simulation. Classes ------- .. autoapisummary:: snsim.utils.CustomRandom Functions --------- .. autoapisummary:: snsim.utils.gauss snsim.utils.reshape_prob_data snsim.utils.set_cosmo snsim.utils.init_snc_source snsim.utils.scale_M0_cosmology snsim.utils.init_astropy_time snsim.utils.compute_z_cdf snsim.utils.asym_gauss snsim.utils.compute_zpcmb snsim.utils.init_snia_source snsim.utils.norm_flux snsim.utils.flux_to_Jansky snsim.utils.zobs_MinT_MaxT snsim.utils.print_dic snsim.utils.Templatelist_fromsncosmo snsim.utils.select_Vincenzi_template snsim.utils.print_rate snsim.utils.sine_interp snsim.utils.gen_rndchilds snsim.utils.compute_weight_mass_for_type snsim.utils.compute_weight_SFR_for_type snsim.utils.compute_weight_mass_sfr_for_type Module Contents --------------- .. py:function:: gauss(mu, sig, x) Gaussian function. :param mu: Mean. :type mu: float :param sig: Sigma. :type sig: float :param x: Variables. :type x: float or numpy.array(float) :returns: G(x). :rtype: numpy.array(float) .. py:class:: CustomRandom(pdf, xmin, xmax, ndiv=10000.0, dx=None) Class to generate random variable on custom dist. :param pdf: Function that return the pdf of the vairable x. :type pdf: lambda function :param xmin: Inferior bound of the distribution. :type xmin: float :param xmax: Superior bound of the distribution. :type xmax: float :param ndiv: Number of division used to integrate the pdf. :type ndiv: float, optional :param dx: Precision used to integrate the pdf. :type dx: float, optional .. rubric:: 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. .. py:attribute:: x .. py:attribute:: dx .. py:attribute:: pdfx .. py:attribute:: norm .. py:attribute:: cdf .. py:method:: plot_pdf(ax=None) Plot the pdf function. :param ax: Figure axis, by default None :type ax: matplotlib axes, optional .. py:method:: plot_cdf(ax=None) Plot the cdf function. :param ax: Figure axis, by default None :type ax: matplotlib axes, optional .. py:method:: draw(n, seed=None) Draw n parameters from the distribution. :param n: Number of parameters to draw. :type n: int :param seed: Random seed, by default None :type seed: int, optional :returns: Random parameters following the custom distribution. :rtype: numpy.array .. py:function:: reshape_prob_data() function that read DES X1-mass probability file and return grid values fro interpolation .. py:function:: set_cosmo(cosmo_dic) Load an astropy cosmological model. :param cosmo_dic: A dict containing cosmology parameters. :type cosmo_dic: dict :returns: An astropy cosmological model. :rtype: astropy.cosmology.object .. py:function:: init_snc_source(name, version=None) .. py:function:: scale_M0_cosmology(h, M0_art, h_art) Compute a value of M0 corresponding the cosmology used in the simulation. :param h: The H0 / 100 constant to scale M0. :type h: float :param M0_art: M0 value to be scaled :type M0_art: float :param h_art: the H0/100 constant used in the article to retrive M0_art :type h_art: float :returns: Scaled SN Absolute Magnitude. :rtype: float .. py:function:: init_astropy_time(date) Take a date and give a astropy.time.Time object. :param date: The date in MJD number or YYYY-MM-DD string. :type date: int, float or str :returns: An astropy.time Time object of the given date. :rtype: astropy.time.Time .. py:function:: compute_z_cdf(z_shell, shell_time_rate) Compute the cumulative distribution function of redshift. :param z_shell: The redshift of the shell edges. :type z_shell: numpy.ndarray(float) :param shell_time_rate: The time rate of each shell. :type shell_time_rate: numpy.ndarray(float) :returns: redshift, CDF(redshift). :rtype: list(numpy.ndarray(float), numpy.ndarray(float)) .. py:function:: asym_gauss(mu, sig_low, sig_high=None, seed=None, size=1) Generate random parameters using an asymetric Gaussian distribution. :param mean: The central value of the Gaussian. :type mean: float :param sig_low: The low sigma. :type sig_low: float :param sig_high: The high sigma. :type sig_high: float :param seed: Random seed. :type seed: int, optional :param size: Number of numbers to generate :type size: int :returns: Random(s) variable(s). :rtype: numpy.ndarray(float) .. py:function:: compute_zpcmb(ra, dec, cmb) Compute the redshifts of a list of objects relative to the CMB. :param ra: Right Ascension of the objects. :type ra: np.ndarray(float) :param dec: Declinaison of the objects. :type dec: np.ndarray(float) :param cmb: Dict containing cmb coords and velocity. :type cmb: dict :returns: Redshifts relative to cmb. :rtype: np.ndarray(float) .. py:function:: init_snia_source(name, model_dir=None, version=None) Initialise a sncosmo source. :param name: Name of the model. :type name: str :param model_dir: Path to the model files. :type model_dir: str :returns: sncosmo Model corresponding to input configuration. :rtype: sncosmo.Model .. py:function:: norm_flux(flux_table, zp) Rescale the flux to a given zeropoint. :param flux_table: A table containing at least flux and fluxerr. :type flux_table: astropy.Table :param zp: The zeropoint to rescale the flux. :type zp: float :returns: Rescaled flux and fluxerr arry. :rtype: np.ndarray(float), np.ndarray(float) .. py:function:: flux_to_Jansky(zp, band) Give the factor to convert flux in uJy. :param zp: The actual zeropoint of flux. :type zp: float :param band: The sncosmo band in which compute the factor. :type band: str :returns: The conversion factor. :rtype: float .. py:function:: zobs_MinT_MaxT(par, model_t_range) .. py:function:: print_dic(dic, prefix='') .. py:function:: Templatelist_fromsncosmo(source_type=None) 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 :rtype: list on names of sources with the given source_type from snscomo catalogue .. py:function:: select_Vincenzi_template(model_list, corr=None) from a given list of sncosmo Template select the ones from Vincenzi et al. 2019 Parameters ----------- model_list : list starting list of templates corr : bool If True select templates that have been corrected for the host galaxy dust Returns --------- list of template names .. py:function:: print_rate(use_rate, gen) Print simulation rate in a fancy format :param use_rate: True if in the simulation the object are created with a specific rate in /Mpc^3/year :type use_rate: bool :param gen: :type gen: Generator Object :rtype: print the rate .. py:function:: sine_interp(x_new, fun_x, fun_y) Make a sinus interpolation of a function. :param x_new: Points where interpolate. :type x_new: numpy.ndarray(float) :param fun_x: x values of the function :type fun_x: numpy.ndarray(float) :param fun_y: values of the function evaluate at fun_x :type fun_y: numpy.ndarray(float) :returns: Values of the function at x_new. :rtype: numpy.ndarray(float) :raises ValueError: fun_x and fun_y don't have the same length :raises ValueError: x_new is out of range .. py:function:: gen_rndchilds(seed, size=1) Create child random seeds. :param seed: A random seed. :type seed: numpy.random.SeedSequence or int :param size: number of child random seed to generate, by default 1 :type size: int, optional :returns: The desired number of child random seeds :rtype: tuple(numpy.random.SeedSequence) .. py:function:: compute_weight_mass_for_type(mass, sn_type, cosmology) compute the mass dependent weights for HOST - SN matching .. py:function:: compute_weight_SFR_for_type(SFR, sn_type, cosmology) compute the SFR dependent weights for HOST - SN matching .. py:function:: compute_weight_mass_sfr_for_type(mass, sfr, sn_type, cosmology) compute the SFR dependent weights for HOST - SN matching