Skip to content

Commit

Permalink
Merge branch 'issue/ccl_v3' into GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
hsinfan1996 authored Sep 15, 2023
2 parents fab71cd + f3b22c7 commit f6bfe95
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 265 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
conda install -c conda-forge cmake swig
git clone https://github.com/LSSTDESC/CCL
cd CCL
git checkout v3.0.0
pip install .
- name: Analysing the code with pylint
run: |
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To create a specific conda environment for CLMM, we recommend you to check the b

### Theory backend installation
First, choose and install a theory backend for CLMM.
This can be CCL (versions between 2.6.0 and 2.7.1.dev9+g1a351df6),
This can be CCL (versions between 2.7.1.dev10+gf81b59a4 and 3),
NumCosmo (v0.15 or later),
or cluster_toolkit and they are installable as follows.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CLMM requires Python version 3.8 or later. CLMM has the following dependencies:
For the theoretical predictions of the signal, CLMM relies on existing libraries and **at least one of the following must be installed as well**:

- [cluster-toolkit](https://cluster-toolkit.readthedocs.io/en/latest/)
- [CCL](https://ccl.readthedocs.io/en/latest/) (versions between 2.6.0 and 2.7.1.dev9+g1a351df6)
- [CCL](https://ccl.readthedocs.io/en/latest/) (versions between 2.7.1.dev10+gf81b59a4 and 3)
- [NumCosmo](https://numcosmo.github.io/) (v0.15 or later)


Expand Down
2 changes: 1 addition & 1 deletion clmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
)
from . import support

__version__ = "1.8.2"
__version__ = "1.9.0"
2 changes: 1 addition & 1 deletion clmm/cosmology/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _eval_sigma_crit_core(self, z_len, z_src):
a_len = self.get_a_from_z(z_len)
a_src = self.get_a_from_z(z_src)

return self.be_cosmo.sigma_critical(a_len, a_src) * self.cor_factor
return self.be_cosmo.sigma_critical(a_lens=a_len, a_source=a_src) * self.cor_factor

def _eval_linear_matter_powerspectrum(self, k_vals, redshift):
return ccl.linear_matter_power(self.be_cosmo, k_vals, self.get_a_from_z(redshift))
4 changes: 2 additions & 2 deletions clmm/theory/_ccl_supported_versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""@file _ccl_supported_versions.py
Versions of CCL supported by the current CLMM version
"""
VMIN = '2.6.0'
VMAX = '2.7.1.dev9+g1a351df6'
VMIN = "2.7.1.dev10+gf81b59a4"
VMAX = "3"
32 changes: 18 additions & 14 deletions clmm/theory/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ class CCLCLMModeling(CLMModeling):
backend: str
Name of the backend being used
massdef : str
Profile mass definition (`mean`, `critical`, `virial` - letter case independent)
Profile mass definition ("mean", "critical", "virial" - letter case independent)
delta_mdef : int
Mass overdensity definition.
halo_profile_model : str
Profile model parameterization (`nfw`, `einasto`, `hernquist` - letter case independent)
Profile model parameterization ("nfw", "einasto", "hernquist" - letter case independent)
cosmo: Cosmology
Cosmology object
hdpm: Object
Expand Down Expand Up @@ -94,12 +94,22 @@ def __init__(
self.set_halo_density_profile(halo_profile_model, massdef, delta_mdef)
self.set_cosmo(None)

def _set_projected_quad(self, use_projected_quad):
if hasattr(self.hdpm, "projected_quad"):
self.hdpm_opts["einasto"]["projected_quad"] = use_projected_quad
self._update_halo_density_profile()
else:
raise NotImplementedError("projected_quad is not available on this version of CCL.")

# Functions implemented by child class

def _update_halo_density_profile(self):
"""updates halo density profile with set internal properties"""
# prepare mdef object
self.mdef = ccl.halos.MassDef(self.delta_mdef, self.mdef_dict[self.massdef])
if self.massdef == "virial":
self.mdef = ccl.halos.MassDef("vir", self.mdef_dict[self.massdef])
else:
self.mdef = ccl.halos.MassDef(self.delta_mdef, self.mdef_dict[self.massdef])
# setting concentration (also updates hdpm)
self.cdelta = self.cdelta if self.hdpm else 4.0 # ccl always needs an input concentration

Expand All @@ -113,13 +123,9 @@ def _get_mass(self):

def _set_concentration(self, cdelta):
"""set concentration. Also sets/updates hdpm"""
# pylint: disable=protected-access
self.conc = ccl.halos.ConcentrationConstant(c=cdelta, mdef=self.mdef)
if hasattr(ccl, 'UnlockInstance'):
ccl.UnlockInstance.Funlock(type(self.mdef), "_concentration_init", True)
self.mdef._concentration_init(self.conc)
self.conc = ccl.halos.ConcentrationConstant(c=cdelta, mass_def=self.mdef)
self.hdpm = self.hdpm_dict[self.halo_profile_model](
self.conc, **self.hdpm_opts[self.halo_profile_model]
concentration=self.conc, mass_def=self.mdef, **self.hdpm_opts[self.halo_profile_model]
)
self.hdpm.update_precision_fftlog(padding_lo_fftlog=1e-4, padding_hi_fftlog=1e3)

Expand All @@ -140,7 +146,7 @@ def _get_einasto_alpha(self, z_cl=None):
a_cl = 1 # a_cl does not matter in this case
else:
a_cl = self.cosmo.get_a_from_z(z_cl)
return self.hdpm._get_alpha(self.cosmo.be_cosmo, self.__mdelta_cor, a_cl, self.mdef)
return self.hdpm._get_alpha(self.cosmo.be_cosmo, self.__mdelta_cor, a_cl)

def _eval_3d_density(self, r3d, z_cl):
"""eval 3d density"""
Expand Down Expand Up @@ -188,7 +194,6 @@ def _call_ccl_profile_lens(self, ccl_hdpm_func, radius, z_lens, ndim=2):
radius / a_lens,
self.__mdelta_cor,
a_lens,
self.mdef,
)
* self.cor_factor
/ a_lens**ndim
Expand All @@ -203,9 +208,8 @@ def _call_ccl_profile_lens_src(self, ccl_hdpm_func, radius, z_lens, z_src):
self.cosmo.be_cosmo,
radius / a_lens,
self.__mdelta_cor,
a_lens,
a_src,
self.mdef,
a_lens=a_lens,
a_source=a_src,
)


Expand Down
11 changes: 5 additions & 6 deletions clmm/theory/cluster_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _assert_correct_type_ct(arg):
Returns
-------
scale_factor : array_like
scale_factor : numpy.ndarray
Scale factor
"""
if np.isscalar(arg):
Expand All @@ -41,11 +41,11 @@ class CTCLMModeling(CLMModeling):
backend: str
Name of the backend being used
massdef : str
Profile mass definition (`mean`, `critical`, `virial` - letter case independent)
Profile mass definition ("mean", "critical" - letter case independent)
delta_mdef : int
Mass overdensity definition.
halo_profile_model : str
Profile model parameterization (`nfw`, `einasto`, `hernquist` - letter case independent)
Profile model parameterization ("nfw" - letter case independent)
cosmo: Cosmology
Cosmology object
hdpm: Object
Expand Down Expand Up @@ -85,7 +85,6 @@ def __init__(
self.mdef_dict = {
"mean": self.cosmo.get_E2Omega_m,
"critical": self.cosmo.get_E2,
"virial": self.cosmo.get_E2,
}

self.set_halo_density_profile(halo_profile_model, massdef, delta_mdef)
Expand Down Expand Up @@ -145,7 +144,7 @@ def _eval_surface_density(self, r_proj, z_cl):
) # pc**-2 to Mpc**-2

def _eval_mean_surface_density(self, r_proj, z_cl):
r"""Computes the mean value of surface density inside radius r_proj
r"""Computes the mean value of surface density inside radius `r_proj`
Parameters
----------
Expand All @@ -156,7 +155,7 @@ def _eval_mean_surface_density(self, r_proj, z_cl):
Returns
-------
array_like, float
numpy.ndarray, float
Excess surface density in units of :math:`M_\odot\ Mpc^{-2}`.
Note
Expand Down
29 changes: 18 additions & 11 deletions clmm/theory/func_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# pylint: disable=invalid-name
# Thin functonal layer on top of the class implementation of CLMModeling .
# The functions expect a global instance of the actual CLMModeling named
# `_modeling_object'.
# "_modeling_object".

import numpy as np

Expand Down Expand Up @@ -109,6 +109,7 @@ def compute_surface_density(
massdef="mean",
alpha_ein=None,
verbose=False,
use_projected_quad=False,
validate_input=True,
):
r"""Computes the surface mass density
Expand Down Expand Up @@ -154,6 +155,10 @@ def compute_surface_density(
verbose : boolean, optional
If True, the Einasto slope (alpha_ein) is printed out. Only available for the NC and CCL
backends.
use_projected_quad : bool
Only available for Einasto profile with CCL as the backend. If True, CCL will use
quad_vec instead of default FFTLog to calculate the surface density profile.
Default: False
validate_input : bool, optional
If True (default), the types of the arguments are checked before proceeding.
Expand All @@ -176,6 +181,8 @@ def compute_surface_density(
_modeling_object.set_mass(mdelta)
if halo_profile_model == "einasto" or alpha_ein is not None:
_modeling_object.set_einasto_alpha(alpha_ein)
if halo_profile_model == "einasto" and _modeling_object.backend=="ccl":
_modeling_object.set_projected_quad(use_projected_quad)

sigma = _modeling_object.eval_surface_density(r_proj, z_cl, verbose=verbose)

Expand Down Expand Up @@ -358,7 +365,7 @@ def compute_excess_surface_density_2h(
.. math::
\Delta\Sigma_{\text{2h}}(R) = \frac{\rho_m(z)b(M)}{(1 + z)^3D_A(z)^2}
\int\frac{ldl}{(2\pi)} P_{\rm mm}(k_l, z)J_2(l\theta)
\int\frac{ldl}{(2\pi)} P_{\text{mm}}(k_l, z)J_2(l\theta)
where
Expand Down Expand Up @@ -424,13 +431,13 @@ def compute_surface_density_2h(
r"""Computes the 2-halo term surface density from eq.(13) of Oguri & Hamana (2011)
.. math::
\Sigma_{\rm 2h}(R) = \frac{\rho_m(z)b(M)}{(1 + z)^3D_A(z)^2} \int\frac{ldl}{(2\pi)}
P_{\rm mm}(k_l, z)J_0(l\theta)
\Sigma_{\text{2h}}(R) = \frac{\rho_\text{m}(z)b(M)}{(1 + z)^3D_A(z)^2}
\int\frac{ldl}{(2\pi)}P_{\text{mm}}(k_l, z)J_0(l\theta)
where
.. math::
k_l = \frac{l}{D_A(z)(1 +z)}
k_l = \frac{l}{D_A(z)(1 + z)}
and :math:`b(M)` is the halo bias
Expand Down Expand Up @@ -481,14 +488,14 @@ def compute_critical_surface_density_eff(cosmo, z_cluster, pzbins, pzpdf, valida
r"""Computes the 'effective critical surface density'
.. math::
\langle \Sigma_{\rm crit}^{-1}\rangle^{-1} = \left(\int \frac{1}{\Sigma_{\rm crit}(z)}
p(z) dz\right)^{-1}
\langle \Sigma_{\text{crit}}^{-1}\rangle^{-1} =
\left(\int \frac{1}{\Sigma_{\text{crit}}(z)}p(z) \mathrm{d}z\right)^{-1}
where :math:`p(z)` is the source photoz probability density function.
This comes from the maximum likelihood estimator for evaluating a :math:`\Delta\Sigma`
profile.
For the standard :math:`\Sigma_{\rm crit}(z)` definition, use the `eval_sigma_crit` method of
For the standard :math:`\Sigma_{\text{crit}}(z)` definition, use the `eval_sigma_crit` method of
the CLMM cosmology object.
Parameters
Expand Down Expand Up @@ -841,9 +848,9 @@ def compute_reduced_tangential_shear(
massdef : str, optional
Profile mass definition, with the following supported options (letter case independent):
* `mean` (default);
* `critical` - not in cluster_toolkit;
* `virial` - not in cluster_toolkit;
* 'mean' (default);
* 'critical' - not in cluster_toolkit;
* 'virial' - not in cluster_toolkit;
alpha_ein : float, None, optional
If `halo_profile_model=='einasto'`, set the value of the Einasto slope.
Expand Down
14 changes: 7 additions & 7 deletions clmm/theory/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def compute_rdelta(mdelta, redshift, cosmo, massdef="mean", delta_mdef=200):
cosmo : clmm.Cosmology
Cosmology object
massdef : str, None
Profile mass definition (`mean`, `critical`, `virial`).
Profile mass definition ("mean", "critical", "virial").
delta_mdef : int, None
Mass overdensity definition.
Expand Down Expand Up @@ -151,11 +151,11 @@ def compute_profile_mass_in_radius(
cdelta : float
Concentration of the profile.
massdef : str, None
Profile mass definition (`mean`, `critical`, `virial`).
Profile mass definition ("mean", "critical", "virial").
delta_mdef : int, None
Mass overdensity definition.
halo_profile_model : str
Profile model parameterization (`nfw`, `einasto`, `hernquist`).
Profile model parameterization ("nfw", "einasto", "hernquist").
alpha : float, None
Einasto slope, required when `halo_profile_model='einasto'`.
Expand Down Expand Up @@ -209,19 +209,19 @@ def convert_profile_mass_concentration(
cosmo : clmm.Cosmology
Cosmology object
massdef : str, None
Input profile mass definition (`mean`, `critical`, `virial`).
Input profile mass definition ("mean", "critical", "virial").
delta_mdef : int, None
Input mass overdensity definition.
halo_profile_model : str, None
Input profile model parameterization (`nfw`, `einasto`, `hernquist`).
Input profile model parameterization ("nfw", "einasto", "hernquist").
massdef2 : str, None
Profile mass definition to convert to (`mean`, `critical`, `virial`).
Profile mass definition to convert to ("mean", "critical", "virial").
If None, `massdef2=massdef`.
delta_mdef2 : int, None
Mass overdensity definition to convert to.
If None, `delta_mdef2=delta_mdef`.
halo_profile_model2 : str, None
Profile model parameterization to convert to (`nfw`, `einasto`, `hernquist`).
Profile model parameterization to convert to ("nfw", "einasto", "hernquist").
If None, `halo_profile_model2=halo_profile_model`.
alpha : float, None
Input Einasto slope when `halo_profile_model='einasto'`.
Expand Down
4 changes: 2 additions & 2 deletions clmm/theory/numcosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class NumCosmoCLMModeling(CLMModeling):
backend: str
Name of the backend being used
massdef : str
Profile mass definition (`mean`, `critical`, `virial` - letter case independent)
Profile mass definition ("mean", "critical", "virial" - letter case independent)
delta_mdef : int
Mass overdensity definition.
halo_profile_model : str
Profile model parameterization (`nfw`, `einasto`, `hernquist` - letter case independent)
Profile model parameterization ("nfw", "einasto", "hernquist" - letter case independent)
cosmo: Cosmology
Cosmology object
hdpm: Object
Expand Down
Loading

0 comments on commit f6bfe95

Please sign in to comment.