Skip to content

Commit

Permalink
Fix error messages when testing coordinate system conversion and gene…
Browse files Browse the repository at this point in the history
…ralize test for mock data
  • Loading branch information
caioolivv committed Jul 18, 2024
1 parent 63e6dc9 commit dd36aac
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
32 changes: 16 additions & 16 deletions tests/test_dataops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)


Expand All @@ -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",
)


Expand Down
25 changes: 13 additions & 12 deletions tests/test_galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
40 changes: 28 additions & 12 deletions tests/test_mockdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit dd36aac

Please sign in to comment.