From 68da66a0c99628b2291b7f331c387271b9121acd Mon Sep 17 00:00:00 2001 From: narayan Date: Tue, 26 Nov 2024 11:51:13 -0500 Subject: [PATCH 1/5] specified z_source in the lens model. This is required by lenstronomy. --- slsim/lens.py | 1 + 1 file changed, 1 insertion(+) diff --git a/slsim/lens.py b/slsim/lens.py index cd4cf1d7..d65229e5 100644 --- a/slsim/lens.py +++ b/slsim/lens.py @@ -802,6 +802,7 @@ def lenstronomy_kwargs(self, band=None): kwargs_model["z_source_convention"] = ( self.max_redshift_source_class.redshift ) + kwargs_model["z_source"] = self.max_redshift_source_class.redshift kwargs_model["cosmo"] = self.cosmo sources, sources_kwargs = self.source_light_model_lenstronomy(band=band) From 32966fa2be6310502c0695668c918cc99b9c0faa Mon Sep 17 00:00:00 2001 From: narayan Date: Tue, 26 Nov 2024 14:28:17 -0500 Subject: [PATCH 2/5] adjusted source list in lens class with light profile. --- slsim/lens.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/slsim/lens.py b/slsim/lens.py index d65229e5..d641b783 100644 --- a/slsim/lens.py +++ b/slsim/lens.py @@ -798,7 +798,11 @@ def lenstronomy_kwargs(self, band=None): lens_mass_model_list ) kwargs_model["z_lens"] = self.deflector_redshift - kwargs_model["source_redshift_list"] = self.source_redshift_list + if self.max_redshift_source_class.light_profile == "single_sersic": + kwargs_model["source_redshift_list"] = self.source_redshift_list + elif self.max_redshift_source_class.light_profile == "double_sersic": + kwargs_model["source_redshift_list"] = [ + z for z in self.source_redshift_list for _ in range(2)] kwargs_model["z_source_convention"] = ( self.max_redshift_source_class.redshift ) @@ -894,19 +898,19 @@ def source_light_model_lenstronomy(self, band=None): ) ) # lets transform list in to required structure - if ( + """if ( self.max_redshift_source_class.light_profile == "double_sersic" and self.source_number > 1 ): source_models_list_restructure = source_models_list kwargs_source_list_restructure = kwargs_source_list - else: - source_models_list_restructure = list( - np.concatenate(source_models_list) - ) - kwargs_source_list_restructure = list( - np.concatenate(kwargs_source_list) - ) + else:""" + source_models_list_restructure = list( + np.concatenate(source_models_list) + ) + kwargs_source_list_restructure = list( + np.concatenate(kwargs_source_list) + ) source_models["source_light_model_list"] = source_models_list_restructure kwargs_source = kwargs_source_list_restructure else: From 0d61d50040c11072b15c28b3896614145629f3bf Mon Sep 17 00:00:00 2001 From: narayan Date: Tue, 26 Nov 2024 14:53:14 -0500 Subject: [PATCH 3/5] adjusted test functions in image simulation --- tests/test_image_simulation.py | 59 ++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/tests/test_image_simulation.py b/tests/test_image_simulation.py index 5226b0ad..71f5af12 100644 --- a/tests/test_image_simulation.py +++ b/tests/test_image_simulation.py @@ -465,42 +465,39 @@ def setup_method(self): source_class=[self.source1, self.source2], cosmo=self.cosmo, ) - path = os.path.dirname(__file__) - psf_kernel_single = np.load( - os.path.join(path, "TestData/psf_kernels_for_image_1.npy") - ) - image1 = lens_image( - lens_class=lens_class1, - band="i", - mag_zero_point=27, - num_pix=64, - psf_kernel=psf_kernel_single, - transform_pix2angle=np.array([[0.2, 0], [0, 0.2]]), - exposure_time=30, - t_obs=10, - ) - image2 = lens_image( - lens_class=lens_class2, + + self.image1 = sharp_image( + lens_class1, + band="i", + mag_zero_point=27, + delta_pix=0.2, + num_pix=64, + with_source=True, + with_deflector=True, + ) + self.image2=sharp_image( + lens_class2, + band="i", + mag_zero_point=27, + delta_pix=0.2, + num_pix=64, + with_source=True, + with_deflector=False, + ) + self.image3 = sharp_image( + lens_class3, band="i", mag_zero_point=27, + delta_pix=0.2, num_pix=64, - psf_kernel=psf_kernel_single, - transform_pix2angle=np.array([[0.2, 0], [0, 0.2]]), - exposure_time=30, - t_obs=10, + with_source=True, + with_deflector=True, ) - image3 = lens_image( - lens_class=lens_class3, - band="i", - mag_zero_point=27, - num_pix=64, - psf_kernel=psf_kernel_single, - transform_pix2angle=np.array([[0.2, 0], [0, 0.2]]), - exposure_time=30, - t_obs=10, + self.combined_image = self.image1 + self.image2 + def test_image_multiple_source(self): + npt.assert_almost_equal( + self.image3, self.combined_image, decimal=10 ) - combined_image = image1 + image2 - assert image3 == combined_image if __name__ == "__main__": From 30b455549f81f4af061056213dad385b869f5619 Mon Sep 17 00:00:00 2001 From: narayan Date: Tue, 26 Nov 2024 15:08:03 -0500 Subject: [PATCH 4/5] minor test --- tests/test_image_simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_image_simulation.py b/tests/test_image_simulation.py index 71f5af12..7a1e8d59 100644 --- a/tests/test_image_simulation.py +++ b/tests/test_image_simulation.py @@ -496,7 +496,7 @@ def setup_method(self): self.combined_image = self.image1 + self.image2 def test_image_multiple_source(self): npt.assert_almost_equal( - self.image3, self.combined_image, decimal=10 + self.image3, self.combined_image, decimal=8 ) From 8ac4905c198883fea041b4901d1b97015cc686d6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:11:01 +0000 Subject: [PATCH 5/5] Autofix formatting from pre-commit.com hooks --- slsim/lens.py | 11 ++++------ tests/test_image_simulation.py | 39 +++++++++++++++++----------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/slsim/lens.py b/slsim/lens.py index d641b783..2ebbd3ee 100644 --- a/slsim/lens.py +++ b/slsim/lens.py @@ -802,7 +802,8 @@ def lenstronomy_kwargs(self, band=None): kwargs_model["source_redshift_list"] = self.source_redshift_list elif self.max_redshift_source_class.light_profile == "double_sersic": kwargs_model["source_redshift_list"] = [ - z for z in self.source_redshift_list for _ in range(2)] + z for z in self.source_redshift_list for _ in range(2) + ] kwargs_model["z_source_convention"] = ( self.max_redshift_source_class.redshift ) @@ -905,12 +906,8 @@ def source_light_model_lenstronomy(self, band=None): source_models_list_restructure = source_models_list kwargs_source_list_restructure = kwargs_source_list else:""" - source_models_list_restructure = list( - np.concatenate(source_models_list) - ) - kwargs_source_list_restructure = list( - np.concatenate(kwargs_source_list) - ) + source_models_list_restructure = list(np.concatenate(source_models_list)) + kwargs_source_list_restructure = list(np.concatenate(kwargs_source_list)) source_models["source_light_model_list"] = source_models_list_restructure kwargs_source = kwargs_source_list_restructure else: diff --git a/tests/test_image_simulation.py b/tests/test_image_simulation.py index 7a1e8d59..a33722d3 100644 --- a/tests/test_image_simulation.py +++ b/tests/test_image_simulation.py @@ -467,23 +467,23 @@ def setup_method(self): ) self.image1 = sharp_image( - lens_class1, - band="i", - mag_zero_point=27, - delta_pix=0.2, - num_pix=64, - with_source=True, - with_deflector=True, - ) - self.image2=sharp_image( - lens_class2, - band="i", - mag_zero_point=27, - delta_pix=0.2, - num_pix=64, - with_source=True, - with_deflector=False, - ) + lens_class1, + band="i", + mag_zero_point=27, + delta_pix=0.2, + num_pix=64, + with_source=True, + with_deflector=True, + ) + self.image2 = sharp_image( + lens_class2, + band="i", + mag_zero_point=27, + delta_pix=0.2, + num_pix=64, + with_source=True, + with_deflector=False, + ) self.image3 = sharp_image( lens_class3, band="i", @@ -494,10 +494,9 @@ def setup_method(self): with_deflector=True, ) self.combined_image = self.image1 + self.image2 + def test_image_multiple_source(self): - npt.assert_almost_equal( - self.image3, self.combined_image, decimal=8 - ) + npt.assert_almost_equal(self.image3, self.combined_image, decimal=8) if __name__ == "__main__":