From dd36aacad71f6da590ad6216189398519eba6b3b Mon Sep 17 00:00:00 2001 From: Caio Lima de Oliveira Date: Thu, 18 Jul 2024 12:41:49 -0300 Subject: [PATCH] Fix error messages when testing coordinate system conversion and generalize test for mock data --- tests/test_dataops.py | 32 ++++++++++++++--------------- tests/test_galaxycluster.py | 25 ++++++++++++----------- tests/test_mockdata.py | 40 ++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index 9c27dd23a..54942c9dd 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -138,25 +138,25 @@ def test_compute_lensing_angles_flatsky(): # coordinate_system conversion ra_l, dec_l = 161.32, 51.49 ra_s, dec_s = np.array([161.29, 161.34]), np.array([51.45, 51.55]) - thetas_pixel, phis_pixel = da._compute_lensing_angles_flatsky( + thetas_euclidean, phis_euclidean = da._compute_lensing_angles_flatsky( ra_l, dec_l, ra_s, dec_s, coordinate_system="euclidean" ) - thetas_sky, phis_sky = da._compute_lensing_angles_flatsky( + thetas_celestial, phis_celestial = da._compute_lensing_angles_flatsky( ra_l, dec_l, ra_s, dec_s, coordinate_system="celestial" ) assert_allclose( - thetas_sky, - thetas_pixel, + thetas_celestial, + thetas_euclidean, **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for theta failed", + err_msg="Conversion from euclidean to celestial coordinate system for theta failed", ) assert_allclose( - phis_sky, - np.pi - phis_pixel, + phis_celestial, + np.pi - phis_euclidean, **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for phi failed", + err_msg="Conversion from euclidean to celestial coordinate system for phi failed", ) @@ -166,25 +166,25 @@ def test_compute_lensing_angles_astropy(): # coordinate_system conversion ra_l, dec_l = 161.32, 51.49 ra_s, dec_s = np.array([161.29, 161.34]), np.array([51.45, 51.55]) - thetas_pixel, phis_pixel = da._compute_lensing_angles_astropy( + thetas_euclidean, phis_euclidean = da._compute_lensing_angles_astropy( ra_l, dec_l, ra_s, dec_s, coordinate_system="euclidean" ) - thetas_sky, phis_sky = da._compute_lensing_angles_astropy( + thetas_celestial, phis_celestial = da._compute_lensing_angles_astropy( ra_l, dec_l, ra_s, dec_s, coordinate_system="celestial" ) assert_allclose( - thetas_sky, - thetas_pixel, + thetas_celestial, + thetas_euclidean, **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for theta failed", + err_msg="Conversion from euclidean to celestial coordinate system for theta failed", ) assert_allclose( - phis_sky, - np.pi - phis_pixel, + phis_celestial, + np.pi - phis_euclidean, **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for phi failed", + err_msg="Conversion from euclidean to celestial coordinate system for phi failed", ) diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index 9bea436e3..565d0fffe 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -498,46 +498,47 @@ def test_coordinate_system(): dec_source = [41.9, 42.2] z_src = [1.0, 2.0] shear1 = [0.2, 0.4] - shear2_pixel = [0.3, 0.5] - shear2_sky = [-0.3, -0.5] + shear2_euclidean = [0.3, 0.5] + shear2_celestial = [-0.3, -0.5] # Set up radial values bins_radians = [0.002, 0.003, 0.004] bin_units = "radians" # create cluster - cl_pixel = clmm.GalaxyCluster( + cl_euclidean = clmm.GalaxyCluster( unique_id="test", ra=ra_lens, dec=dec_lens, z=z_lens, galcat=GCData( - [ra_source, dec_source, shear1, shear2_pixel, z_src], + [ra_source, dec_source, shear1, shear2_euclidean, z_src], names=("ra", "dec", "e1", "e2", "z"), ), coordinate_system="euclidean", ) - cl_sky = clmm.GalaxyCluster( + cl_celestial = clmm.GalaxyCluster( unique_id="test", ra=ra_lens, dec=dec_lens, z=z_lens, galcat=GCData( - [ra_source, dec_source, shear1, shear2_sky, z_src], names=("ra", "dec", "e1", "e2", "z") + [ra_source, dec_source, shear1, shear2_celestial, z_src], + names=("ra", "dec", "e1", "e2", "z"), ), coordinate_system="celestial", ) - cl_pixel.compute_tangential_and_cross_components() - cl_sky.compute_tangential_and_cross_components() + cl_euclidean.compute_tangential_and_cross_components() + cl_celestial.compute_tangential_and_cross_components() assert_allclose( - cl_pixel.galcat["et"], - cl_sky.galcat["et"], + cl_euclidean.galcat["et"], + cl_celestial.galcat["et"], **TOLERANCE, err_msg="Tangential component conversion between ellipticity coordinate systems failed", ) assert_allclose( - cl_pixel.galcat["ex"], - -cl_sky.galcat["ex"], + cl_euclidean.galcat["ex"], + -cl_celestial.galcat["ex"], **TOLERANCE, err_msg="Cross component conversion between ellipticity coordinate systems failed", ) diff --git a/tests/test_mockdata.py b/tests/test_mockdata.py index c075b6e79..9cd53e219 100644 --- a/tests/test_mockdata.py +++ b/tests/test_mockdata.py @@ -284,27 +284,43 @@ def test_coordinate_system(): # Verify that the coordinate system is correctly set up np.random.seed(285713) - pixel_data = mock.generate_galaxy_catalog( - 10**15.0, 0.3, 4, cosmo, 0.8, ngals=50000, coordinate_system="euclidean" + euclidean_data = mock.generate_galaxy_catalog( + 10**15.0, + 0.3, + 4, + cosmo, + 0.8, + ngals=50000, + shapenoise=0.05, + photoz_sigma_unscaled=0.05, + coordinate_system="euclidean", ) np.random.seed(285713) - sky_data = mock.generate_galaxy_catalog( - 10**15.0, 0.3, 4, cosmo, 0.8, ngals=50000, coordinate_system="celestial" + celestial_data = mock.generate_galaxy_catalog( + 10**15.0, + 0.3, + 4, + cosmo, + 0.8, + ngals=50000, + shapenoise=0.05, + photoz_sigma_unscaled=0.05, + coordinate_system="celestial", ) - assert_equal(pixel_data["ra"], sky_data["ra"]) - assert_equal(pixel_data["dec"], sky_data["dec"]) + assert_equal(euclidean_data["ra"], celestial_data["ra"]) + assert_equal(euclidean_data["dec"], celestial_data["dec"]) assert_allclose( - pixel_data["e1"], - sky_data["e1"], + euclidean_data["e1"], + celestial_data["e1"], **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for theta failed" + err_msg="Conversion from euclidean to celestial coordinate system for theta failed" ) assert_allclose( - pixel_data["e2"], - -sky_data["e2"], + euclidean_data["e2"], + -celestial_data["e2"], **TOLERANCE, - err_msg="Conversion from sky to pixel coordinate system for theta failed" + err_msg="Conversion from euclidean to celestial coordinate system for theta failed" ) assert_raises(