Skip to content

Commit

Permalink
Fixed all the documentation for coordinate_system and changed names f…
Browse files Browse the repository at this point in the history
…rom 'pixel'/'sky' to 'euclidean'/'celestial'
  • Loading branch information
Caio Lima de Oliveira committed Jul 18, 2024
1 parent d36a771 commit c84b83b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 53 deletions.
21 changes: 12 additions & 9 deletions clmm/dataops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
-------
Expand All @@ -392,15 +392,15 @@ 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")
return angsep, phi


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.
Expand All @@ -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
-------
Expand All @@ -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

Expand Down
11 changes: 4 additions & 7 deletions clmm/galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions clmm/support/mock_data.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions clmm/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ 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:
* 'int_array' - interger, interger array
* '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'.")
4 changes: 2 additions & 2 deletions examples/demo_mock_cluster.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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\"."
]
},
{
Expand All @@ -139,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"coordinate_system = \"pixel\"\n"
"coordinate_system = \"euclidean\"\n"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions tests/test_dataops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
32 changes: 16 additions & 16 deletions tests/test_galaxycluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

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

0 comments on commit c84b83b

Please sign in to comment.