From c84b83b8ba7c9a3c69f5369fae6c892957e6302a Mon Sep 17 00:00:00 2001 From: Caio Lima de Oliveira Date: Thu, 18 Jul 2024 05:44:42 -0300 Subject: [PATCH] Fixed all the documentation for coordinate_system and changed names from 'pixel'/'sky' to 'euclidean'/'celestial' --- clmm/dataops/__init__.py | 21 ++++++++++++--------- clmm/galaxycluster.py | 11 ++++------- clmm/support/mock_data.py | 10 ++++++---- clmm/utils/validation.py | 6 +++--- examples/demo_mock_cluster.ipynb | 4 ++-- tests/test_dataops.py | 8 ++++---- tests/test_galaxycluster.py | 32 ++++++++++++++++---------------- tests/test_mockdata.py | 12 ++++-------- 8 files changed, 51 insertions(+), 53 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index d7901a160..2a442cc12 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -31,7 +31,7 @@ def compute_tangential_and_cross_components( dec_source, shear1, shear2, - coordinate_system="pixel", + coordinate_system="euclidean", geometry="curve", is_deltasigma=False, sigma_c=None, @@ -99,8 +99,8 @@ def compute_tangential_and_cross_components( shear2: array The measured shear (or reduced shear or ellipticity) of the source galaxies coordinate_system: str, optional - Coordinate system of the ellipticity components. Options are 'pixel' or 'sky'. - Default is 'pixel'. + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. + Default is 'euclidean'. geometry: str, optional Sky geometry to compute angular separation. Options are curve (uses astropy) or flat. @@ -341,7 +341,7 @@ def compute_galaxy_weights( def _compute_lensing_angles_flatsky( - ra_lens, dec_lens, ra_source_list, dec_source_list, coordinate_system="pixel" + ra_lens, dec_lens, ra_source_list, dec_source_list, coordinate_system="euclidean" ): r"""Compute the angular separation between the lens and the source and the azimuthal angle from the lens to the source in radians. @@ -367,8 +367,8 @@ def _compute_lensing_angles_flatsky( dec_source_list: array Declinations of each source galaxy in degrees coordinate_system: str, optional - Coordinate system of the ellipticity components. Options are 'pixel' or 'sky'. - Default is 'pixel'. + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. + Default is 'euclidean'. Returns ------- @@ -392,7 +392,7 @@ def _compute_lensing_angles_flatsky( phi[angsep == 0.0] = 0.0 else: phi = 0.0 if angsep == 0.0 else phi - if coordinate_system == "sky": + if coordinate_system == "celestial": phi = np.pi - phi if np.any(angsep > np.pi / 180.0): warnings.warn("Using the flat-sky approximation with separations >1 deg may be inaccurate") @@ -400,7 +400,7 @@ def _compute_lensing_angles_flatsky( def _compute_lensing_angles_astropy( - ra_lens, dec_lens, ra_source_list, dec_source_list, coordinate_system="pixel" + ra_lens, dec_lens, ra_source_list, dec_source_list, coordinate_system="euclidean" ): r"""Compute the angular separation between the lens and the source and the azimuthal angle from the lens to the source in radians. @@ -415,6 +415,9 @@ def _compute_lensing_angles_astropy( Right ascensions of each source galaxy in degrees dec_source_list: array Declinations of each source galaxy in degrees + coordinate_system: str, optional + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. + Default is 'euclidean'. Returns ------- @@ -434,7 +437,7 @@ def _compute_lensing_angles_astropy( else: phi -= 2 * np.pi if phi > np.pi else 0 phi = 0 if angsep == 0 else phi - if coordinate_system == "sky": + if coordinate_system == "celestial": phi = np.pi - phi return angsep, phi diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index f7dbb567f..13ce8deb4 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -37,9 +37,9 @@ class GalaxyCluster: Redshift of galaxy cluster center galcat : GCData Table of background galaxy data containing at least galaxy_id, ra, dec, e1, e2, z - coordinate_system : str - Coordinate system of the galaxy cluster center (pixel or sky) - + coordinate_system : str, optional + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. + Default is 'euclidean'. validate_input: bool Validade each input argument """ @@ -63,7 +63,7 @@ def _add_values( dec: float, z: float, galcat: GCData, - coordinate_system: str = "pixel", + coordinate_system: str = "euclidean", ): """Add values for all attributes""" self.unique_id = unique_id @@ -257,9 +257,6 @@ def compute_tangential_and_cross_components( Name of the column to be added to the `galcat` astropy table that will contain the cross component computed from columns `shape_component1` and `shape_component2`. Default: `ex` - coordinate_system: str, optional - Coordinate system of the ellipticity components. Options are 'pixel' or 'sky'. - Default: 'pixel' geometry: str, optional Sky geometry to compute angular separation. Options are curve (uses astropy) or flat. diff --git a/clmm/support/mock_data.py b/clmm/support/mock_data.py index 1e8379880..e50a3a280 100644 --- a/clmm/support/mock_data.py +++ b/clmm/support/mock_data.py @@ -1,4 +1,5 @@ """Functions to generate mock source galaxy distributions to demo lensing code""" + import warnings import numpy as np from astropy import units as u @@ -38,7 +39,7 @@ def generate_galaxy_catalog( ngal_density=None, pz_bins=101, pzpdf_type="shared_bins", - coordinate_system="pixel", + coordinate_system="euclidean", validate_input=True, ): r"""Generates a mock dataset of sheared background galaxies. @@ -158,7 +159,8 @@ def generate_galaxy_catalog( The number of galaxies to be drawn will then depend on the redshift distribution and user-defined redshift range. If specified, the ngals argument will be ignored. coordinate_system : str, optional - The coordinate system to use for the output catalog. Options are 'pixel' and 'sky'. + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. + Default is 'euclidean'. validate_input: bool Validade each input argument @@ -366,7 +368,7 @@ def _generate_galaxy_catalog( photoz_sigma_unscaled=None, pz_bins=101, pzpdf_type="shared_bins", - coordinate_system="pixel", + coordinate_system="euclidean", field_size=None, ): """A private function that skips the sanity checks on derived properties. This @@ -428,7 +430,7 @@ def _generate_galaxy_catalog( _, posangle = c_cl.separation(c_gal).rad, c_cl.position_angle(c_gal).rad posangle += 0.5 * np.pi # for right convention - if coordinate_system == "sky": + if coordinate_system == "celestial": posangle = np.pi - posangle # ellipticity coordinate system conversion # corresponding shear1,2 components diff --git a/clmm/utils/validation.py b/clmm/utils/validation.py index 539b8482f..767ef67f5 100644 --- a/clmm/utils/validation.py +++ b/clmm/utils/validation.py @@ -235,7 +235,7 @@ def _validate_coordinate_system(loc, coordinate_system, valid_type): loc: dict Dictionary with all input arguments. Should be locals(). coordinate_system: str - Coordinate system used for the input data. + Coordinate system of the ellipticity components. Must be either 'celestial' or 'euclidean'. valid_type: str, type Valid types for argument, options are object types, list/tuple of types, or: @@ -243,5 +243,5 @@ def _validate_coordinate_system(loc, coordinate_system, valid_type): * 'float_array' - float, float array """ validate_argument(loc, coordinate_system, valid_type) - if loc[coordinate_system] not in ["sky", "pixel"]: - raise ValueError(f"{coordinate_system} must be 'sky' or 'pixel'.") + if loc[coordinate_system] not in ["celestial", "euclidean"]: + raise ValueError(f"{coordinate_system} must be 'celestial' or 'euclidean'.") diff --git a/examples/demo_mock_cluster.ipynb b/examples/demo_mock_cluster.ipynb index 81b90e1c1..795b6b32e 100644 --- a/examples/demo_mock_cluster.ipynb +++ b/examples/demo_mock_cluster.ipynb @@ -130,7 +130,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "It is also possible to choose the coordinate system for the generated ellipticities. Possible options are either \"sky\" or \"pixel\". The default choice is \"pixel\"." + "It is also possible to choose the coordinate system for the generated ellipticities. Possible options are either \"celestial\" or \"euclidean\". The default choice is \"euclidean\"." ] }, { @@ -139,7 +139,7 @@ "metadata": {}, "outputs": [], "source": [ - "coordinate_system = \"pixel\"\n" + "coordinate_system = \"euclidean\"\n" ] }, { diff --git a/tests/test_dataops.py b/tests/test_dataops.py index 81e586f06..9c27dd23a 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -139,10 +139,10 @@ def test_compute_lensing_angles_flatsky(): 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( - ra_l, dec_l, ra_s, dec_s, coordinate_system="pixel" + ra_l, dec_l, ra_s, dec_s, coordinate_system="euclidean" ) thetas_sky, phis_sky = da._compute_lensing_angles_flatsky( - ra_l, dec_l, ra_s, dec_s, coordinate_system="sky" + ra_l, dec_l, ra_s, dec_s, coordinate_system="celestial" ) assert_allclose( @@ -167,10 +167,10 @@ def test_compute_lensing_angles_astropy(): 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( - ra_l, dec_l, ra_s, dec_s, coordinate_system="pixel" + ra_l, dec_l, ra_s, dec_s, coordinate_system="euclidean" ) thetas_sky, phis_sky = da._compute_lensing_angles_astropy( - ra_l, dec_l, ra_s, dec_s, coordinate_system="sky" + ra_l, dec_l, ra_s, dec_s, coordinate_system="celestial" ) assert_allclose( diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index 66b20ea66..9bea436e3 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -20,7 +20,7 @@ def test_initialization(): "dec": 34.0, "z": 0.3, "galcat": GCData(), - "coordinate_system": "pixel", + "coordinate_system": "euclidean", } cl1 = clmm.GalaxyCluster(**testdict1) @@ -49,7 +49,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( ValueError, @@ -59,7 +59,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( ValueError, @@ -69,7 +69,7 @@ def test_integrity(): # Converge on name dec=95.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( ValueError, @@ -79,7 +79,7 @@ def test_integrity(): # Converge on name dec=-95.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( ValueError, @@ -89,7 +89,7 @@ def test_integrity(): # Converge on name dec=34.0, z=-0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( ValueError, @@ -111,7 +111,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -121,7 +121,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=1, - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -131,7 +131,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=[], - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -141,7 +141,7 @@ def test_integrity(): # Converge on name dec=34.0, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -151,7 +151,7 @@ def test_integrity(): # Converge on name dec=None, z=0.3, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -161,7 +161,7 @@ def test_integrity(): # Converge on name dec=34.0, z=None, galcat=GCData(), - coordinate_system="pixel", + coordinate_system="euclidean", ) assert_raises( TypeError, @@ -177,13 +177,13 @@ def test_integrity(): # Converge on name # Test that id can support numbers and strings assert isinstance( clmm.GalaxyCluster( - unique_id=1, ra=161.3, dec=34.0, z=0.3, galcat=GCData(), coordinate_system="pixel" + unique_id=1, ra=161.3, dec=34.0, z=0.3, galcat=GCData(), coordinate_system="euclidean" ).unique_id, str, ) assert isinstance( clmm.GalaxyCluster( - unique_id="1", ra=161.3, dec=34.0, z=0.3, galcat=GCData(), coordinate_system="pixel" + unique_id="1", ra=161.3, dec=34.0, z=0.3, galcat=GCData(), coordinate_system="euclidean" ).unique_id, str, ) @@ -513,7 +513,7 @@ def test_coordinate_system(): [ra_source, dec_source, shear1, shear2_pixel, z_src], names=("ra", "dec", "e1", "e2", "z"), ), - coordinate_system="pixel", + coordinate_system="euclidean", ) cl_sky = clmm.GalaxyCluster( unique_id="test", @@ -523,7 +523,7 @@ def test_coordinate_system(): galcat=GCData( [ra_source, dec_source, shear1, shear2_sky, z_src], names=("ra", "dec", "e1", "e2", "z") ), - coordinate_system="sky", + coordinate_system="celestial", ) cl_pixel.compute_tangential_and_cross_components() diff --git a/tests/test_mockdata.py b/tests/test_mockdata.py index 6297b8c0e..7bf14bbbb 100644 --- a/tests/test_mockdata.py +++ b/tests/test_mockdata.py @@ -264,17 +264,13 @@ def test_shapenoise(): # Verify that the shape noise is Gaussian around 0 (for the very small shear here) sigma = 0.25 - data = mock.generate_galaxy_catalog( - 10**12.0, 0.3, 4, cosmo, 0.8, ngals=50000, shapenoise=sigma - ) + data = mock.generate_galaxy_catalog(10**12.0, 0.3, 4, cosmo, 0.8, ngals=50000, shapenoise=sigma) # Check that there are no galaxies with |e|>1 assert_equal(np.count_nonzero((data["e1"] > 1) | (data["e1"] < -1)), 0) assert_equal(np.count_nonzero((data["e2"] > 1) | (data["e2"] < -1)), 0) # Check that shape noise is Guassian with correct std dev bins = np.arange(-1, 1.1, 0.1) - gauss = ( - 5000 * np.exp(-0.5 * (bins[:-1] + 0.05) ** 2 / sigma**2) / (sigma * np.sqrt(2 * np.pi)) - ) + gauss = 5000 * np.exp(-0.5 * (bins[:-1] + 0.05) ** 2 / sigma**2) / (sigma * np.sqrt(2 * np.pi)) 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) @@ -289,11 +285,11 @@ 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="pixel" + 10**15.0, 0.3, 4, cosmo, 0.8, ngals=50000, 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="sky" + 10**15.0, 0.3, 4, cosmo, 0.8, ngals=50000, coordinate_system="celestial" ) assert_equal(pixel_data["ra"], sky_data["ra"])