Skip to content

Commit

Permalink
fixed a test area issue in random lens draw.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhadka21 committed Oct 18, 2024
1 parent cdd539a commit 1d94e25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 8 additions & 3 deletions slsim/lens_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,23 @@ def __init__(
if self.los_config is None:
self.los_config = LOSConfig()

def select_lens_at_random(self, **kwargs_lens_cut):
def select_lens_at_random(self, test_area=None, **kwargs_lens_cut):
"""Draw a random lens within the cuts of the lens and source, with possible
additional cut in the lensing configuration.
# TODO: make sure mass function is preserved, # as well as option to draw all
lenses within the cuts within the area
:param test_area: solid angle around one lensing galaxies to be investigated on
(in arc-seconds^2). If None, computed using deflector's velocity dispersion.
:return: Lens() instance with parameters of the deflector and lens and source
light
"""
while True:
source = self._sources.draw_source()
lens = self._lens_galaxies.draw_deflector()
if test_area is None:
test_area = draw_test_area(deflector=lens)
else:
test_area = test_area
gg_lens = Lens(
deflector_dict=lens,
source_dict=source,
Expand All @@ -94,6 +98,7 @@ def select_lens_at_random(self, **kwargs_lens_cut):
sn_absolute_mag_band=self.sn_absolute_mag_band,
sn_absolute_zpsys=self.sn_absolute_zpsys,
cosmo=self.cosmo,
test_area=test_area,
source_type=self._sources.source_type,
light_profile=self._sources.light_profile,
lightcurve_time=self.lightcurve_time,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_lens_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def test_cluster_lens_pop_instance():
)

kwargs_lens_cut = {}
pes_lens_class = cluster_lens_pop.select_lens_at_random(**kwargs_lens_cut)
pes_lens_class = cluster_lens_pop.select_lens_at_random(
test_area=4 * np.pi, **kwargs_lens_cut
)
assert pes_lens_class.deflector.deflector_type == "NFW_CLUSTER"
kwargs_model, kwargs_params = pes_lens_class.lenstronomy_kwargs(band="g")
assert len(kwargs_model["lens_model_list"]) >= 3 # halo, 1>= subhalo, LoS
Expand Down

0 comments on commit 1d94e25

Please sign in to comment.