ler 0.3.6__py3-none-any.whl → 0.3.8__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 +56 -7
- 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 +41 -19
- 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 +18 -17
- ler/rates/gwrates.py +4 -1
- ler/rates/ler.py +198 -58
- ler/utils/utils.py +20 -8
- {ler-0.3.6.dist-info → ler-0.3.8.dist-info}/METADATA +2 -2
- ler-0.3.8.dist-info/RECORD +24 -0
- {ler-0.3.6.dist-info → ler-0.3.8.dist-info}/WHEEL +1 -1
- ler-0.3.6.dist-info/RECORD +0 -24
- {ler-0.3.6.dist-info → ler-0.3.8.dist-info}/LICENSE +0 -0
- {ler-0.3.6.dist-info → ler-0.3.8.dist-info}/top_level.txt +0 -0
ler/__init__.py
CHANGED
|
@@ -827,6 +827,55 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
827
827
|
mass_1_source, mass_2_source = model.sample(Nsample=size)
|
|
828
828
|
|
|
829
829
|
return (mass_1_source, mass_2_source)
|
|
830
|
+
|
|
831
|
+
def binary_masses_uniform(
|
|
832
|
+
self,
|
|
833
|
+
size,
|
|
834
|
+
m_min=1.0,
|
|
835
|
+
m_max=3.0,
|
|
836
|
+
get_attribute=False,
|
|
837
|
+
param=None,
|
|
838
|
+
):
|
|
839
|
+
"""
|
|
840
|
+
Function to sample source mass1 and mass2 from uniform distribution.
|
|
841
|
+
|
|
842
|
+
Parameters
|
|
843
|
+
----------
|
|
844
|
+
size : `int`
|
|
845
|
+
Number of samples to draw
|
|
846
|
+
m_min : `float`
|
|
847
|
+
Minimum mass of the BNS
|
|
848
|
+
default: 1.0
|
|
849
|
+
m_max : `float`
|
|
850
|
+
Maximum mass of the BNS
|
|
851
|
+
default: 3.0
|
|
852
|
+
get_attribute : `bool`
|
|
853
|
+
If True, return a sampler function with size as the only input where parameters are fixed to the given values.
|
|
854
|
+
param : `dict`
|
|
855
|
+
Allows to pass in above parameters as dict.
|
|
856
|
+
e.g. param = dict(m_min=1.0, m_max=3.0)
|
|
857
|
+
|
|
858
|
+
Returns
|
|
859
|
+
----------
|
|
860
|
+
mass_1_source : `numpy.ndarray` (1D array of floats)
|
|
861
|
+
Array of mass1 in source frame (Msun)
|
|
862
|
+
mass_2_source : `numpy.ndarray` (1D array of floats)
|
|
863
|
+
Array of mass2 in source frame (Msun)
|
|
864
|
+
|
|
865
|
+
Examples
|
|
866
|
+
----------
|
|
867
|
+
>>> from ler.gw_source_population import CBCSourceParameterDistribution
|
|
868
|
+
>>> cbc = CBCSourceParameterDistribution()
|
|
869
|
+
>>> m1_src, m2_src = cbc.binary_masses_uniform(size=1000)
|
|
870
|
+
"""
|
|
871
|
+
|
|
872
|
+
if param:
|
|
873
|
+
m_min = param["m_min"]
|
|
874
|
+
m_max = param["m_max"]
|
|
875
|
+
|
|
876
|
+
if get_attribute:
|
|
877
|
+
return njit(lambda size: (np.random.uniform(m_min, m_max, size), np.random.uniform(m_min, m_max, size)))
|
|
878
|
+
return np.random.uniform(m_min, m_max, size), np.random.uniform(m_min, m_max, size)
|
|
830
879
|
|
|
831
880
|
def binary_masses_BNS_bimodal(
|
|
832
881
|
self,
|
|
@@ -918,13 +967,13 @@ class CBCSourceParameterDistribution(CBCSourceRedshiftDistribution):
|
|
|
918
967
|
# find inverse cdf
|
|
919
968
|
inv_cdf = interpolator_from_pickle(
|
|
920
969
|
param_dict_given=dict(
|
|
921
|
-
w=
|
|
922
|
-
muL=
|
|
923
|
-
sigmaL=
|
|
924
|
-
muR=
|
|
925
|
-
sigmaR=
|
|
926
|
-
mmin=
|
|
927
|
-
mmax=
|
|
970
|
+
w=w,
|
|
971
|
+
muL=muL,
|
|
972
|
+
sigmaL=sigmaL,
|
|
973
|
+
muR=muR,
|
|
974
|
+
sigmaR=sigmaR,
|
|
975
|
+
mmin=mmin,
|
|
976
|
+
mmax=mmax,
|
|
928
977
|
resolution=500,
|
|
929
978
|
),
|
|
930
979
|
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(Dl_to_z=dict(create_new=False, resolution=
|
|
70
|
+
default: dict(Dl_to_z=dict(create_new=False, resolution=1000))
|
|
71
71
|
|
|
72
72
|
Examples
|
|
73
73
|
--------
|
|
@@ -140,13 +140,13 @@ class ImageProperties():
|
|
|
140
140
|
|
|
141
141
|
# initialize the interpolator's parameters
|
|
142
142
|
self.create_new_interpolator = dict(
|
|
143
|
-
Dl_to_z=dict(create_new=False, resolution=
|
|
143
|
+
Dl_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
|
-
Dl_to_z=dict(create_new=True, resolution=
|
|
149
|
+
Dl_to_z=dict(create_new=True, resolution=1000)
|
|
150
150
|
)
|
|
151
151
|
|
|
152
152
|
resolution = self.create_new_interpolator["Dl_to_z"]["resolution"]
|
|
@@ -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(
|
|
@@ -494,19 +514,21 @@ class ImageProperties():
|
|
|
494
514
|
phi_12=phi_12[idx],
|
|
495
515
|
phi_jl=phi_jl[idx],
|
|
496
516
|
),
|
|
497
|
-
output_jsonfile=False,
|
|
498
517
|
)
|
|
499
518
|
result_dict["pdet_net"][idx, i] = pdet["pdet_net"]
|
|
500
519
|
|
|
501
520
|
if list_of_detectors:
|
|
502
521
|
for detector in list_of_detectors:
|
|
503
|
-
|
|
522
|
+
if detector in pdet:
|
|
523
|
+
result_dict[detector][idx, i] = pdet[detector]
|
|
504
524
|
|
|
505
525
|
|
|
506
526
|
lensed_param["effective_luminosity_distance"][:, i] = effective_luminosity_distance
|
|
507
527
|
lensed_param["effective_geocent_time"][:, i] = effective_geocent_time
|
|
508
528
|
|
|
509
|
-
|
|
510
|
-
|
|
529
|
+
if dl_eff_present:
|
|
530
|
+
del lensed_param["effective_luminosity_distance"]
|
|
531
|
+
if time_eff_present:
|
|
532
|
+
del lensed_param["effective_geocent_time"]
|
|
511
533
|
|
|
512
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
|
-
Dl_to_z=dict(create_new=False, resolution=
|
|
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=1000),
|
|
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
|
+
Dl_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
|
-
Dl_to_z=dict(create_new=True, resolution=
|
|
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=1000),
|
|
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
|
+
Dl_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
|
)
|
|
@@ -186,25 +186,25 @@ class OpticalDepth():
|
|
|
186
186
|
|
|
187
187
|
self.directory = directory
|
|
188
188
|
self.c_n_i = dict(
|
|
189
|
-
velocity_dispersion=dict(create_new=False, resolution=
|
|
190
|
-
axis_ratio=dict(create_new=False, resolution=
|
|
191
|
-
optical_depth=dict(create_new=False, resolution=
|
|
192
|
-
z_to_Dc=dict(create_new=False, resolution=
|
|
193
|
-
Dc_to_z=dict(create_new=False, resolution=
|
|
194
|
-
angular_diameter_distance=dict(create_new=False, resolution=
|
|
195
|
-
differential_comoving_volume=dict(create_new=False, resolution=
|
|
189
|
+
velocity_dispersion=dict(create_new=False, resolution=1000),
|
|
190
|
+
axis_ratio=dict(create_new=False, resolution=1000),
|
|
191
|
+
optical_depth=dict(create_new=False, resolution=1000),
|
|
192
|
+
z_to_Dc=dict(create_new=False, resolution=1000),
|
|
193
|
+
Dc_to_z=dict(create_new=False, resolution=1000),
|
|
194
|
+
angular_diameter_distance=dict(create_new=False, resolution=1000),
|
|
195
|
+
differential_comoving_volume=dict(create_new=False, resolution=1000),
|
|
196
196
|
)
|
|
197
197
|
if isinstance(create_new_interpolator, dict):
|
|
198
198
|
self.c_n_i.update(create_new_interpolator)
|
|
199
199
|
elif create_new_interpolator is True:
|
|
200
200
|
self.c_n_i = dict(
|
|
201
|
-
velocity_dispersion=dict(create_new=True, resolution=
|
|
202
|
-
axis_ratio=dict(create_new=True, resolution=
|
|
203
|
-
optical_depth=dict(create_new=True, resolution=
|
|
204
|
-
z_to_Dc=dict(create_new=True, resolution=
|
|
205
|
-
Dc_to_z=dict(create_new=True, resolution=
|
|
206
|
-
angular_diameter_distance=dict(create_new=True, resolution=
|
|
207
|
-
differential_comoving_volume=dict(create_new=True, resolution=
|
|
201
|
+
velocity_dispersion=dict(create_new=True, resolution=1000),
|
|
202
|
+
axis_ratio=dict(create_new=True, resolution=1000),
|
|
203
|
+
optical_depth=dict(create_new=True, resolution=1000),
|
|
204
|
+
z_to_Dc=dict(create_new=True, resolution=1000),
|
|
205
|
+
Dc_to_z=dict(create_new=True, resolution=1000),
|
|
206
|
+
angular_diameter_distance=dict(create_new=True, resolution=1000),
|
|
207
|
+
differential_comoving_volume=dict(create_new=True, resolution=1000),
|
|
208
208
|
)
|
|
209
209
|
|
|
210
210
|
vd_name = self.sampler_priors["velocity_dispersion"] # velocity dispersion sampler name
|
|
@@ -237,8 +237,8 @@ class OpticalDepth():
|
|
|
237
237
|
self.vd_min = self.sampler_priors_params['velocity_dispersion']['vd_min']
|
|
238
238
|
self.vd_max = self.sampler_priors_params['velocity_dispersion']['vd_max']
|
|
239
239
|
except:
|
|
240
|
-
self.vd_min =
|
|
241
|
-
self.vd_max =
|
|
240
|
+
self.vd_min = 10.
|
|
241
|
+
self.vd_max = 350.
|
|
242
242
|
|
|
243
243
|
# generating inverse cdf interpolator for velocity dispersion
|
|
244
244
|
param_dict_given_ = dict(z_min=self.z_min, z_max=self.z_max, vd_min=self.vd_min, vd_max=self.vd_max, cosmology=self.cosmo, name=vd_name, resolution=self.c_n_i["velocity_dispersion"]["resolution"])
|
|
@@ -966,7 +966,8 @@ class OpticalDepth():
|
|
|
966
966
|
Function to list all available axis ratio sampler.
|
|
967
967
|
"""
|
|
968
968
|
self._available_axis_ratio_list_and_its_params = dict(
|
|
969
|
-
axis_ratio_rayleigh=
|
|
969
|
+
axis_ratio_rayleigh=dict(q_min=0.2, q_max=1.0),
|
|
970
|
+
axis_ratio_padilla_strauss=dict(q_min=0.2, q_max=1.0),
|
|
970
971
|
axis_ratio_SIS=None,
|
|
971
972
|
)
|
|
972
973
|
|
ler/rates/gwrates.py
CHANGED
|
@@ -915,7 +915,10 @@ class GWRATES(CBCSourceParameterDistribution):
|
|
|
915
915
|
# save meta data
|
|
916
916
|
meta_data = dict(events_total=[events_total], detectable_events=[float(n)], total_rate=[total_rate])
|
|
917
917
|
if os.path.exists(meta_data_path):
|
|
918
|
-
|
|
918
|
+
try:
|
|
919
|
+
append_json(file_name=meta_data_path, new_dictionary=meta_data, replace=False)
|
|
920
|
+
except:
|
|
921
|
+
append_json(file_name=meta_data_path, new_dictionary=meta_data, replace=True)
|
|
919
922
|
else:
|
|
920
923
|
append_json(file_name=meta_data_path, new_dictionary=meta_data, replace=True)
|
|
921
924
|
|
ler/rates/ler.py
CHANGED
|
@@ -300,7 +300,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
300
300
|
print("npool = ", self.npool)
|
|
301
301
|
print("z_min = ", self.z_min)
|
|
302
302
|
print("z_max = ", self.z_max)
|
|
303
|
-
print("event_type =
|
|
303
|
+
print(f"event_type = '{self.event_type}'")
|
|
304
304
|
print("size = ", self.size)
|
|
305
305
|
print("batch_size = ", self.batch_size)
|
|
306
306
|
print("cosmology = ", self.cosmo)
|
|
@@ -320,7 +320,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
320
320
|
print("create_new_interpolator=", self.gw_param_sampler_dict["create_new_interpolator"])
|
|
321
321
|
|
|
322
322
|
print("\n LeR also takes LensGalaxyParameterDistribution params as kwargs, as follows:")
|
|
323
|
-
print("lens_type =
|
|
323
|
+
print(f"lens_type = '{self.gw_param_sampler_dict['lens_type']}'")
|
|
324
324
|
print("lens_functions = ", self.gw_param_sampler_dict["lens_functions"])
|
|
325
325
|
print("lens_priors = ", self.gw_param_sampler_dict["lens_priors"])
|
|
326
326
|
print("lens_priors_params = ", self.gw_param_sampler_dict["lens_priors_params"])
|
|
@@ -341,9 +341,9 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
341
341
|
print("mtot_resolution = ", self.snr_calculator_dict["mtot_resolution"])
|
|
342
342
|
print("ratio_resolution = ", self.snr_calculator_dict["ratio_resolution"])
|
|
343
343
|
print("sampling_frequency = ", self.snr_calculator_dict["sampling_frequency"])
|
|
344
|
-
print("waveform_approximant =
|
|
344
|
+
print(f"waveform_approximant = '{self.snr_calculator_dict['waveform_approximant']}'")
|
|
345
345
|
print("minimum_frequency = ", self.snr_calculator_dict["minimum_frequency"])
|
|
346
|
-
print("snr_type =
|
|
346
|
+
print(f"snr_type = '{self.snr_calculator_dict['snr_type']}'")
|
|
347
347
|
print("psds = ", self.snr_calculator_dict["psds"])
|
|
348
348
|
print("ifos = ", self.snr_calculator_dict["ifos"])
|
|
349
349
|
print("interpolator_dir = ", self.snr_calculator_dict["interpolator_dir"])
|
|
@@ -354,54 +354,54 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
354
354
|
del self.gwsnr
|
|
355
355
|
|
|
356
356
|
print("\n For reference, the chosen source parameters are listed below:")
|
|
357
|
-
print("merger_rate_density =
|
|
357
|
+
print(f"merger_rate_density = '{self.gw_param_samplers['merger_rate_density']}'")
|
|
358
358
|
print("merger_rate_density_params = ", self.gw_param_samplers_params["merger_rate_density"])
|
|
359
|
-
print("source_frame_masses =
|
|
359
|
+
print(f"source_frame_masses = '{self.gw_param_samplers['source_frame_masses']}'")
|
|
360
360
|
print("source_frame_masses_params = ", self.gw_param_samplers_params["source_frame_masses"])
|
|
361
|
-
print("geocent_time =
|
|
361
|
+
print(f"geocent_time = '{self.gw_param_samplers['geocent_time']}'")
|
|
362
362
|
print("geocent_time_params = ", self.gw_param_samplers_params["geocent_time"])
|
|
363
|
-
print("ra =
|
|
363
|
+
print(f"ra = '{self.gw_param_samplers['ra']}'")
|
|
364
364
|
print("ra_params = ", self.gw_param_samplers_params["ra"])
|
|
365
|
-
print("dec =
|
|
365
|
+
print(f"dec = '{self.gw_param_samplers['dec']}'")
|
|
366
366
|
print("dec_params = ", self.gw_param_samplers_params["dec"])
|
|
367
|
-
print("phase =
|
|
367
|
+
print(f"phase = '{self.gw_param_samplers['phase']}'")
|
|
368
368
|
print("phase_params = ", self.gw_param_samplers_params["phase"])
|
|
369
|
-
print("psi =
|
|
369
|
+
print(f"psi = '{self.gw_param_samplers['psi']}'")
|
|
370
370
|
print("psi_params = ", self.gw_param_samplers_params["psi"])
|
|
371
|
-
print("theta_jn =
|
|
371
|
+
print(f"theta_jn = '{self.gw_param_samplers['theta_jn']}'")
|
|
372
372
|
print("theta_jn_params = ", self.gw_param_samplers_params["theta_jn"])
|
|
373
373
|
if self.spin_zero==False:
|
|
374
|
-
print("a_1 =
|
|
374
|
+
print(f"a_1 = '{self.gw_param_samplers['a_1']}'")
|
|
375
375
|
print("a_1_params = ", self.gw_param_samplers_params["a_1"])
|
|
376
|
-
print("a_2 =
|
|
376
|
+
print(f"a_2 = '{self.gw_param_samplers['a_2']}'")
|
|
377
377
|
print("a_2_params = ", self.gw_param_samplers_params["a_2"])
|
|
378
378
|
if self.spin_precession==True:
|
|
379
|
-
print("tilt_1 =
|
|
379
|
+
print(f"tilt_1 = '{self.gw_param_samplers['tilt_1']}'")
|
|
380
380
|
print("tilt_1_params = ", self.gw_param_samplers_params["tilt_1"])
|
|
381
|
-
print("tilt_2 =
|
|
381
|
+
print(f"tilt_2 = '{self.gw_param_samplers['tilt_2']}'")
|
|
382
382
|
print("tilt_2_params = ", self.gw_param_samplers_params["tilt_2"])
|
|
383
|
-
print("phi_12 =
|
|
383
|
+
print(f"phi_12 = '{self.gw_param_samplers['phi_12']}'")
|
|
384
384
|
print("phi_12_params = ", self.gw_param_samplers_params["phi_12"])
|
|
385
|
-
print("phi_jl =
|
|
385
|
+
print(f"phi_jl = '{self.gw_param_samplers['phi_jl']}'")
|
|
386
386
|
print("phi_jl_params = ", self.gw_param_samplers_params["phi_jl"])
|
|
387
387
|
|
|
388
388
|
print("\n For reference, the chosen lens related parameters and functions are listed below:")
|
|
389
|
-
print("lens_redshift =
|
|
389
|
+
print(f"lens_redshift = '{self.lens_param_samplers['lens_redshift']}'")
|
|
390
390
|
print("lens_redshift_params = ", self.lens_param_samplers_params["lens_redshift"])
|
|
391
|
-
print("velocity_dispersion =
|
|
391
|
+
print(f"velocity_dispersion = '{self.lens_param_samplers['velocity_dispersion']}'")
|
|
392
392
|
print("velocity_dispersion_params = ", self.lens_param_samplers_params["velocity_dispersion"])
|
|
393
|
-
print("axis_ratio =
|
|
393
|
+
print(f"axis_ratio = '{self.lens_param_samplers['axis_ratio']}'")
|
|
394
394
|
print("axis_ratio_params = ", self.lens_param_samplers_params["axis_ratio"])
|
|
395
|
-
print("axis_rotation_angle =
|
|
395
|
+
print(f"axis_rotation_angle = '{self.lens_param_samplers['axis_rotation_angle']}'")
|
|
396
396
|
print("axis_rotation_angle_params = ", self.lens_param_samplers_params["axis_rotation_angle"])
|
|
397
|
-
print("shear =
|
|
397
|
+
print(f"shear = '{self.lens_param_samplers['shear']}'")
|
|
398
398
|
print("shear_params = ", self.lens_param_samplers_params["shear"])
|
|
399
|
-
print("mass_density_spectral_index =
|
|
399
|
+
print(f"mass_density_spectral_index = '{self.lens_param_samplers['mass_density_spectral_index']}'")
|
|
400
400
|
print("mass_density_spectral_index_params = ", self.lens_param_samplers_params["mass_density_spectral_index"])
|
|
401
401
|
# lens functions
|
|
402
402
|
print("Lens functions:")
|
|
403
|
-
print("strong_lensing_condition =
|
|
404
|
-
print("optical_depth =
|
|
403
|
+
print(f"strong_lensing_condition = '{self.lens_functions['strong_lensing_condition']}'")
|
|
404
|
+
print(f"optical_depth = '{self.lens_functions['optical_depth']}'")
|
|
405
405
|
|
|
406
406
|
@property
|
|
407
407
|
def snr(self):
|
|
@@ -612,7 +612,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
612
612
|
ifos=None,
|
|
613
613
|
interpolator_dir=self.interpolator_directory,
|
|
614
614
|
create_new_interpolator=False,
|
|
615
|
-
gwsnr_verbose=
|
|
615
|
+
gwsnr_verbose=False,
|
|
616
616
|
multiprocessing_verbose=True,
|
|
617
617
|
mtot_cut=True,
|
|
618
618
|
)
|
|
@@ -756,7 +756,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
756
756
|
if self.dict_buffer:
|
|
757
757
|
unlensed_param = self.dict_buffer.copy()
|
|
758
758
|
# store all params in json file
|
|
759
|
-
print(f"saving all unlensed_params in {output_path}
|
|
759
|
+
print(f"saving all unlensed_params in {output_path} ")
|
|
760
760
|
append_json(output_path, unlensed_param, replace=True)
|
|
761
761
|
else:
|
|
762
762
|
print("unlensed_params already sampled.")
|
|
@@ -821,7 +821,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
821
821
|
output_jsonfile=None,
|
|
822
822
|
detectability_condition="step_function",
|
|
823
823
|
snr_recalculation=False,
|
|
824
|
-
|
|
824
|
+
snr_threshold_recalculation=5.5,
|
|
825
825
|
):
|
|
826
826
|
"""
|
|
827
827
|
Function to calculate the unlensed rate. This function also stores the parameters of the detectable events in json file.
|
|
@@ -842,9 +842,9 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
842
842
|
default detectability_condition = 'step_function'.
|
|
843
843
|
other options are 'pdet'.
|
|
844
844
|
snr_recalculation : `bool`
|
|
845
|
-
if True, the SNR of centain events (snr>
|
|
845
|
+
if True, the SNR of centain events (snr>snr_threshold_recalculation)will be recalculate with 'inner product'. This is useful when the snr is calculated with 'ann' method.
|
|
846
846
|
default snr_recalculation = False.
|
|
847
|
-
|
|
847
|
+
snr_threshold_recalculation : `float`
|
|
848
848
|
threshold for recalculation of detection signal to noise ratio.
|
|
849
849
|
|
|
850
850
|
Returns
|
|
@@ -885,7 +885,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
885
885
|
if snr_recalculation:
|
|
886
886
|
# select only above centain snr threshold
|
|
887
887
|
param = unlensed_param["optimal_snr_net"]
|
|
888
|
-
idx_detectable = param >
|
|
888
|
+
idx_detectable = param > snr_threshold_recalculation
|
|
889
889
|
# reduce the size of the dict
|
|
890
890
|
for key, value in unlensed_param.items():
|
|
891
891
|
unlensed_param[key] = value[idx_detectable]
|
|
@@ -924,7 +924,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
924
924
|
|
|
925
925
|
# store all detectable params in json file
|
|
926
926
|
for key, value in unlensed_param.items():
|
|
927
|
-
unlensed_param[key] = value[idx_detectable]
|
|
927
|
+
unlensed_param[key] = np.array(value)[idx_detectable]
|
|
928
928
|
|
|
929
929
|
# store all detectable params in json file
|
|
930
930
|
if output_jsonfile is None:
|
|
@@ -1002,7 +1002,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1002
1002
|
if self.dict_buffer:
|
|
1003
1003
|
lensed_param = self.dict_buffer.copy()
|
|
1004
1004
|
# store all params in json file
|
|
1005
|
-
print(f"saving all lensed_params in {output_path}
|
|
1005
|
+
print(f"saving all lensed_params in {output_path} ")
|
|
1006
1006
|
append_json(output_path, lensed_param, replace=True)
|
|
1007
1007
|
else:
|
|
1008
1008
|
print("lensed_params already sampled.")
|
|
@@ -1101,7 +1101,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1101
1101
|
nan_to_num=True,
|
|
1102
1102
|
detectability_condition="step_function",
|
|
1103
1103
|
snr_recalculation=False,
|
|
1104
|
-
|
|
1104
|
+
snr_threshold_recalculation=[5.5,5.5],
|
|
1105
1105
|
):
|
|
1106
1106
|
"""
|
|
1107
1107
|
Function to calculate the lensed rate. This function also stores the parameters of the detectable events in json file.
|
|
@@ -1128,9 +1128,9 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1128
1128
|
default detectability_condition = 'step_function'.
|
|
1129
1129
|
other options are 'pdet'.
|
|
1130
1130
|
snr_recalculation : `bool`
|
|
1131
|
-
if True, the SNR of centain events (snr>
|
|
1131
|
+
if True, the SNR of centain events (snr>snr_threshold_recalculation)will be recalculate with 'inner product'. This is useful when the snr is calculated with 'ann' method.
|
|
1132
1132
|
default snr_recalculation = False.
|
|
1133
|
-
|
|
1133
|
+
snr_threshold_recalculation : `float`
|
|
1134
1134
|
threshold for recalculation of detection signal to noise ratio.
|
|
1135
1135
|
|
|
1136
1136
|
Returns
|
|
@@ -1158,7 +1158,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1158
1158
|
if type(lensed_param) == str:
|
|
1159
1159
|
self.json_file_names["lensed_param"] = lensed_param
|
|
1160
1160
|
path_ = self.ler_directory+"/"+lensed_param
|
|
1161
|
-
print(f"getting lensed_params from json file {path_}
|
|
1161
|
+
print(f"getting lensed_params from json file {path_} ")
|
|
1162
1162
|
lensed_param = get_param_from_json(self.ler_directory+"/"+lensed_param)
|
|
1163
1163
|
else:
|
|
1164
1164
|
print("using provided lensed_param dict...")
|
|
@@ -1178,11 +1178,14 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1178
1178
|
# recalculate snr if required
|
|
1179
1179
|
# this ensures that the snr is recalculated for the detectable events
|
|
1180
1180
|
# with inner product
|
|
1181
|
+
############################
|
|
1182
|
+
# for ANN SNR #
|
|
1183
|
+
############################
|
|
1181
1184
|
if snr_recalculation:
|
|
1182
|
-
# dealing with provided
|
|
1183
|
-
|
|
1184
|
-
idx = np.argsort(-
|
|
1185
|
-
|
|
1185
|
+
# dealing with provided snr_threshold_recalculation
|
|
1186
|
+
snr_threshold_recalculation = np.array([snr_threshold_recalculation]).reshape(-1)
|
|
1187
|
+
idx = np.argsort(-snr_threshold_recalculation)
|
|
1188
|
+
snr_threshold_recalculation = snr_threshold_recalculation[idx]
|
|
1186
1189
|
num_img_recalculation = num_img[idx]
|
|
1187
1190
|
|
|
1188
1191
|
# check optimal_snr_net is provided in dict
|
|
@@ -1196,9 +1199,9 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1196
1199
|
j = 0
|
|
1197
1200
|
idx_max = 0
|
|
1198
1201
|
snr_hit = np.full(total_events, True) # boolean array to store the result of the threshold condition
|
|
1199
|
-
for i in range(len(
|
|
1202
|
+
for i in range(len(snr_threshold_recalculation)):
|
|
1200
1203
|
idx_max = idx_max + num_img_recalculation[i]
|
|
1201
|
-
snr_hit = snr_hit & (np.sum((snr_param[:,j:idx_max] >
|
|
1204
|
+
snr_hit = snr_hit & (np.sum((snr_param[:,j:idx_max] > snr_threshold_recalculation[i]), axis=1) >= num_img_recalculation[i])
|
|
1202
1205
|
j = idx_max
|
|
1203
1206
|
|
|
1204
1207
|
# reduce the size of the dict
|
|
@@ -1212,6 +1215,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1212
1215
|
lensed_param=lensed_param,
|
|
1213
1216
|
)
|
|
1214
1217
|
lensed_param.update(snrs)
|
|
1218
|
+
############################
|
|
1215
1219
|
|
|
1216
1220
|
if self.snr:
|
|
1217
1221
|
if "optimal_snr_net" not in lensed_param:
|
|
@@ -1443,7 +1447,10 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1443
1447
|
resume=False,
|
|
1444
1448
|
output_jsonfile="n_unlensed_param_detectable.json",
|
|
1445
1449
|
meta_data_file="meta_unlensed.json",
|
|
1450
|
+
detectability_condition="step_function",
|
|
1446
1451
|
trim_to_size=True,
|
|
1452
|
+
snr_recalculation=False,
|
|
1453
|
+
snr_threshold_recalculation=5.5,
|
|
1447
1454
|
):
|
|
1448
1455
|
"""
|
|
1449
1456
|
Function to select n unlensed detectable events.
|
|
@@ -1513,10 +1520,44 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1513
1520
|
size=batch_size, output_jsonfile=buffer_file, save_batch=False,resume=False
|
|
1514
1521
|
)
|
|
1515
1522
|
|
|
1516
|
-
|
|
1517
|
-
|
|
1523
|
+
total_events_in_this_iteration = len(unlensed_param["zs"])
|
|
1524
|
+
############################
|
|
1525
|
+
# for ANN SNR #
|
|
1526
|
+
############################
|
|
1527
|
+
if snr_recalculation:
|
|
1528
|
+
# select only above centain snr threshold
|
|
1529
|
+
param = unlensed_param["optimal_snr_net"]
|
|
1530
|
+
idx_detectable = param > snr_threshold_recalculation
|
|
1531
|
+
# reduce the size of the dict
|
|
1532
|
+
for key, value in unlensed_param.items():
|
|
1533
|
+
unlensed_param[key] = value[idx_detectable]
|
|
1534
|
+
# recalculate more accurate snrs
|
|
1535
|
+
snrs = self.snr_bilby(gw_param_dict=unlensed_param)
|
|
1536
|
+
unlensed_param.update(snrs)
|
|
1537
|
+
############################
|
|
1538
|
+
|
|
1539
|
+
if self.snr:
|
|
1540
|
+
if "optimal_snr_net" not in unlensed_param:
|
|
1541
|
+
raise ValueError("'optimal_snr_net' not in unlensed parm dict provided")
|
|
1542
|
+
if detectability_condition == "step_function":
|
|
1543
|
+
#print("given detectability_condition == 'step_function'")
|
|
1544
|
+
param = unlensed_param["optimal_snr_net"]
|
|
1545
|
+
threshold = snr_threshold
|
|
1546
|
+
elif detectability_condition == "pdet":
|
|
1547
|
+
# print("given detectability_condition == 'pdet'")
|
|
1548
|
+
param = 1 - norm.cdf(snr_threshold - unlensed_param["optimal_snr_net"])
|
|
1549
|
+
unlensed_param["pdet_net"] = param
|
|
1550
|
+
threshold = 0.5
|
|
1551
|
+
elif self.pdet:
|
|
1552
|
+
if "pdet_net" in unlensed_param:
|
|
1553
|
+
#print("given detectability_condition == 'pdet'")
|
|
1554
|
+
param = unlensed_param["pdet_net"]
|
|
1555
|
+
threshold = 0.5
|
|
1556
|
+
else:
|
|
1557
|
+
raise ValueError("'pdet_net' not in unlensed parm dict provided")
|
|
1558
|
+
|
|
1518
1559
|
# index of detectable events
|
|
1519
|
-
idx =
|
|
1560
|
+
idx = param > threshold
|
|
1520
1561
|
|
|
1521
1562
|
# store all params in json file
|
|
1522
1563
|
for key, value in unlensed_param.items():
|
|
@@ -1524,7 +1565,7 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1524
1565
|
append_json(file_name=output_path, new_dictionary=unlensed_param, replace=False)
|
|
1525
1566
|
|
|
1526
1567
|
n += np.sum(idx)
|
|
1527
|
-
events_total +=
|
|
1568
|
+
events_total += total_events_in_this_iteration
|
|
1528
1569
|
total_rate = self.normalization_pdf_z * n / events_total
|
|
1529
1570
|
|
|
1530
1571
|
# save meta data
|
|
@@ -1539,17 +1580,43 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1539
1580
|
print(f"total unlensed rate (yr^-1): {total_rate}")
|
|
1540
1581
|
|
|
1541
1582
|
print(f"storing detectable unlensed params in {output_path}")
|
|
1583
|
+
print(f"storing meta data in {meta_data_path}")
|
|
1542
1584
|
|
|
1543
1585
|
if trim_to_size:
|
|
1544
1586
|
# trim the final param dictionary
|
|
1545
1587
|
print(f"\n trmming final result to size={size}")
|
|
1546
1588
|
param_final = get_param_from_json(output_path)
|
|
1589
|
+
# randomly select size number of samples
|
|
1590
|
+
len_ = len(list(param_final.values())[0])
|
|
1591
|
+
idx = np.random.choice(len_, size, replace=False)
|
|
1547
1592
|
# trim the final param dictionary, randomly, without repeating
|
|
1548
1593
|
for key, value in param_final.items():
|
|
1549
|
-
param_final[key] =
|
|
1594
|
+
param_final[key] = value[idx]
|
|
1595
|
+
|
|
1596
|
+
# change meta data
|
|
1597
|
+
meta_data = load_json(meta_data_path)
|
|
1598
|
+
old_events_total = meta_data["events_total"][-1]
|
|
1599
|
+
old_detectable_events = meta_data["detectable_events"][-1]
|
|
1600
|
+
|
|
1601
|
+
# adjust the meta data
|
|
1602
|
+
# following is to keep rate the same
|
|
1603
|
+
new_events_total = np.round(size*old_events_total/old_detectable_events)
|
|
1604
|
+
new_total_rate = self.normalization_pdf_z * size / new_events_total
|
|
1605
|
+
meta_data["events_total"][-1] = new_events_total
|
|
1606
|
+
meta_data["detectable_events"][-1] = size
|
|
1607
|
+
meta_data["total_rate"][-1] = new_total_rate
|
|
1608
|
+
|
|
1609
|
+
|
|
1610
|
+
print("collected number of detectable events = ", size)
|
|
1611
|
+
print("total number of events = ", new_events_total)
|
|
1612
|
+
print(f"total unlensed rate (yr^-1): {new_total_rate}")
|
|
1550
1613
|
|
|
1551
|
-
|
|
1552
|
-
|
|
1614
|
+
# save the meta data
|
|
1615
|
+
append_json(meta_data_path, meta_data, replace=True)
|
|
1616
|
+
# save the final param dictionary
|
|
1617
|
+
append_json(output_path, param_final, replace=True)
|
|
1618
|
+
else:
|
|
1619
|
+
param_final = get_param_from_json(output_path)
|
|
1553
1620
|
|
|
1554
1621
|
return param_final
|
|
1555
1622
|
|
|
@@ -1557,14 +1624,16 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1557
1624
|
self,
|
|
1558
1625
|
size=100,
|
|
1559
1626
|
batch_size=None,
|
|
1560
|
-
snr_threshold=8.0,
|
|
1561
|
-
num_img=
|
|
1627
|
+
snr_threshold=[8.0,8.0],
|
|
1628
|
+
num_img=[1,1],
|
|
1562
1629
|
resume=False,
|
|
1563
1630
|
detectability_condition="step_function",
|
|
1564
1631
|
output_jsonfile="n_lensed_params_detectable.json",
|
|
1565
1632
|
meta_data_file="meta_lensed.json",
|
|
1566
1633
|
trim_to_size=True,
|
|
1567
1634
|
nan_to_num=False,
|
|
1635
|
+
snr_recalculation=False,
|
|
1636
|
+
snr_threshold_recalculation=[5.5,5.5],
|
|
1568
1637
|
):
|
|
1569
1638
|
"""
|
|
1570
1639
|
Function to select n lensed detectable events.
|
|
@@ -1605,6 +1674,8 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1605
1674
|
|
|
1606
1675
|
meta_data_path = self.ler_directory+"/"+meta_data_file
|
|
1607
1676
|
output_path = self.ler_directory+"/"+output_jsonfile
|
|
1677
|
+
if meta_data_path==output_path:
|
|
1678
|
+
raise ValueError("meta_data_file and output_jsonfile cannot be same.")
|
|
1608
1679
|
|
|
1609
1680
|
if batch_size is None:
|
|
1610
1681
|
batch_size = self.batch_size
|
|
@@ -1649,6 +1720,47 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1649
1720
|
size=self.batch_size, output_jsonfile=buffer_file, resume=False
|
|
1650
1721
|
) # Dimensions are (size, n_max_images)
|
|
1651
1722
|
|
|
1723
|
+
total_events_in_this_iteration = len(lensed_param["zs"])
|
|
1724
|
+
############################
|
|
1725
|
+
# for ANN SNR #
|
|
1726
|
+
############################
|
|
1727
|
+
if snr_recalculation:
|
|
1728
|
+
# dealing with provided snr_threshold_recalculation
|
|
1729
|
+
snr_threshold_recalculation = np.array([snr_threshold_recalculation]).reshape(-1)
|
|
1730
|
+
idx = np.argsort(-snr_threshold_recalculation)
|
|
1731
|
+
snr_threshold_recalculation = snr_threshold_recalculation[idx]
|
|
1732
|
+
num_img_recalculation = num_img[idx]
|
|
1733
|
+
|
|
1734
|
+
# check optimal_snr_net is provided in dict
|
|
1735
|
+
snr_param = lensed_param["optimal_snr_net"]
|
|
1736
|
+
if "optimal_snr_net" in lensed_param.keys():
|
|
1737
|
+
snr_param = -np.sort(-snr_param, axis=1) # sort snr in descending order
|
|
1738
|
+
else:
|
|
1739
|
+
raise ValueError("optimal_snr_net not provided in lensed_param dict. Exiting...")
|
|
1740
|
+
|
|
1741
|
+
# for each row: choose a threshold and check if the number of images above threshold. Sum over the images. If sum is greater than num_img, then snr_hit = True
|
|
1742
|
+
j = 0
|
|
1743
|
+
idx_max = 0
|
|
1744
|
+
snr_hit = np.full(len(snr_param), True) # boolean array to store the result of the threshold condition
|
|
1745
|
+
for i, snr_th in enumerate(snr_threshold_recalculation):
|
|
1746
|
+
idx_max = idx_max + num_img_recalculation[i]
|
|
1747
|
+
|
|
1748
|
+
snr_hit = snr_hit & (np.sum((snr_param[:,j:idx_max] > snr_th), axis=1) >= num_img_recalculation[i])
|
|
1749
|
+
j = idx_max
|
|
1750
|
+
|
|
1751
|
+
# reduce the size of the dict
|
|
1752
|
+
for key, value in lensed_param.items():
|
|
1753
|
+
lensed_param[key] = value[snr_hit]
|
|
1754
|
+
# recalculate more accurate snrs
|
|
1755
|
+
print("calculating snrs...")
|
|
1756
|
+
snrs, lensed_param = self.get_lensed_snrs(
|
|
1757
|
+
snr_calculator=self.snr_bilby,
|
|
1758
|
+
list_of_detectors=self.list_of_detectors,
|
|
1759
|
+
lensed_param=lensed_param,
|
|
1760
|
+
)
|
|
1761
|
+
lensed_param.update(snrs)
|
|
1762
|
+
############################
|
|
1763
|
+
|
|
1652
1764
|
if detectability_condition == "step_function":
|
|
1653
1765
|
snr_hit = np.full(len(lensed_param["zs"]), True) # boolean array to store the result of the threshold condition
|
|
1654
1766
|
try:
|
|
@@ -1699,12 +1811,15 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1699
1811
|
lensed_param[key] = value[snr_hit]
|
|
1700
1812
|
|
|
1701
1813
|
if os.path.exists(output_path):
|
|
1702
|
-
|
|
1814
|
+
try:
|
|
1815
|
+
append_json(output_path, lensed_param, replace=False)
|
|
1816
|
+
except:
|
|
1817
|
+
append_json(output_path, lensed_param, replace=True)
|
|
1703
1818
|
else:
|
|
1704
1819
|
append_json(output_path, lensed_param, replace=True)
|
|
1705
1820
|
|
|
1706
1821
|
n += np.sum(snr_hit)
|
|
1707
|
-
events_total +=
|
|
1822
|
+
events_total += total_events_in_this_iteration
|
|
1708
1823
|
|
|
1709
1824
|
# save meta data
|
|
1710
1825
|
total_rate = self.normalization_pdf_z_lensed * n / events_total
|
|
@@ -1714,22 +1829,47 @@ class LeR(LensGalaxyParameterDistribution):
|
|
|
1714
1829
|
else:
|
|
1715
1830
|
append_json(meta_data_path, meta_data, replace=True)
|
|
1716
1831
|
|
|
1717
|
-
print("collected number of events = ", n)
|
|
1832
|
+
print("collected number of detectable events = ", n)
|
|
1718
1833
|
print("total number of events = ", events_total)
|
|
1719
1834
|
print(f"total lensed rate (yr^-1): {total_rate}")
|
|
1720
1835
|
|
|
1721
1836
|
print(f"storing detectable lensed params in {output_path}")
|
|
1837
|
+
print(f"storing meta data in {meta_data_path}")
|
|
1722
1838
|
|
|
1723
1839
|
if trim_to_size:
|
|
1724
1840
|
# trim the final param dictionary
|
|
1725
1841
|
print(f"\n trmming final result to size={size}")
|
|
1726
1842
|
param_final = get_param_from_json(output_path)
|
|
1843
|
+
# randomly select size number of samples
|
|
1844
|
+
len_ = len(list(param_final.values())[0])
|
|
1845
|
+
idx = np.random.choice(len_, size, replace=False)
|
|
1727
1846
|
# trim the final param dictionary
|
|
1728
1847
|
for key, value in param_final.items():
|
|
1729
|
-
param_final[key] =
|
|
1730
|
-
|
|
1848
|
+
param_final[key] = value[idx]
|
|
1849
|
+
|
|
1850
|
+
# change meta data
|
|
1851
|
+
meta_data = load_json(meta_data_path)
|
|
1852
|
+
old_events_total = meta_data["events_total"][-1]
|
|
1853
|
+
old_detectable_events = meta_data["detectable_events"][-1]
|
|
1854
|
+
|
|
1855
|
+
# adjust the meta data
|
|
1856
|
+
# following is to keep rate the same
|
|
1857
|
+
new_events_total = np.round(size * old_events_total/old_detectable_events)
|
|
1858
|
+
new_total_rate = self.normalization_pdf_z_lensed * size / new_events_total
|
|
1859
|
+
meta_data["events_total"][-1] = new_events_total
|
|
1860
|
+
meta_data["detectable_events"][-1] = size
|
|
1861
|
+
meta_data["total_rate"][-1] = new_total_rate
|
|
1862
|
+
|
|
1863
|
+
print("collected number of detectable events = ", size)
|
|
1864
|
+
print("total number of events = ", new_events_total)
|
|
1865
|
+
print(f"total unlensed rate (yr^-1): {new_total_rate}")
|
|
1866
|
+
|
|
1867
|
+
# save the meta data
|
|
1868
|
+
append_json(meta_data_path, meta_data, replace=True)
|
|
1731
1869
|
# save the final param dictionary
|
|
1732
1870
|
append_json(output_path, param_final, replace=True)
|
|
1871
|
+
else:
|
|
1872
|
+
param_final = get_param_from_json(output_path)
|
|
1733
1873
|
|
|
1734
1874
|
return param_final
|
|
1735
1875
|
|
ler/utils/utils.py
CHANGED
|
@@ -139,7 +139,7 @@ def add_dict_values(dict1, dict2):
|
|
|
139
139
|
data_key = dict1.keys()
|
|
140
140
|
for key, value in dict2.items():
|
|
141
141
|
if key in data_key:
|
|
142
|
-
dict1[key] = np.concatenate((dict1[key], value))
|
|
142
|
+
dict1[key] = np.concatenate((dict1[key], value))
|
|
143
143
|
|
|
144
144
|
return dict1
|
|
145
145
|
|
|
@@ -187,15 +187,24 @@ def rejection_sample(pdf, xmin, xmax, size=100, chunk_size=10000):
|
|
|
187
187
|
"""
|
|
188
188
|
x = np.linspace(xmin, xmax, chunk_size)
|
|
189
189
|
y = pdf(x)
|
|
190
|
+
# Maximum value of the pdf
|
|
190
191
|
ymax = np.max(y)
|
|
192
|
+
|
|
191
193
|
# Rejection sample in chunks
|
|
192
194
|
x_sample = []
|
|
193
195
|
while len(x_sample) < size:
|
|
194
196
|
x_try = np.random.uniform(xmin, xmax, size=chunk_size)
|
|
197
|
+
pdf_x_try = pdf(x_try) # Calculate the pdf at the random x values
|
|
198
|
+
# this is for comparing with the pdf value at x_try, will be used to accept or reject the sample
|
|
195
199
|
y_try = np.random.uniform(0, ymax, size=chunk_size)
|
|
196
|
-
|
|
200
|
+
|
|
201
|
+
# Update the maximum value of the pdf
|
|
202
|
+
ymax = max(ymax, np.max(pdf_x_try))
|
|
203
|
+
|
|
204
|
+
# applying condition to accept the sample
|
|
197
205
|
# Add while retaining 1D shape of the list
|
|
198
|
-
x_sample += list(x_try[y_try <
|
|
206
|
+
x_sample += list(x_try[y_try < pdf_x_try])
|
|
207
|
+
|
|
199
208
|
# Transform the samples to a 1D numpy array
|
|
200
209
|
x_sample = np.array(x_sample).flatten()
|
|
201
210
|
# Return the correct number of samples
|
|
@@ -228,11 +237,11 @@ def rejection_sample2d(pdf, xmin, xmax, ymin, ymax, size=100, chunk_size=10000):
|
|
|
228
237
|
x_sample : `numpy.ndarray`
|
|
229
238
|
samples from the pdf in the x-axis.
|
|
230
239
|
"""
|
|
231
|
-
chunk_size = 10000
|
|
232
240
|
|
|
233
241
|
x = np.random.uniform(xmin, xmax, chunk_size)
|
|
234
242
|
y = np.random.uniform(ymin, ymax, chunk_size)
|
|
235
243
|
z = pdf(x, y)
|
|
244
|
+
# Maximum value of the pdf
|
|
236
245
|
zmax = np.max(z)
|
|
237
246
|
|
|
238
247
|
# Rejection sample in chunks
|
|
@@ -241,12 +250,15 @@ def rejection_sample2d(pdf, xmin, xmax, ymin, ymax, size=100, chunk_size=10000):
|
|
|
241
250
|
while len(x_sample) < size:
|
|
242
251
|
x_try = np.random.uniform(xmin, xmax, size=chunk_size)
|
|
243
252
|
y_try = np.random.uniform(ymin, ymax, size=chunk_size)
|
|
244
|
-
|
|
253
|
+
pdf_xy_try = pdf(x_try, y_try)
|
|
254
|
+
# this is for comparing with the pdf value at x_try, will be used to accept or reject the sample
|
|
245
255
|
z_try = np.random.uniform(0, zmax, size=chunk_size)
|
|
246
|
-
|
|
256
|
+
|
|
257
|
+
# Update the maximum value of the pdf
|
|
258
|
+
zmax = max(zmax, np.max(pdf_xy_try))
|
|
247
259
|
|
|
248
|
-
x_sample += list(x_try[z_try <
|
|
249
|
-
y_sample += list(y_try[z_try <
|
|
260
|
+
x_sample += list(x_try[z_try < pdf_xy_try])
|
|
261
|
+
y_sample += list(y_try[z_try < pdf_xy_try])
|
|
250
262
|
|
|
251
263
|
# Transform the samples to a 1D numpy array
|
|
252
264
|
x_sample = np.array(x_sample).flatten()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ler
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: Gravitational waves Lensing Rates
|
|
5
5
|
Home-page: https://github.com/hemantaph/ler
|
|
6
6
|
Author: Hemantakumar
|
|
@@ -16,7 +16,7 @@ Requires-Dist: numpy >=1.18
|
|
|
16
16
|
Requires-Dist: numba >=0.57.1
|
|
17
17
|
Requires-Dist: bilby >=1.0.2
|
|
18
18
|
Requires-Dist: gwsnr >=0.2.0
|
|
19
|
-
Requires-Dist: scipy
|
|
19
|
+
Requires-Dist: scipy <1.14.0
|
|
20
20
|
Requires-Dist: lenstronomy >=1.10.4
|
|
21
21
|
Requires-Dist: astropy >=5.1
|
|
22
22
|
Requires-Dist: tqdm >=4.64.1
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
ler/__init__.py,sha256=mTa4tgjjmfWuadm6yhsGqo-92BYy_Ad0lbBcvRZnJn4,804
|
|
2
|
+
ler/gw_source_population/__init__.py,sha256=HG0ve5wTpBDN2fNMxHLnoOqTz-S0jXM_DsWEJ5PEHAw,126
|
|
3
|
+
ler/gw_source_population/cbc_source_parameter_distribution.py,sha256=jSqAE4tm-4ZmQiKRpxZ7-LGAP_uGpEMGX197Eh2Iuyg,67862
|
|
4
|
+
ler/gw_source_population/cbc_source_redshift_distribution.py,sha256=o2qAM_-9SeLxxfGwqXrdVWTCeEAaXVan_OPDd4jrplg,28559
|
|
5
|
+
ler/gw_source_population/jit_functions.py,sha256=aQV9mv3IY5b3OLiPeXmoLWJ_TbFUS9M1OgnIyIY3eX4,8668
|
|
6
|
+
ler/image_properties/__init__.py,sha256=XfJFlyZuOrKODT-z9WxjR9mI8eT399YJV-jzcJKTqGo,71
|
|
7
|
+
ler/image_properties/image_properties.py,sha256=as-6ZKoA7bvOTDNsCE0o9LyoKzfdHip-nRRq86UkjX0,25166
|
|
8
|
+
ler/image_properties/multiprocessing_routine.py,sha256=hYnQTM7PSIj3X-5YNDqMxH9UgeXHUPPdLG70h_r6sEY,18333
|
|
9
|
+
ler/lens_galaxy_population/__init__.py,sha256=TXk1nwiYy0tvTpKs35aYK0-ZK63g2JLPyGG_yfxD0YU,126
|
|
10
|
+
ler/lens_galaxy_population/jit_functions.py,sha256=tCTcr4FWyQXH7SQlHsUWeZBpv4jnG00DsBIljdWFs5M,8472
|
|
11
|
+
ler/lens_galaxy_population/lens_galaxy_parameter_distribution.py,sha256=074RNd1EPilObL0dh7NLW1bxl9xRqv0TqdFkrAx4Ebw,48246
|
|
12
|
+
ler/lens_galaxy_population/mp.py,sha256=TPnFDEzojEqJzE3b0g39emZasHeeaeXN2q7JtMcgihk,6387
|
|
13
|
+
ler/lens_galaxy_population/optical_depth.py,sha256=fcZSXaIjx7v8WDZuiIIMEqR1gtKJc4V4gTnQpVlTpas,42437
|
|
14
|
+
ler/rates/__init__.py,sha256=N4li9NouSVjZl5HIhyuiKKRyrpUgQkBZaUeDgL1m4ic,43
|
|
15
|
+
ler/rates/gwrates.py,sha256=2svyxdEzChiK4YDN4rRVrm0Yhh0TXrRXxobg9d1sF-4,40865
|
|
16
|
+
ler/rates/ler.py,sha256=QySWLxrjP9XJGH423lHlwL006znde-lNvxTTV3O7CFI,84164
|
|
17
|
+
ler/utils/__init__.py,sha256=JWF9SKoqj1BThpV_ynfoyUeU06NQQ45DHCUGaaMSp_8,42
|
|
18
|
+
ler/utils/plots.py,sha256=D8MjTrfyE4cc0D6KBu1Mw4VMllp9Yp73bSi2cqPmNOM,10742
|
|
19
|
+
ler/utils/utils.py,sha256=FI_o6klrkZGzDlKYxSV3S5ovGQFfCNuNoc_m2qBD7pg,27945
|
|
20
|
+
ler-0.3.8.dist-info/LICENSE,sha256=9LeXXC3WaHBpiUGhLVgOVnz0F12olPma1RX5zgpfp8Q,1081
|
|
21
|
+
ler-0.3.8.dist-info/METADATA,sha256=wsmsniEhQ7kv8zjiRqZSXvGiJaVwSkEMMulE9aFkpfQ,6521
|
|
22
|
+
ler-0.3.8.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
23
|
+
ler-0.3.8.dist-info/top_level.txt,sha256=VWeWLF_gNMjzquGmqrLXqp2J5WegY86apTUimMTh68I,4
|
|
24
|
+
ler-0.3.8.dist-info/RECORD,,
|
ler-0.3.6.dist-info/RECORD
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
ler/__init__.py,sha256=Y1j_RXriJ7OLOdESsyeZkh4W7p438p5-Hgt88zZsQCA,804
|
|
2
|
-
ler/gw_source_population/__init__.py,sha256=HG0ve5wTpBDN2fNMxHLnoOqTz-S0jXM_DsWEJ5PEHAw,126
|
|
3
|
-
ler/gw_source_population/cbc_source_parameter_distribution.py,sha256=jAFBAen3ZsGkJSxSDeBT0WZlVYNTIF-ICRiftVlnlMo,66229
|
|
4
|
-
ler/gw_source_population/cbc_source_redshift_distribution.py,sha256=ajI4L7vkoNNzw2Y_bZTe9T3F9uFcrYt_KaINT9anuvw,28160
|
|
5
|
-
ler/gw_source_population/jit_functions.py,sha256=phUYdbFRvNMRgXJtSwGYSY2HN5h3n3IcLJR9AvHyC6o,8666
|
|
6
|
-
ler/image_properties/__init__.py,sha256=XfJFlyZuOrKODT-z9WxjR9mI8eT399YJV-jzcJKTqGo,71
|
|
7
|
-
ler/image_properties/image_properties.py,sha256=XKOTimOFmSCNlEfUT_oEwPGm7P3tEwEtfsydXeJmhy8,24080
|
|
8
|
-
ler/image_properties/multiprocessing_routine.py,sha256=f5sXcAx01xAx7AvOFE1Q99w7X9WIUwqlsUl7zq--rG4,17805
|
|
9
|
-
ler/lens_galaxy_population/__init__.py,sha256=TXk1nwiYy0tvTpKs35aYK0-ZK63g2JLPyGG_yfxD0YU,126
|
|
10
|
-
ler/lens_galaxy_population/jit_functions.py,sha256=8ZlseC6oaNuiZg5DvOeoonkH1BUE_dZyFMfmAx7_TPw,8419
|
|
11
|
-
ler/lens_galaxy_population/lens_galaxy_parameter_distribution.py,sha256=e_3lgfJi3K_ioZf5VTw4hPgtUHeDThMHUYGmUnuKE9Q,48174
|
|
12
|
-
ler/lens_galaxy_population/mp.py,sha256=TPnFDEzojEqJzE3b0g39emZasHeeaeXN2q7JtMcgihk,6387
|
|
13
|
-
ler/lens_galaxy_population/optical_depth.py,sha256=m4rBkE2-7Gd6z_oHmHOfg4bPHOi0xotCs5VQnFbzz_A,42333
|
|
14
|
-
ler/rates/__init__.py,sha256=N4li9NouSVjZl5HIhyuiKKRyrpUgQkBZaUeDgL1m4ic,43
|
|
15
|
-
ler/rates/gwrates.py,sha256=cAMC57G9D0yiJLN_Q6qV4wyTlnyk_vkrZ3nCbbSb6dw,40718
|
|
16
|
-
ler/rates/ler.py,sha256=Ff1u0sWb_1rHzuUjm7xgZ1q8xBh57TQ3VxJVjgFhjZE,76975
|
|
17
|
-
ler/utils/__init__.py,sha256=JWF9SKoqj1BThpV_ynfoyUeU06NQQ45DHCUGaaMSp_8,42
|
|
18
|
-
ler/utils/plots.py,sha256=D8MjTrfyE4cc0D6KBu1Mw4VMllp9Yp73bSi2cqPmNOM,10742
|
|
19
|
-
ler/utils/utils.py,sha256=BPMUMamJeAW9-LlvW4ao93jAZSG6YBS6Hd3FpTYJgB4,27465
|
|
20
|
-
ler-0.3.6.dist-info/LICENSE,sha256=9LeXXC3WaHBpiUGhLVgOVnz0F12olPma1RX5zgpfp8Q,1081
|
|
21
|
-
ler-0.3.6.dist-info/METADATA,sha256=92RR_37n1guw-A7aebZbeeDqPnosEJ-fee4NQaeiqOY,6521
|
|
22
|
-
ler-0.3.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
|
23
|
-
ler-0.3.6.dist-info/top_level.txt,sha256=VWeWLF_gNMjzquGmqrLXqp2J5WegY86apTUimMTh68I,4
|
|
24
|
-
ler-0.3.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|