Skip to content

Commit

Permalink
Added ellipticity coordinate system conversion tests to test_galaxycl…
Browse files Browse the repository at this point in the history
…uster.py and test_mockdata.py
  • Loading branch information
Caio Lima de Oliveira committed Jul 16, 2024
1 parent c950229 commit 9bdc6cd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test_galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,45 @@ def test_plot_profiles():
cluster.plot_profiles()
# check it passes missing a component error
cluster.plot_profiles(cross_component_error="made_up_component")


def test_coordinate_system():
"""test coordinate system"""
# Input values
ra_lens, dec_lens, z_lens = 120.0, 42.0, 0.5
ra_source = [120.1, 119.9]
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]
# Set up radial values
bins_radians = [0.002, 0.003, 0.004]
bin_units = "radians"
# create cluster
cl_pixel = 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], names=("ra", "dec", "e1", "e2", "z")
),
coordinate_system="pixel"
)
cl_sky = 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")
),
coordinate_system="sky"
)

cl_pixel.compute_tangential_and_cross_components()
cl_sky.compute_tangential_and_cross_components()

assert_allclose(cl_pixel.galcat["et"], cl_sky.galcat["et"], **TOLERANCE, err_msg="Tangential component conversion between ellipticity coordinate systems failed")
assert_allclose(cl_pixel.galcat["ex"], -cl_sky.galcat["ex"], **TOLERANCE, err_msg="Cross component conversion between ellipticity coordinate systems failed")
24 changes: 24 additions & 0 deletions tests/test_mockdata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for examples/support/mock_data.py"""

import warnings
import numpy as np
from numpy.testing import assert_raises, assert_allclose, assert_equal
Expand Down Expand Up @@ -276,3 +277,26 @@ def test_shapenoise():
)
assert_allclose(np.histogram(data["e1"], bins=bins)[0], gauss, atol=50, rtol=0.05)
assert_allclose(np.histogram(data["e2"], bins=bins)[0], gauss, atol=50, rtol=0.05)


def test_coordinate_system():
"""
Test that the coordinate system is correctly set up and that the galaxies are in the correct
position.
"""
cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.27 - 0.045, Omega_b0=0.045, Omega_k0=0.0)

# 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="pixel"
)
np.random.seed(285713)
sky_data = mock.generate_galaxy_catalog(
10**15.0, 0.3, 4, cosmo, 0.8, ngals=50000, coordinate_system="sky"
)

assert_equal(pixel_data["ra"], sky_data["ra"])
assert_equal(pixel_data["dec"], sky_data["dec"])
assert_allclose(pixel_data["e1"], sky_data["e1"], **TOLERANCE, err_msg="Conversion from sky to pixel coordinate system for theta failed")
assert_allclose(pixel_data["e2"], -sky_data["e2"], **TOLERANCE, err_msg="Conversion from sky to pixel coordinate system for theta failed")

0 comments on commit 9bdc6cd

Please sign in to comment.