diff --git a/slsim/lens_pop.py b/slsim/lens_pop.py index c104b990a..692731cc4 100644 --- a/slsim/lens_pop.py +++ b/slsim/lens_pop.py @@ -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, @@ -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, diff --git a/slsim/roman_image_simulation.py b/slsim/roman_image_simulation.py index fb3783c1c..ef8563e0a 100644 --- a/slsim/roman_image_simulation.py +++ b/slsim/roman_image_simulation.py @@ -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 diff --git a/tests/test_lens_pop.py b/tests/test_lens_pop.py index 946134b62..9fde452ab 100644 --- a/tests/test_lens_pop.py +++ b/tests/test_lens_pop.py @@ -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