From 7acf0c040544036ff31971cbf76019e453ca152f Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 13:57:51 +0100 Subject: [PATCH 1/8] Test file --- skypy/supernova/test.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 skypy/supernova/test.py diff --git a/skypy/supernova/test.py b/skypy/supernova/test.py new file mode 100644 index 000000000..df1dc6821 --- /dev/null +++ b/skypy/supernova/test.py @@ -0,0 +1 @@ +print('Hello World') From ade2aa8f51128e8154ab74e73a3e0e1f8273455a Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:40:51 +0100 Subject: [PATCH 2/8] Create Ia redshift rate Create Ia volumetric rate for a specific redshift --- skypy/supernova/Ia_redshift_rate.py | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 skypy/supernova/Ia_redshift_rate.py diff --git a/skypy/supernova/Ia_redshift_rate.py b/skypy/supernova/Ia_redshift_rate.py new file mode 100644 index 000000000..93b81c05d --- /dev/null +++ b/skypy/supernova/Ia_redshift_rate.py @@ -0,0 +1,48 @@ +r"""Creates the volumetric SNe Ia rate for an array of redshifts +================= +.. autosummary:: + :nosignatures: + :toctree: ../api/ + SNeIa_redshifts + +Models +====== +.. autosummary:: + :nosignatures: + :toctree: ../api/ + Ia_redshift_rate + +""" + +import numpy as np +from astropy import units + +def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): + """Creates a redshift distribution of Type Ia Supernovae + This function computes the redshift distribution of Type Ia Supernovae + using the rate parameters as given in [1]. + Parameters + ---------- + redshift : float + Redshift at which to evaluate the Type Ia supernovae rate. + cosmology : astropy.cosmology.Cosmology + Cosmology object providing methods for the evolution history of + omega_matter and omega_lambda with redshift. + Returns + ------- + rate : astropy.Quantity + Volumetric rate of Type Ia's the redshifts given in units of [SNe Ia yr−1 Mpc−3] + + Examples + -------- + >>> import numpy as np + >>> z = np.array([0.0,0.1,0.2]) + >>> Ia_redshift_rate(z,r0=2.27e-5,a=1.7) + + References + ---------- + .. [1] Frohmaier, C. et al. (2019), https://arxiv.org/pdf/1903.08580.pdf . + """ + + rate = r0*(1+redshift)**a * units.year *(units.Mpc)**-3 + return rate \ No newline at end of file From a2568e3c1594a07a6020e886fe16382df683955f Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:42:17 +0100 Subject: [PATCH 3/8] Fix github bug fix github bug --- skypy/supernova/Ia_redshift_rate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/skypy/supernova/Ia_redshift_rate.py b/skypy/supernova/Ia_redshift_rate.py index 93b81c05d..b67143884 100644 --- a/skypy/supernova/Ia_redshift_rate.py +++ b/skypy/supernova/Ia_redshift_rate.py @@ -14,7 +14,6 @@ """ -import numpy as np from astropy import units def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): From b09793214625a45faf0d82f1c8f623de8f22edd6 Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:43:27 +0100 Subject: [PATCH 4/8] Update to required modules Update to required modules --- skypy/supernova/Ia_redshift_rate.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/skypy/supernova/Ia_redshift_rate.py b/skypy/supernova/Ia_redshift_rate.py index b67143884..89e048743 100644 --- a/skypy/supernova/Ia_redshift_rate.py +++ b/skypy/supernova/Ia_redshift_rate.py @@ -22,11 +22,8 @@ def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): using the rate parameters as given in [1]. Parameters ---------- - redshift : float + redshift : numpy.array Redshift at which to evaluate the Type Ia supernovae rate. - cosmology : astropy.cosmology.Cosmology - Cosmology object providing methods for the evolution history of - omega_matter and omega_lambda with redshift. Returns ------- rate : astropy.Quantity From b861c5d22f9306160ba880e877e1de9d54b5ea14 Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:44:28 +0100 Subject: [PATCH 5/8] Removed test file Removed test file --- skypy/supernova/test.py | 1 - 1 file changed, 1 deletion(-) delete mode 100644 skypy/supernova/test.py diff --git a/skypy/supernova/test.py b/skypy/supernova/test.py deleted file mode 100644 index df1dc6821..000000000 --- a/skypy/supernova/test.py +++ /dev/null @@ -1 +0,0 @@ -print('Hello World') From f63b212f6f69d21625ff2aaf2dea77a0826b1caf Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:47:37 +0100 Subject: [PATCH 6/8] Fix whitespace Fix whitespace --- skypy/supernova/Ia_redshift_rate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skypy/supernova/Ia_redshift_rate.py b/skypy/supernova/Ia_redshift_rate.py index 89e048743..8744ae03c 100644 --- a/skypy/supernova/Ia_redshift_rate.py +++ b/skypy/supernova/Ia_redshift_rate.py @@ -11,11 +11,11 @@ :nosignatures: :toctree: ../api/ Ia_redshift_rate - """ from astropy import units + def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): """Creates a redshift distribution of Type Ia Supernovae This function computes the redshift distribution of Type Ia Supernovae From ce81b81b9f6069d5ccc9d1ec0930dbfd275704bd Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Fri, 17 Apr 2020 14:50:37 +0100 Subject: [PATCH 7/8] Updated whitespace and style Updated whitespace and style --- skypy/supernova/Ia_redshift_rate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/skypy/supernova/Ia_redshift_rate.py b/skypy/supernova/Ia_redshift_rate.py index 8744ae03c..1ab5f3ce2 100644 --- a/skypy/supernova/Ia_redshift_rate.py +++ b/skypy/supernova/Ia_redshift_rate.py @@ -16,7 +16,7 @@ from astropy import units -def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): +def Ia_redshift_rate(redshift, r0=2.27e-5, a=1.7): """Creates a redshift distribution of Type Ia Supernovae This function computes the redshift distribution of Type Ia Supernovae using the rate parameters as given in [1]. @@ -27,7 +27,8 @@ def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): Returns ------- rate : astropy.Quantity - Volumetric rate of Type Ia's the redshifts given in units of [SNe Ia yr−1 Mpc−3] + Volumetric rate of Type Ia's the redshifts given in units of + [SNe Ia yr−1 Mpc−3] Examples -------- @@ -41,4 +42,4 @@ def Ia_redshift_rate(redshift,r0 = 2.27e-5,a = 1.7): """ rate = r0*(1+redshift)**a * units.year *(units.Mpc)**-3 - return rate \ No newline at end of file + return rate From b9c61e0ecf8a0f40b5967428193235604acc66fb Mon Sep 17 00:00:00 2001 From: elizabethswann Date: Sun, 30 Aug 2020 00:01:50 +0100 Subject: [PATCH 8/8] Create Ia_redshift_distribution.py --- skypy/supernova/Ia_redshift_distribution.py | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 skypy/supernova/Ia_redshift_distribution.py diff --git a/skypy/supernova/Ia_redshift_distribution.py b/skypy/supernova/Ia_redshift_distribution.py new file mode 100644 index 000000000..ffe545003 --- /dev/null +++ b/skypy/supernova/Ia_redshift_distribution.py @@ -0,0 +1,80 @@ +r"""Creates the redshift distribution of SNe Ia given a volumetric rate +================= +.. autosummary:: + :nosignatures: + :toctree: ../api/ + SNeIa_redshifts + +Models +====== +.. autosummary:: + :nosignatures: + :toctree: ../api/ + Ia_redshift_dist +""" +import numpy as np +from astropy import units +from scipy.interpolate import InterpolatedUnivariateSpline +from numpy import random + +def Ia_redshift_dist(zmax, cosmology, time=365.25, area=10., rate_function=lambda z: 2.47.e-5): + """Generates an intrisic redshift distribution and number of tranisents, + given an input volumetric rate, number of days and sky area. + Parameters + ---------- + zmax : float + Maximum redshift at which to calculate the SNe Ia rate + cosmology : instance + Instance of an Astropy Cosmology class. + time : float, optional + Time in days (default is 1 year or 365.25 days), observer frame + area : float, optional + Area in square degrees (default is 10 square degrees). + rate_function : callable + A function that accepts a single float (redshift) and returns the + comoving volumetric rate at each redshift in units of yr^-1 Mpc^-3. + Default is to set the rate to 2.47e-5 yr^-1 Mpc^-3 for all redshifts (accurate to z~0.1) + + Returns + ------- + redshift_dist : numpy.array + + Examples + -------- + >>> + >>> + >>> + """ + + # Get the comoving volume for each redshift shell + z_bins = 100 + z_binedges = np.linspace(0., zmax, z_bins + 1) + z_bincentre = np.array(0.5 * (z_binedges[1:] + z_binedges[:-1])) + + vol_sphere = np.array(cosmology.comoving_volume(z_binedges).value).real + vol_shell = vol_sphere[1:] - vol_sphere[:-1] + + # SN / (observer year) in shell + rate_in_shell = np.array(vol_shell * rate_function(z_bincentre).value / (1.+z_bincentre)) + + # SN / (observer year) within z_binedges + vol_rate = np.zeros_like(z_binedges) + vol_rate[1:] = np.add.accumulate(rate_in_shell) + + # Create a percent point function. + snrate_cdf = vol_rate / vol_rate[-1] + snrate_ppf = InterpolatedUnivariateSpline(snrate_cdf, z_binedges, k=1) + + print(snrate_ppf) + + # Total numbe of SNe + print(area/(4. * np.pi * (180. / np.pi) ** 2)) + print(vol_rate[-1]) + nsne = vol_rate[-1] * (time/365.25) * (area/(4. * np.pi * (180. / np.pi) ** 2)) + print(nsne) + + #for i in range(random.poisson(nsne)): + # yield float(snrate_ppf(random.random())) + redshifts=np.array(list([float(snrate_ppf(random.random())) for i in range(random.poisson(nsne))])) + + return redshifts \ No newline at end of file