ler 0.3.7__py3-none-any.whl → 0.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ler might be problematic. Click here for more details.
- ler/__init__.py +1 -1
- ler/gw_source_population/cbc_source_parameter_distribution.py +74 -31
- ler/gw_source_population/cbc_source_redshift_distribution.py +37 -28
- ler/gw_source_population/jit_functions.py +1 -1
- ler/image_properties/image_properties.py +46 -23
- ler/image_properties/multiprocessing_routine.py +26 -11
- ler/lens_galaxy_population/jit_functions.py +1 -0
- ler/lens_galaxy_population/lens_galaxy_parameter_distribution.py +23 -23
- ler/lens_galaxy_population/optical_depth.py +20 -18
- ler/rates/gwrates.py +593 -205
- ler/rates/ler copy.py +2097 -0
- ler/rates/ler.py +1068 -577
- ler/utils/plots.py +266 -223
- ler/utils/utils.py +44 -10
- {ler-0.3.7.dist-info → ler-0.3.9.dist-info}/METADATA +2 -2
- ler-0.3.9.dist-info/RECORD +25 -0
- {ler-0.3.7.dist-info → ler-0.3.9.dist-info}/WHEEL +1 -1
- ler-0.3.7.dist-info/RECORD +0 -24
- {ler-0.3.7.dist-info → ler-0.3.9.dist-info}/LICENSE +0 -0
- {ler-0.3.7.dist-info → ler-0.3.9.dist-info}/top_level.txt +0 -0
ler/__init__.py
CHANGED
|
@@ -269,9 +269,9 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
269
269
|
self.directory = directory
|
|
270
270
|
# initialize the interpolator's parameters
|
|
271
271
|
self.create_new_interpolator = dict(
|
|
272
|
-
redshift_distribution=dict(create_new=False, resolution=
|
|
273
|
-
z_to_luminosity_distance=dict(create_new=False, resolution=
|
|
274
|
-
differential_comoving_volume=dict(create_new=False, resolution=
|
|
272
|
+
redshift_distribution=dict(create_new=False, resolution=1000),
|
|
273
|
+
z_to_luminosity_distance=dict(create_new=False, resolution=1000),
|
|
274
|
+
differential_comoving_volume=dict(create_new=False, resolution=1000),
|
|
275
275
|
)
|
|
276
276
|
if isinstance(create_new_interpolator, dict):
|
|
277
277
|
self.create_new_interpolator.update(create_new_interpolator)
|
|
@@ -291,27 +291,21 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
291
291
|
event_type, source_priors, source_priors_params
|
|
292
292
|
)
|
|
293
293
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
else:
|
|
311
|
-
# if you already have the redshift distribution function, you can pass it in.
|
|
312
|
-
# super class will not be initialized anymore,
|
|
313
|
-
# get z_to_luminosity_distance
|
|
314
|
-
self.lookup_table_luminosity_distance(z_min, z_max, directory)
|
|
294
|
+
# initialize the SourceGalaxyPopulationModel mother class
|
|
295
|
+
# for redshift distribution
|
|
296
|
+
# instance attribute sample_source_redshift is initialized here
|
|
297
|
+
super().__init__(
|
|
298
|
+
z_min=z_min,
|
|
299
|
+
z_max=z_max,
|
|
300
|
+
event_type=event_type,
|
|
301
|
+
merger_rate_density=self.gw_param_samplers["merger_rate_density"],
|
|
302
|
+
merger_rate_density_param=self.gw_param_samplers_params[
|
|
303
|
+
"merger_rate_density"
|
|
304
|
+
],
|
|
305
|
+
cosmology=cosmology,
|
|
306
|
+
directory=directory,
|
|
307
|
+
create_new_interpolator=self.create_new_interpolator,
|
|
308
|
+
)
|
|
315
309
|
|
|
316
310
|
# initializing samplers
|
|
317
311
|
# it goes through the setter functions and assign the sampler functions
|
|
@@ -827,6 +821,55 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
827
821
|
mass_1_source, mass_2_source = model.sample(Nsample=size)
|
|
828
822
|
|
|
829
823
|
return (mass_1_source, mass_2_source)
|
|
824
|
+
|
|
825
|
+
def binary_masses_uniform(
|
|
826
|
+
self,
|
|
827
|
+
size,
|
|
828
|
+
m_min=1.0,
|
|
829
|
+
m_max=3.0,
|
|
830
|
+
get_attribute=False,
|
|
831
|
+
param=None,
|
|
832
|
+
):
|
|
833
|
+
"""
|
|
834
|
+
Function to sample source mass1 and mass2 from uniform distribution.
|
|
835
|
+
|
|
836
|
+
Parameters
|
|
837
|
+
----------
|
|
838
|
+
size : `int`
|
|
839
|
+
Number of samples to draw
|
|
840
|
+
m_min : `float`
|
|
841
|
+
Minimum mass of the BNS
|
|
842
|
+
default: 1.0
|
|
843
|
+
m_max : `float`
|
|
844
|
+
Maximum mass of the BNS
|
|
845
|
+
default: 3.0
|
|
846
|
+
get_attribute : `bool`
|
|
847
|
+
If True, return a sampler function with size as the only input where parameters are fixed to the given values.
|
|
848
|
+
param : `dict`
|
|
849
|
+
Allows to pass in above parameters as dict.
|
|
850
|
+
e.g. param = dict(m_min=1.0, m_max=3.0)
|
|
851
|
+
|
|
852
|
+
Returns
|
|
853
|
+
----------
|
|
854
|
+
mass_1_source : `numpy.ndarray` (1D array of floats)
|
|
855
|
+
Array of mass1 in source frame (Msun)
|
|
856
|
+
mass_2_source : `numpy.ndarray` (1D array of floats)
|
|
857
|
+
Array of mass2 in source frame (Msun)
|
|
858
|
+
|
|
859
|
+
Examples
|
|
860
|
+
----------
|
|
861
|
+
>>> from ler.gw_source_population import CBCSourceParameterDistribution
|
|
862
|
+
>>> cbc = CBCSourceParameterDistribution()
|
|
863
|
+
>>> m1_src, m2_src = cbc.binary_masses_uniform(size=1000)
|
|
864
|
+
"""
|
|
865
|
+
|
|
866
|
+
if param:
|
|
867
|
+
m_min = param["m_min"]
|
|
868
|
+
m_max = param["m_max"]
|
|
869
|
+
|
|
870
|
+
if get_attribute:
|
|
871
|
+
return njit(lambda size: (np.random.uniform(m_min, m_max, size), np.random.uniform(m_min, m_max, size)))
|
|
872
|
+
return np.random.uniform(m_min, m_max, size), np.random.uniform(m_min, m_max, size)
|
|
830
873
|
|
|
831
874
|
def binary_masses_BNS_bimodal(
|
|
832
875
|
self,
|
|
@@ -918,13 +961,13 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
918
961
|
# find inverse cdf
|
|
919
962
|
inv_cdf = interpolator_from_pickle(
|
|
920
963
|
param_dict_given=dict(
|
|
921
|
-
w=
|
|
922
|
-
muL=
|
|
923
|
-
sigmaL=
|
|
924
|
-
muR=
|
|
925
|
-
sigmaR=
|
|
926
|
-
mmin=
|
|
927
|
-
mmax=
|
|
964
|
+
w=w,
|
|
965
|
+
muL=muL,
|
|
966
|
+
sigmaL=sigmaL,
|
|
967
|
+
muR=muR,
|
|
968
|
+
sigmaR=sigmaR,
|
|
969
|
+
mmin=mmin,
|
|
970
|
+
mmax=mmax,
|
|
928
971
|
resolution=500,
|
|
929
972
|
),
|
|
930
973
|
directory=self.directory,
|
|
@@ -53,7 +53,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
53
53
|
default: './interpolator_pickle'
|
|
54
54
|
create_new_interpolator : `dict`
|
|
55
55
|
Dictionary of interpolator creation parameters
|
|
56
|
-
default: None/dict(redshift_distribution=dict(create_new=False, resolution=
|
|
56
|
+
default: None/dict(redshift_distribution=dict(create_new=False, resolution=1000), z_to_luminosity_distance=dict(create_new=False, resolution=1000), differential_comoving_volume=dict(create_new=False, resolution=1000))
|
|
57
57
|
|
|
58
58
|
Examples
|
|
59
59
|
----------
|
|
@@ -86,7 +86,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
86
86
|
| | and its parameters |
|
|
87
87
|
+-------------------------------------+----------------------------------+
|
|
88
88
|
|:attr:`~sample_source_redshift` | Function to sample source |
|
|
89
|
-
| | redshifts
|
|
89
|
+
| | redshifts |
|
|
90
90
|
+-------------------------------------+----------------------------------+
|
|
91
91
|
|
|
92
92
|
Instance Methods
|
|
@@ -104,10 +104,10 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
104
104
|
|:meth:`~pdf_z` | Function to compute the pdf |
|
|
105
105
|
| | p(z) |
|
|
106
106
|
+-------------------------------------+----------------------------------+
|
|
107
|
-
|:meth:`~
|
|
107
|
+
|:meth:`~merger_rate_density_detector_frame` |
|
|
108
108
|
+-------------------------------------+----------------------------------+
|
|
109
109
|
| | Function to compute the merger |
|
|
110
|
-
| | rate density (
|
|
110
|
+
| | rate density (detector frame) |
|
|
111
111
|
+-------------------------------------+----------------------------------+
|
|
112
112
|
|:meth:`~create_lookup_table` | Function to create a lookup |
|
|
113
113
|
| | table for the differential |
|
|
@@ -170,7 +170,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
170
170
|
c_n_i = None
|
|
171
171
|
"""``dict`` \n
|
|
172
172
|
c_n_i stands for 'create new interpolator'. Dictionary of interpolator creation parameters. \n
|
|
173
|
-
e.g. dict(redshift_distribution=dict(create_new=False, resolution=
|
|
173
|
+
e.g. dict(redshift_distribution=dict(create_new=False, resolution=1000), z_to_luminosity_distance=dict(create_new=False, resolution=1000), differential_comoving_volume=dict(create_new=False, resolution=1000))
|
|
174
174
|
"""
|
|
175
175
|
|
|
176
176
|
normalization_pdf_z = None
|
|
@@ -207,7 +207,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
207
207
|
self.cosmo = cosmology if cosmology else LambdaCDM(H0=70, Om0=0.3, Ode0=0.7)
|
|
208
208
|
# setting up the interpolator creation parameters
|
|
209
209
|
self.c_n_i = dict(
|
|
210
|
-
redshift_distribution=dict(create_new=False, resolution=
|
|
210
|
+
redshift_distribution=dict(create_new=False, resolution=1000), z_to_luminosity_distance=dict(create_new=False, resolution=1000), differential_comoving_volume=dict(create_new=False, resolution=1000))
|
|
211
211
|
if create_new_interpolator:
|
|
212
212
|
self.c_n_i.update(create_new_interpolator)
|
|
213
213
|
# creating of interpolators for redshift dependent quantities
|
|
@@ -219,21 +219,23 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
219
219
|
# if None is passed, use the default merger_rate_density_param
|
|
220
220
|
if merger_rate_density_param is None and merger_rate_density== "merger_rate_density_bbh_popI_II_oguri2018":
|
|
221
221
|
if self.event_type == "BBH":
|
|
222
|
-
R0 =
|
|
222
|
+
R0 = 23.9 * 1e-9
|
|
223
223
|
elif self.event_type == "BNS":
|
|
224
|
-
R0 =
|
|
224
|
+
R0 = 105.5 * 1e-9
|
|
225
225
|
elif self.event_type == "NSBH":
|
|
226
|
-
R0 =
|
|
226
|
+
R0 = 45.0 * 1e-9
|
|
227
227
|
else:
|
|
228
228
|
raise ValueError("event_type must be one of 'BBH', 'BNS', 'NSBH'")
|
|
229
|
-
|
|
229
|
+
merger_rate_density_param = dict(R0=R0, b2=1.6, b3=2.0, b4=30)
|
|
230
|
+
self.merger_rate_density_param = merger_rate_density_param
|
|
231
|
+
|
|
230
232
|
|
|
231
233
|
# To find the normalization constant of the pdf p(z)
|
|
232
|
-
#
|
|
233
|
-
|
|
234
|
+
# merger_rate_density_detector_frame is njit function and takes array as input but quad integrand function takes only float as input
|
|
235
|
+
merger_rate_density_detector_frame = lambda z: self.merger_rate_density_detector_frame(zs=np.array([z]), param=merger_rate_density_param)[0]
|
|
234
236
|
# this normalization is important to find the correct pdf p(z)
|
|
235
237
|
self.normalization_pdf_z = quad(
|
|
236
|
-
|
|
238
|
+
merger_rate_density_detector_frame,
|
|
237
239
|
z_min,
|
|
238
240
|
z_max
|
|
239
241
|
)[0]
|
|
@@ -242,18 +244,24 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
242
244
|
# create sampler using the pdf p(z)
|
|
243
245
|
resolution = self.c_n_i["redshift_distribution"]["resolution"]
|
|
244
246
|
create_new = self.c_n_i["redshift_distribution"]["create_new"]
|
|
247
|
+
|
|
248
|
+
# if callable(merger_rate_density):
|
|
249
|
+
# merger_rate_density_name = merger_rate_density.__name__
|
|
250
|
+
# else:
|
|
251
|
+
# merger_rate_density_name = merger_rate_density
|
|
252
|
+
|
|
245
253
|
zs_inv_cdf = interpolator_from_pickle(
|
|
246
|
-
param_dict_given= dict(z_min=z_min,
|
|
247
|
-
z_max=z_max,
|
|
254
|
+
param_dict_given= dict(z_min=z_min,
|
|
255
|
+
z_max=z_max,
|
|
248
256
|
cosmology=self.cosmo,
|
|
249
257
|
event_type=event_type,
|
|
250
|
-
merger_rate_density=merger_rate_density,
|
|
251
|
-
merger_rate_density_param=merger_rate_density_param,
|
|
258
|
+
merger_rate_density=str(merger_rate_density),
|
|
259
|
+
merger_rate_density_param=str(merger_rate_density_param),
|
|
252
260
|
resolution=resolution,
|
|
253
261
|
),
|
|
254
262
|
directory=directory,
|
|
255
|
-
sub_directory=merger_rate_density,
|
|
256
|
-
name=merger_rate_density,
|
|
263
|
+
sub_directory="merger_rate_density",
|
|
264
|
+
name="merger_rate_density",
|
|
257
265
|
x = np.linspace(z_min, z_max, resolution),
|
|
258
266
|
pdf_func= lambda z_: self.pdf_z(zs=z_, param=merger_rate_density_param),
|
|
259
267
|
conditioned_y=None,
|
|
@@ -267,7 +275,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
267
275
|
|
|
268
276
|
def pdf_z(self, zs, param=None):
|
|
269
277
|
"""
|
|
270
|
-
Function to compute the pdf p(z). The output is in
|
|
278
|
+
Function to compute the pdf p(z). The output is in detector frame and is normalized.
|
|
271
279
|
|
|
272
280
|
Parameters
|
|
273
281
|
----------
|
|
@@ -291,11 +299,11 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
291
299
|
>>> pdf = cbc.pdf_z(zs=0.1)
|
|
292
300
|
"""
|
|
293
301
|
|
|
294
|
-
return self.
|
|
302
|
+
return self.merger_rate_density_detector_frame(zs=zs,param=param)/self.normalization_pdf_z
|
|
295
303
|
|
|
296
|
-
def
|
|
304
|
+
def merger_rate_density_detector_frame(self, zs, param=None):
|
|
297
305
|
"""
|
|
298
|
-
Function to compute the merger rate density (
|
|
306
|
+
Function to compute the merger rate density (detector frame). The output is in detector frame and is unnormalized.
|
|
299
307
|
|
|
300
308
|
Parameters
|
|
301
309
|
----------
|
|
@@ -310,13 +318,13 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
310
318
|
----------
|
|
311
319
|
rate_density : `numpy.ndarray`
|
|
312
320
|
1D array of floats
|
|
313
|
-
merger rate density (
|
|
321
|
+
merger rate density (detector frame) (Mpc^-3 yr^-1)
|
|
314
322
|
|
|
315
323
|
Examples
|
|
316
324
|
----------
|
|
317
325
|
>>> from ler.gw_source_population import SourceGalaxyPopulationModel
|
|
318
326
|
>>> cbc = SourceGalaxyPopulationModel()
|
|
319
|
-
>>> rate_density = cbc.
|
|
327
|
+
>>> rate_density = cbc.merger_rate_density_detector_frame(zs=0.1)
|
|
320
328
|
"""
|
|
321
329
|
|
|
322
330
|
zs = np.array([zs]).reshape(-1)
|
|
@@ -333,7 +341,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
333
341
|
zs, R0=23.9 * 1e-9, b2=1.6, b3=2.0, b4=30, param=None
|
|
334
342
|
):
|
|
335
343
|
"""
|
|
336
|
-
Function to compute the merger rate density (PopI/PopII). Reference: Oguri et al. (2018). The output is in
|
|
344
|
+
Function to compute the merger rate density (PopI/PopII). Reference: Oguri et al. (2018). The output is in source frame and is unnormalized.
|
|
337
345
|
|
|
338
346
|
Parameters
|
|
339
347
|
----------
|
|
@@ -374,6 +382,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
374
382
|
b3 = param["b3"]
|
|
375
383
|
b4 = param["b4"]
|
|
376
384
|
|
|
385
|
+
#print(f"\nR0: {R0}\n")
|
|
377
386
|
return merger_rate_density_bbh_popI_II_oguri2018(zs=zs, R0=R0, b2=b2, b3=b3, b4=b4)
|
|
378
387
|
|
|
379
388
|
def star_formation_rate_madau_dickinson2014(self,
|
|
@@ -595,7 +604,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
595
604
|
@property
|
|
596
605
|
def sample_source_redshift(self):
|
|
597
606
|
"""
|
|
598
|
-
Function to sample source redshifts (
|
|
607
|
+
Function to sample source redshifts (detector frame) between z_min and z_max from the detector galaxy population
|
|
599
608
|
|
|
600
609
|
Parameters
|
|
601
610
|
----------
|
|
@@ -641,7 +650,7 @@ class CBCSourceRedshiftDistribution(object):
|
|
|
641
650
|
|
|
642
651
|
@merger_rate_density.setter
|
|
643
652
|
def merger_rate_density(self, merger_rate_density):
|
|
644
|
-
error_msg = ValueError(f"merger_rate_density must be one of {self.merger_rate_density_model_list}")
|
|
653
|
+
# error_msg = ValueError(f"merger_rate_density must be one of {self.merger_rate_density_model_list}")
|
|
645
654
|
# check if it is a string
|
|
646
655
|
if isinstance(merger_rate_density, str):
|
|
647
656
|
try:
|
|
@@ -143,7 +143,7 @@ def star_formation_rate_madau_dickinson2014(
|
|
|
143
143
|
return 0.015 * (1 + zs) ** af / (1 + ((1 + zs) / cf) ** bf)
|
|
144
144
|
|
|
145
145
|
|
|
146
|
-
@jit
|
|
146
|
+
# @jit
|
|
147
147
|
def merger_rate_density_bbh_primordial_ken2022(
|
|
148
148
|
zs, cosmology=cosmo, n0=0.044 * 1e-9, t0=13.786885302009708
|
|
149
149
|
):
|
|
@@ -67,7 +67,7 @@ class ImageProperties():
|
|
|
67
67
|
default: "./interpolator_pickle"
|
|
68
68
|
create_new_interpolator : `dict`
|
|
69
69
|
dictionary to create new interpolator pickle files
|
|
70
|
-
default: dict(
|
|
70
|
+
default: dict(luminosity_distance_to_z=dict(create_new=False, resolution=1000))
|
|
71
71
|
|
|
72
72
|
Examples
|
|
73
73
|
--------
|
|
@@ -140,22 +140,22 @@ class ImageProperties():
|
|
|
140
140
|
|
|
141
141
|
# initialize the interpolator's parameters
|
|
142
142
|
self.create_new_interpolator = dict(
|
|
143
|
-
|
|
143
|
+
luminosity_distance_to_z=dict(create_new=False, resolution=1000),
|
|
144
144
|
)
|
|
145
145
|
if isinstance(create_new_interpolator, dict):
|
|
146
146
|
self.create_new_interpolator.update(create_new_interpolator)
|
|
147
147
|
elif create_new_interpolator is True:
|
|
148
148
|
self.create_new_interpolator = dict(
|
|
149
|
-
|
|
149
|
+
luminosity_distance_to_z=dict(create_new=True, resolution=1000)
|
|
150
150
|
)
|
|
151
151
|
|
|
152
|
-
resolution = self.create_new_interpolator["
|
|
153
|
-
create_new = self.create_new_interpolator["
|
|
152
|
+
resolution = self.create_new_interpolator["luminosity_distance_to_z"]["resolution"]
|
|
153
|
+
create_new = self.create_new_interpolator["luminosity_distance_to_z"]["create_new"]
|
|
154
154
|
spline1 = interpolator_from_pickle(
|
|
155
155
|
param_dict_given= dict(z_min=z_min, z_max=z_max, cosmology=self.cosmo, resolution=resolution),
|
|
156
156
|
directory=directory,
|
|
157
|
-
sub_directory="
|
|
158
|
-
name="
|
|
157
|
+
sub_directory="luminosity_distance_to_z",
|
|
158
|
+
name="luminosity_distance_to_z",
|
|
159
159
|
x = np.linspace(z_min, z_max, resolution),
|
|
160
160
|
pdf_func= lambda z_: cosmo.luminosity_distance(z_).value,
|
|
161
161
|
conditioned_y=None,
|
|
@@ -163,7 +163,7 @@ class ImageProperties():
|
|
|
163
163
|
category="function_inverse",
|
|
164
164
|
create_new=create_new,
|
|
165
165
|
)
|
|
166
|
-
self.
|
|
166
|
+
self.luminosity_distance_to_z = njit(lambda z_: cubic_spline_interpolator(z_, spline1[0], spline1[1]))
|
|
167
167
|
|
|
168
168
|
def image_properties(
|
|
169
169
|
self,
|
|
@@ -375,15 +375,13 @@ class ImageProperties():
|
|
|
375
375
|
|
|
376
376
|
# Get the binary parameters
|
|
377
377
|
number_of_lensed_events = len(magnifications)
|
|
378
|
-
mass_1, mass_2,
|
|
378
|
+
mass_1, mass_2, theta_jn, psi, ra, dec, phase, a_1, a_2, tilt_1, tilt_2, phi_12, phi_jl = (
|
|
379
379
|
lensed_param["mass_1"],
|
|
380
380
|
lensed_param["mass_2"],
|
|
381
|
-
lensed_param["luminosity_distance"],
|
|
382
381
|
lensed_param["theta_jn"],
|
|
383
382
|
lensed_param["psi"],
|
|
384
383
|
lensed_param["ra"],
|
|
385
384
|
lensed_param["dec"],
|
|
386
|
-
lensed_param["geocent_time"],
|
|
387
385
|
lensed_param["phase"],
|
|
388
386
|
np.zeros(size),
|
|
389
387
|
np.zeros(size),
|
|
@@ -423,24 +421,45 @@ class ImageProperties():
|
|
|
423
421
|
np.ones((number_of_lensed_events, n_max_images)) * np.nan
|
|
424
422
|
)
|
|
425
423
|
|
|
426
|
-
|
|
427
|
-
|
|
428
424
|
# for updating the lensed_param
|
|
429
|
-
|
|
430
|
-
|
|
425
|
+
if "luminosity_distance" in lensed_param:
|
|
426
|
+
luminosity_distance = lensed_param["luminosity_distance"]
|
|
427
|
+
lensed_param["effective_luminosity_distance"] = np.ones((number_of_lensed_events, n_max_images)) * np.nan
|
|
428
|
+
dl_eff_present = False
|
|
429
|
+
elif "effective_luminosity_distance" in lensed_param:
|
|
430
|
+
dl_eff = lensed_param["effective_luminosity_distance"]
|
|
431
|
+
dl_eff_present = True
|
|
432
|
+
else:
|
|
433
|
+
raise ValueError("luminosity_distance or effective_luminosity_distance not given")
|
|
434
|
+
|
|
435
|
+
if "geocent_time" in lensed_param:
|
|
436
|
+
geocent_time = lensed_param["geocent_time"]
|
|
437
|
+
lensed_param["effective_geocent_time"] = np.ones((number_of_lensed_events, n_max_images)) * np.nan
|
|
438
|
+
time_eff_present = False
|
|
439
|
+
elif "effective_geocent_time" in lensed_param:
|
|
440
|
+
time_eff = lensed_param["effective_geocent_time"]
|
|
441
|
+
time_eff_present = True
|
|
442
|
+
else:
|
|
443
|
+
raise ValueError("geocent_time or effective_geocent_time not given")
|
|
431
444
|
|
|
432
445
|
# Get the optimal signal to noise ratios for each image
|
|
433
446
|
# iterate over the image type (column)
|
|
434
447
|
for i in range(n_max_images):
|
|
435
448
|
|
|
436
449
|
# get the effective time for each image type
|
|
437
|
-
|
|
450
|
+
if not time_eff_present:
|
|
451
|
+
effective_geocent_time = geocent_time + time_delays[:, i]
|
|
452
|
+
else:
|
|
453
|
+
effective_geocent_time = time_eff[:, i]
|
|
438
454
|
# choose only the events that are within the time range and also not nan
|
|
439
455
|
idx = (effective_geocent_time <= self.geocent_time_max) & (effective_geocent_time >= self.geocent_time_min)
|
|
440
456
|
# get the effective luminosity distance for each image type
|
|
441
|
-
|
|
442
|
-
np.
|
|
443
|
-
|
|
457
|
+
if not dl_eff_present:
|
|
458
|
+
effective_luminosity_distance = luminosity_distance / np.sqrt(
|
|
459
|
+
np.abs(magnifications[:, i])
|
|
460
|
+
)
|
|
461
|
+
else:
|
|
462
|
+
effective_luminosity_distance = dl_eff[:, i]
|
|
444
463
|
|
|
445
464
|
# check for nan values
|
|
446
465
|
idx = idx & ~np.isnan(effective_luminosity_distance) & ~np.isnan(effective_geocent_time)
|
|
@@ -473,7 +492,8 @@ class ImageProperties():
|
|
|
473
492
|
|
|
474
493
|
if list_of_detectors:
|
|
475
494
|
for detector in list_of_detectors:
|
|
476
|
-
|
|
495
|
+
if detector in optimal_snr:
|
|
496
|
+
result_dict[detector][idx, i] = optimal_snr[detector]
|
|
477
497
|
|
|
478
498
|
elif pdet_calculator:
|
|
479
499
|
pdet = pdet_calculator(
|
|
@@ -499,13 +519,16 @@ class ImageProperties():
|
|
|
499
519
|
|
|
500
520
|
if list_of_detectors:
|
|
501
521
|
for detector in list_of_detectors:
|
|
502
|
-
|
|
522
|
+
if detector in pdet:
|
|
523
|
+
result_dict[detector][idx, i] = pdet[detector]
|
|
503
524
|
|
|
504
525
|
|
|
505
526
|
lensed_param["effective_luminosity_distance"][:, i] = effective_luminosity_distance
|
|
506
527
|
lensed_param["effective_geocent_time"][:, i] = effective_geocent_time
|
|
507
528
|
|
|
508
|
-
|
|
509
|
-
|
|
529
|
+
if dl_eff_present:
|
|
530
|
+
del lensed_param["effective_luminosity_distance"]
|
|
531
|
+
if time_eff_present:
|
|
532
|
+
del lensed_param["effective_geocent_time"]
|
|
510
533
|
|
|
511
534
|
return result_dict, lensed_param
|
|
@@ -151,17 +151,32 @@ def solve_lens_equation(lens_parameters):
|
|
|
151
151
|
# try:
|
|
152
152
|
x_source, y_source = pointpats.random.poisson(caustic_double, size=1)
|
|
153
153
|
# Solve the lens equation
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
154
|
+
try: # this to catch this error: "ValueError: Signs are not different"
|
|
155
|
+
(
|
|
156
|
+
x0_image_position,
|
|
157
|
+
x1_image_position,
|
|
158
|
+
) = lens_eq_solver.image_position_from_source(
|
|
159
|
+
sourcePos_x=x_source,
|
|
160
|
+
sourcePos_y=y_source,
|
|
161
|
+
kwargs_lens=kwargs_lens,
|
|
162
|
+
solver="analytical",
|
|
163
|
+
magnification_limit=1.0 / 100.0,
|
|
164
|
+
arrival_time_sort=True,
|
|
165
|
+
)
|
|
166
|
+
except:
|
|
167
|
+
return (
|
|
168
|
+
np.nan,
|
|
169
|
+
np.nan,
|
|
170
|
+
np.array([np.nan,np.nan]),
|
|
171
|
+
np.array([np.nan,np.nan]),
|
|
172
|
+
np.array([np.nan,np.nan]),
|
|
173
|
+
np.array([np.nan,np.nan]),
|
|
174
|
+
0,
|
|
175
|
+
np.array([np.nan,np.nan]),
|
|
176
|
+
np.array([np.nan,np.nan]),
|
|
177
|
+
iteration,
|
|
178
|
+
)
|
|
179
|
+
|
|
165
180
|
nImages = len(x0_image_position) # shows how many images
|
|
166
181
|
if nImages >= n_min_images:
|
|
167
182
|
strongly_lensed = True
|
|
@@ -228,6 +228,7 @@ def lens_redshift_SDSS_catalogue(zs, splineDc, splineDcInv, u, cdf):
|
|
|
228
228
|
splineDcInv: `list`
|
|
229
229
|
List of spline coefficients for the inverse of comoving distance and redshifts
|
|
230
230
|
u: `numpy.ndarray` (1D array of float of size=size)
|
|
231
|
+
corresponding x values wrt to the cdf values
|
|
231
232
|
e.g. u = np.linspace(0, 1, 500)
|
|
232
233
|
cdf: `numpy.ndarray` (1D array of float of size=size)
|
|
233
234
|
Cumulative distribution function of the lens redshift distribution between 0 and 1
|
|
@@ -233,31 +233,31 @@ class LensGalaxyParameterDistribution(CBCSourceParameterDistribution, ImagePrope
|
|
|
233
233
|
self.directory = directory
|
|
234
234
|
# initialize the interpolator's parameters
|
|
235
235
|
self.create_new_interpolator = dict(
|
|
236
|
-
redshift_distribution=dict(create_new=False, resolution=
|
|
237
|
-
z_to_luminosity_distance=dict(create_new=False, resolution=
|
|
238
|
-
velocity_dispersion=dict(create_new=False, resolution=
|
|
239
|
-
axis_ratio=dict(create_new=False, resolution=
|
|
240
|
-
optical_depth=dict(create_new=False, resolution=
|
|
241
|
-
z_to_Dc=dict(create_new=False, resolution=
|
|
242
|
-
Dc_to_z=dict(create_new=False, resolution=
|
|
243
|
-
angular_diameter_distance=dict(create_new=False, resolution=
|
|
244
|
-
differential_comoving_volume=dict(create_new=False, resolution=
|
|
245
|
-
|
|
236
|
+
redshift_distribution=dict(create_new=False, resolution=1000),
|
|
237
|
+
z_to_luminosity_distance=dict(create_new=False, resolution=1000),
|
|
238
|
+
velocity_dispersion=dict(create_new=False, resolution=1000),
|
|
239
|
+
axis_ratio=dict(create_new=False, resolution=1000),
|
|
240
|
+
optical_depth=dict(create_new=False, resolution=200),
|
|
241
|
+
z_to_Dc=dict(create_new=False, resolution=1000),
|
|
242
|
+
Dc_to_z=dict(create_new=False, resolution=1000),
|
|
243
|
+
angular_diameter_distance=dict(create_new=False, resolution=1000),
|
|
244
|
+
differential_comoving_volume=dict(create_new=False, resolution=1000),
|
|
245
|
+
luminosity_distance_to_z=dict(create_new=False, resolution=1000),
|
|
246
246
|
)
|
|
247
247
|
if isinstance(create_new_interpolator, dict):
|
|
248
248
|
self.create_new_interpolator.update(create_new_interpolator)
|
|
249
249
|
elif create_new_interpolator is True:
|
|
250
250
|
self.create_new_interpolator = dict(
|
|
251
|
-
redshift_distribution=dict(create_new=True, resolution=
|
|
252
|
-
z_to_luminosity_distance=dict(create_new=True, resolution=
|
|
253
|
-
velocity_dispersion=dict(create_new=True, resolution=
|
|
254
|
-
axis_ratio=dict(create_new=True, resolution=
|
|
255
|
-
optical_depth=dict(create_new=True, resolution=
|
|
256
|
-
z_to_Dc=dict(create_new=True, resolution=
|
|
257
|
-
Dc_to_z=dict(create_new=True, resolution=
|
|
258
|
-
angular_diameter_distance=dict(create_new=True, resolution=
|
|
259
|
-
differential_comoving_volume=dict(create_new=True, resolution=
|
|
260
|
-
|
|
251
|
+
redshift_distribution=dict(create_new=True, resolution=1000),
|
|
252
|
+
z_to_luminosity_distance=dict(create_new=True, resolution=1000),
|
|
253
|
+
velocity_dispersion=dict(create_new=True, resolution=1000),
|
|
254
|
+
axis_ratio=dict(create_new=True, resolution=1000),
|
|
255
|
+
optical_depth=dict(create_new=True, resolution=200),
|
|
256
|
+
z_to_Dc=dict(create_new=True, resolution=1000),
|
|
257
|
+
Dc_to_z=dict(create_new=True, resolution=1000),
|
|
258
|
+
angular_diameter_distance=dict(create_new=True, resolution=1000),
|
|
259
|
+
differential_comoving_volume=dict(create_new=True, resolution=1000),
|
|
260
|
+
luminosity_distance_to_z=dict(create_new=True, resolution=1000),
|
|
261
261
|
)
|
|
262
262
|
|
|
263
263
|
# dealing with prior functions and categorization
|
|
@@ -294,7 +294,7 @@ class LensGalaxyParameterDistribution(CBCSourceParameterDistribution, ImagePrope
|
|
|
294
294
|
# To find the normalization constant of the pdf p(z)
|
|
295
295
|
# this under the assumption that the event is strongly lensed
|
|
296
296
|
# Define the merger-rate density function
|
|
297
|
-
pdf_unnormalized_ = lambda z: self.
|
|
297
|
+
pdf_unnormalized_ = lambda z: self.merger_rate_density_detector_frame(np.array([z]), param=self.merger_rate_density_param) * self.strong_lensing_optical_depth(np.array([z]))
|
|
298
298
|
pdf_unnormalized = lambda z: pdf_unnormalized_(z)[0]
|
|
299
299
|
|
|
300
300
|
self.normalization_pdf_z_lensed = quad(
|
|
@@ -601,7 +601,7 @@ class LensGalaxyParameterDistribution(CBCSourceParameterDistribution, ImagePrope
|
|
|
601
601
|
size=size)
|
|
602
602
|
|
|
603
603
|
# sample gravitional waves source parameter
|
|
604
|
-
param = dict(zs=
|
|
604
|
+
param = dict(zs=lens_parameters["zs"])
|
|
605
605
|
if samplers_params["source_parameters"]:
|
|
606
606
|
param.update(self.sample_gw_parameters(size=size))
|
|
607
607
|
gw_param = self.sample_source_parameters(size=size, param=param)
|
|
@@ -1173,7 +1173,7 @@ class LensGalaxyParameterDistribution(CBCSourceParameterDistribution, ImagePrope
|
|
|
1173
1173
|
"""
|
|
1174
1174
|
|
|
1175
1175
|
self._available_lens_functions = dict(
|
|
1176
|
-
strong_lensing_condition=["rjs_with_cross_section_SIE", "
|
|
1176
|
+
strong_lensing_condition=["rjs_with_cross_section_SIE", "rjs_with_cross_section_SIS"],
|
|
1177
1177
|
optical_depth=["SIS", "optical_depth_SIS_haris","optical_depth_SIS_hemanta", "SIE", "optical_depth_SIE_hemanta"],
|
|
1178
1178
|
param_sampler_type=["sample_all_routine"],
|
|
1179
1179
|
)
|