Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue/591/triaxiality: Build scripts in examples/triaxiality #603

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
dd3fd10
built a folder examples/triaxiality, added a readme file inside
shenmingfu Jul 18, 2023
656b37b
added mock catalog info into readme file
shenmingfu Jul 18, 2023
740bae1
added mock catalogs, added a notebook for visualization
shenmingfu Jul 18, 2023
5d279b6
test notebook plotting delta sigma vs radius
akumgill Jul 19, 2023
0a70528
Model predictions for Quadrupole lensing
rkrishnan2912 Jul 19, 2023
b38d2c6
updating notebook with gamma sign and cos term sign
akumgill Jul 19, 2023
f1d118f
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
akumgill Jul 19, 2023
2b31613
code cleanup / removing dupe loops
akumgill Jul 19, 2023
a8c2e32
put functions for data analysis into script file
rancesol Jul 20, 2023
167f3c3
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 20, 2023
7e5999d
Comparison of two implementations
rkrishnan2912 Jul 21, 2023
ae56e5f
adding fitting files
rancesol Jul 22, 2023
5461145
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 22, 2023
0a020c5
update fitting notebook
rancesol Jul 22, 2023
e742f2a
fixed emcee fitting error due to inconcistent parameter values
rancesol Jul 29, 2023
e517e13
cleaning up repeated data files
rancesol Jul 29, 2023
0ee57e9
update fitting nnotebook to account for corrected monopole term
rancesol Aug 16, 2023
f2da93b
MCMC fitting for elliptical lens model
rkrishnan2912 Aug 25, 2023
5fdf268
Fixed the fitting modules
rkrishnan2912 Jul 15, 2024
54f0299
Added triaxiality theory functions in func_layer.py
Jul 16, 2024
6647498
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
Jul 16, 2024
da083fc
some changes to initialize triaxiality functions
Jul 16, 2024
3b0b7c3
Merge branch 'main' into issue/591/triaxiality
Jul 16, 2024
7fc4d2d
added triaxial functions to class modules
rancesol Jul 16, 2024
8e7865f
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 16, 2024
c8f1d61
added quadrupole calculation plus major axis calculation
tae-h-shin Jul 16, 2024
04951c8
fixed conflicts
tae-h-shin Jul 16, 2024
a453bf7
documentation updated
Jul 16, 2024
a40ff56
add triaxial functions
rancesol Jul 16, 2024
c47ea78
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 16, 2024
9134c90
typo correction
rancesol Jul 17, 2024
3dd3d64
Minor comments and cosmetic changres
Jul 17, 2024
2f39979
Data operation-functions for triaxiality added to dataops
Jul 17, 2024
46067b8
edited galaxycluster.py to incorporate quadrupole lensing
tae-h-shin Jul 17, 2024
8cef454
edited galaxycluster.py to incorporate quadrupole lensing
tae-h-shin Jul 17, 2024
2223c3b
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 17, 2024
8525ba7
changed dataops/__init__.py for quadrupole
tae-h-shin Jul 17, 2024
40358a7
changed galaxycluser.py for quadrupole
tae-h-shin Jul 17, 2024
ad70d4e
Edited a minor typo in code in dataops/__init__.py
Jul 18, 2024
9ba290a
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
Jul 18, 2024
28b7016
argument and backend validation
rancesol Jul 18, 2024
2a196f7
Edited a small typo in dataops/__init__.py
Jul 18, 2024
3e90071
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 18, 2024
92586b3
initial edit to clusterensemble.py for quadrupole
tae-h-shin Jul 18, 2024
e4130d3
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 18, 2024
ce51076
finished adding quadrupole operations to clusterensemble.py
tae-h-shin Jul 18, 2024
243bf0f
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 18, 2024
a0e060a
cleaned up triaxiality functions
rancesol Jul 18, 2024
3b12ff1
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 18, 2024
b722e79
Minor addition to doc string in func_layer.py
Jul 18, 2024
50ce90b
Reformatting func_layer.py
Jul 18, 2024
e6cbf2f
delted three redundant functions from dataopts
tae-h-shin Jul 18, 2024
af3d466
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 18, 2024
8088606
fixed formating
rancesol Jul 18, 2024
6d18127
add triaxial tests
rancesol Jul 18, 2024
87d7547
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 18, 2024
1d4f39f
cosmetic changes to make pylint happy and added one test
tae-h-shin Jul 18, 2024
175e7e6
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 18, 2024
17806f6
fix 'test_triaxial' arguments
rancesol Jul 18, 2024
8a90ad3
correct arments for simpson integration function
rancesol Jul 18, 2024
0e97a3b
Pylint corrections to func_layer.py and __init__.py
Jul 18, 2024
b63aa75
triaxial test added for object-oriented and functional form comparison
rancesol Jul 18, 2024
b619780
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 18, 2024
7090659
pylint is finally happy
tae-h-shin Jul 18, 2024
c23cd98
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
tae-h-shin Jul 18, 2024
51fd52c
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 19, 2024
ea8cdd5
Updates to the interpolation and sampling in func_layer.py theory fun…
Jul 19, 2024
f0eea39
Merge branch 'issue/591/triaxiality' of https://github.com/LSSTDESC/C…
rancesol Jul 19, 2024
2d5aa5b
issue/627/testskypixelcoords: New notebook to test coordinate system …
ts485 Jul 19, 2024
3082315
minor edits to triaxial functs to bring into agreement with naming sc…
rancesol Jul 23, 2024
425a3e8
edits to triaxial functs to bring into agreement with func_layer.py
rancesol Jul 23, 2024
5d0f007
added tests for triaxial functions
rancesol Jul 23, 2024
b346a88
ran black on files
rancesol Jul 23, 2024
c4f4290
removed unused function
rancesol Jul 23, 2024
23bd956
remove obsolete function from test
rancesol Jul 23, 2024
424ced9
finished test_dataops.py
tae-h-shin Jul 24, 2024
530496f
finished test_galaxycluster.py
tae-h-shin Jul 26, 2024
4d873f8
finished test_clusterensemble.py
tae-h-shin Jul 26, 2024
704faae
add triaxial functions from func_layer
rancesol Jul 29, 2024
a638d6d
Merge branch 'main' into issue/591/triaxiality
rancesol Jul 30, 2024
8cfea7c
raise value error if term is incorrect for triaxial calculations
rancesol Jul 30, 2024
f0212ec
minor edit
rancesol Jul 30, 2024
30e824d
fixed local variables in triaxial calculations
rancesol Jul 30, 2024
c11e6fe
fixed number of local variables in triaxial calculations
rancesol Jul 30, 2024
e55877f
pylint ignore number of instances (8/7)
rancesol Jul 30, 2024
94b751e
minor formating edit
rancesol Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# CLMM
[![Build and Check](https://github.com/LSSTDESC/CLMM/workflows/Build%20and%20Check/badge.svg)](https://github.com/LSSTDESC/CLMM/actions?query=workflow%3A%22Build+and+Check%22)
[![Coverage Status](https://coveralls.io/repos/github/LSSTDESC/CLMM/badge.svg?branch=main)](https://coveralls.io/github/LSSTDESC/CLMM?branch=main)
Expand Down Expand Up @@ -110,6 +109,7 @@ the `CCL` publication be cited. See details
The `Cluster Toolkit` documentation can be found
[here](https://cluster-toolkit.readthedocs.io/en/latest/#).

The data for the notebook test_coordinate.ipynb is available at https://www.dropbox.com/scl/fo/dwsccslr5iwb7lnkf8jvx/AJkjgFeemUEHpHaZaHHqpAg?rlkey=efbtsr15mdrs3y6xsm7l48o0r&st=xb58ap0g&dl=0

# Contributing to CLMM <a name="contributing"></a>

Expand Down
6 changes: 6 additions & 0 deletions clmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
Modeling,
Cosmology,
)
from .theory.func_layer import (
compute_delta_sigma_4theta_triaxiality,
compute_delta_sigma_const_triaxiality,
compute_delta_sigma_excess_triaxiality,
)

from . import support

__version__ = "1.12.5"
271 changes: 232 additions & 39 deletions clmm/clusterensemble.py

Large diffs are not rendered by default.

125 changes: 123 additions & 2 deletions clmm/dataops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings
import numpy as np
import scipy
from scipy.stats import binned_statistic
from astropy.coordinates import SkyCoord
from astropy import units as u
from ..gcdata import GCData
Expand All @@ -15,6 +16,7 @@
_validate_ra,
_validate_dec,
_validate_is_deltasigma_sigma_c,
_validate_include_quadrupole_phi_major,
_validate_coordinate_system,
)
from ..redshift import (
Expand All @@ -35,6 +37,9 @@ def compute_tangential_and_cross_components(
geometry="curve",
is_deltasigma=False,
sigma_c=None,
include_quadrupole=False,
phi_major=None,
info_mem=None,
validate_input=True,
):
r"""Computes tangential- and cross- components for shear or ellipticity
Expand Down Expand Up @@ -74,6 +79,14 @@ def compute_tangential_and_cross_components(
g_t =& -\left( g_1\cos\left(2\phi\right)+g_2\sin\left(2\phi\right)\right)\\
g_x =& g_1 \sin\left(2\phi\right)-g_2\cos\left(2\phi\right)

The quadrupole ellipticity/shear components, :math:`g_4theta' and :math:`g_const',
are also calculated using the two ellipticity/shear components :math:`g_1' and :math:`g_2'
of the source galaxies, following Eq.31 and Eq.34 in Shin et al. (2018), arXiv:1705.11167.

.. math::
g_4theta =& \left( g_1\cos\left(4\phi\right)+g_2\sin\left(4\phi\right)\right)\\
g_const =& g_1

Finally, if the critical surface density (:math:`\Sigma_\text{crit}`) is provided, an estimate
of the excess surface density :math:`\widehat{\Delta\Sigma}` is obtained from

Expand Down Expand Up @@ -111,6 +124,20 @@ def compute_tangential_and_cross_components(
sigma_c : None, array_like
Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`.
Used only when is_deltasigma=True.
include_quadrupole: bool
If `True`, the quadrupole shear components (g_4theta, g_const; Shin+2018) are calculated
instead of g_t and g_x
phi_major : float, optional
the direction of the major axis of the input cluster in the unit of radian.
only needed when `include_quadrupole` is `True`.
Users could choose to provide ra_mem, dec_mem and weight_mem instead of this quantity.
info_mem : list of array, optional
RAs, DECs and weights of the member galaxies of the input cluster,
to calcualte the direction of the major axis of the cluster.
Only needed when `include_quadrupole` is `True` and `phi_major` is not provided.
The shape must be in `[ra_mem,dec_mem,weight_mem]`, where each element is an array.
The weights could be `1` (no weights) or
`membership probability (p_mem)` or any user choice.
validate_input: bool
Validade each input argument

Expand All @@ -122,6 +149,11 @@ def compute_tangential_and_cross_components(
Tangential shear (or assimilated quantity) for each source galaxy
cross_component: array_like
Cross shear (or assimilated quantity) for each source galaxy
IF include_quadrupole:
4theta_component: array_like
4theta shear component (or assimilated quantity) for each source galaxy
const_component: array_like
constant shear component (or assimilated quantity) for each source galaxy
"""
# pylint: disable-msg=too-many-locals
# Note: we make these quantities to be np.array so that a name is not passed from astropy
Expand All @@ -134,6 +166,8 @@ def compute_tangential_and_cross_components(
validate_argument(locals(), "shear1", "float_array")
validate_argument(locals(), "shear2", "float_array")
validate_argument(locals(), "geometry", str)
validate_argument(locals(), "is_deltasigma", bool)
validate_argument(locals(), "include_quadrupole", bool)
validate_argument(locals(), "sigma_c", "float_array", none_ok=True)
_validate_coordinate_system(locals(), "coordinate_system", str)
ra_source_, dec_source_, shear1_, shear2_ = arguments_consistency(
Expand All @@ -142,6 +176,9 @@ def compute_tangential_and_cross_components(
prefix="Tangential- and Cross- shape components sources",
)
_validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c)
_validate_include_quadrupole_phi_major(include_quadrupole, phi_major, info_mem)
validate_argument(locals(), "phi_major", float, none_ok=True)
validate_argument(locals(), "info_mem", list, none_ok=True)
elif np.iterable(ra_source):
ra_source_, dec_source_, shear1_, shear2_ = (
np.array(col) for col in [ra_source, dec_source, shear1, shear2]
Expand All @@ -167,12 +204,32 @@ def compute_tangential_and_cross_components(
# Compute the tangential and cross shears
tangential_comp = _compute_tangential_shear(shear1_, shear2_, phi)
cross_comp = _compute_cross_shear(shear1_, shear2_, phi)

# If the is_deltasigma flag is True, multiply the results by Sigma_crit.
if sigma_c is not None:
_sigma_c_arr = np.array(sigma_c)
tangential_comp *= _sigma_c_arr
cross_comp *= _sigma_c_arr

if include_quadrupole:
if (phi_major is None) and (info_mem is None):
raise ValueError("Either phi_major or (ra_mem, dec_mem, weight_mem) should be provided")
phi_major_ = phi_major
if phi_major_ is None:
# info_mem=[ra_mem,dec_mem,weight_mem]
phi_major_ = _calculate_major_axis(
ra_lens, dec_lens, info_mem[0], info_mem[1], info_mem[2]
)
rotated_phi = phi - phi_major_
rotated_shear1, rotated_shear2 = _rotate_shear(shear1_, shear2_, phi_major_)
# Compute the quadrupole shear components
four_theta_comp = _compute_4theta_shear(rotated_shear1, rotated_shear2, rotated_phi)
const_comp = rotated_shear1
# If the is_deltasigma flag is True, multiply the results by Sigma_crit.
if sigma_c is not None:
four_theta_comp *= _sigma_c_arr
const_comp *= _sigma_c_arr
if include_quadrupole:
return angsep, tangential_comp, cross_comp, four_theta_comp, const_comp
return angsep, tangential_comp, cross_comp


Expand Down Expand Up @@ -445,6 +502,51 @@ def _compute_lensing_angles_astropy(
return angsep, phi


def _calculate_major_axis(ra_lens_, dec_lens_, ra_mem_, dec_mem_, weight_mem_):
r"""Compute the major axis of a given cluster from the distribution of
its member galaxies using the position second moments.

The computation is done according to Eq. 5-10 of Shin et al. 2018, arXiv:1705.11167

Current implementation assumes the +RA direction is aligned with +x direction.

For extended descriptions of parameters, see `compute_shear()` documentation.
"""
ind_bcg = (np.array(ra_mem_) == ra_lens_) * (np.array(dec_mem_) == dec_lens_)
sk_lens = SkyCoord(ra_lens_ * u.deg, dec_lens_ * u.deg, frame="icrs")
sk_mem = SkyCoord(
np.array(ra_mem_)[~ind_bcg] * u.deg, np.array(dec_mem_)[~ind_bcg] * u.deg, frame="icrs"
)
position_angle_mem = np.array(sk_lens.position_angle(sk_mem).radian + np.pi / 2.0)
separation_mem = np.array(sk_lens.separation(sk_mem).degree)
x_mem = separation_mem * np.cos(position_angle_mem)
y_mem = separation_mem * np.sin(position_angle_mem)
distance_weight_mem = 1.0 / (separation_mem**2)
weight_total_mem = np.array(weight_mem_) * distance_weight_mem
sum_weight_total_mem = np.sum(weight_total_mem)
# Calcualte second moments of the member galaxies
ixx = np.sum(x_mem**2 * weight_total_mem) / sum_weight_total_mem
iyy = np.sum(y_mem**2 * weight_total_mem) / sum_weight_total_mem
ixy = np.sum(x_mem * y_mem * weight_total_mem) / sum_weight_total_mem
# Transformation of the second moments to the direction of the major axis
phi_major = np.arctan2(2.0 * ixy, ixx - iyy) / 2.0
return phi_major


def _rotate_shear(shear1, shear2, phi_major):
r"""Rotate shear components into the coordinate where +x axis is aligned with
the cluster major axis.

.. math::
g_rotated = g * \exp\left(-2i\phi\right)

For extended descriptions of parameters, see `compute_shear()` documentation.
"""
shear_vec = shear1 + shear2 * 1.0j
rotated_shear_vec = shear_vec * np.exp(-2.0j * phi_major)
return np.real(rotated_shear_vec), np.imag(rotated_shear_vec)


def _compute_tangential_shear(shear1, shear2, phi):
r"""Compute the tangential shear given the two shears and azimuthal positions for
a single source or list of sources.
Expand Down Expand Up @@ -474,6 +576,25 @@ def _compute_cross_shear(shear1, shear2, phi):
return shear1 * np.sin(2.0 * phi) - shear2 * np.cos(2.0 * phi)


def _compute_4theta_shear(shear1, shear2, phi):
r"""Compute the 4theta component of the quadrupole shear given the two shear components and
azimuthal positions for a single source or list of sources.

We compute the tangential shear following Eq. 31 of Shin et al. 2018, arXiv:1705.11167

.. math::
g_4theta = g_1\cos\left(4\phi\right)+g_2\sin\left(4\phi\right)

Note that here `\phi` is the position angle of the source galaxies
with respect to the major axis of the cluster.
Also, `shear1` and `shear2` are measured in the coordinate where
the +x axis is aligned with the major axis of the cluster.

For extended descriptions of parameters, see `compute_shear()' documentation.
"""
return shear1 * np.cos(4.0 * phi) + shear2 * np.sin(4.0 * phi)


def make_radial_profile(
components,
angsep,
Expand Down Expand Up @@ -613,7 +734,7 @@ def make_stacked_radial_profile(angsep, weights, components):
Parameters
----------
angsep: 2d array
Transvesal distances corresponding to each object with shape `n_obj, n_rad_bins`.
Transversal distances corresponding to each object with shape `n_obj, n_rad_bins`.
weights: 2d array
Weights corresponding to each objects with shape `n_obj, n_rad_bins`.
components: list of 2d arrays
Expand Down
Loading
Loading