Skip to content

Commit

Permalink
Merge pull request #263 from nkhadka21/galsim_fix
Browse files Browse the repository at this point in the history
galasim import issue fix
  • Loading branch information
nkhadka21 authored Oct 18, 2024
2 parents ec73359 + 1d94e25 commit 0a7c8f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 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
8 changes: 5 additions & 3 deletions slsim/roman_image_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
import os.path
import pickle
from webbpsf.roman import WFI
import warnings

try:
import galsim
from galsim import Image, InterpolatedImage, roman
except ModuleNotFoundError:
raise ModuleNotFoundError(
"Please install the galsim module in order to use simulate_roman_image.\n"
warning_msg = (
"If you want to simulate images with Roman filters, please install the galsim module.\n"
"Note that this module is not supported on Windows"
)
)
warnings.warn(warning_msg, category=UserWarning, stacklevel=2)

# NOTE: Adding sky background requires webbpsf-data, which can be found at
# https://webbpsf.readthedocs.io/en/latest/installation.html. Then, the
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 0a7c8f6

Please sign in to comment.