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/592/ccl v3 #595

Merged
merged 44 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c835c49
Update for CCL v3
hsinfan1996 May 12, 2023
9fc9515
Merge branch 'main' into issue/ccl_v3
hsinfan1996 Jun 13, 2023
324d6d3
Update CCL version numbers
hsinfan1996 Jun 13, 2023
ffd3978
Update to CCL v3 api
hsinfan1996 Jun 13, 2023
212c7f1
Install latest CCL
hsinfan1996 Jun 13, 2023
9fd472e
Fix docs compiling
hsinfan1996 Jun 13, 2023
7bfcc04
Remove warning filter
hsinfan1996 Jun 13, 2023
cc9e339
Remove warning filter
hsinfan1996 Jun 13, 2023
f96f432
Update generate_einasto_hernquist_benchmarks_fromNC.ipynb
hsinfan1996 Jun 29, 2023
dcd95af
Update demo_mock_ensemble_realistic.ipynb
hsinfan1996 Jul 2, 2023
2607cda
Remove concentration from MassDef
hsinfan1996 Jul 2, 2023
963f82a
Fix profile name validation
hsinfan1996 Jul 28, 2023
6b58996
Add virial massdef properly
hsinfan1996 Jul 28, 2023
19a6be7
Update dicstrings
hsinfan1996 Jul 28, 2023
a9a2109
Update dicstrings
hsinfan1996 Jul 28, 2023
96b9446
Add virial massdef properly
hsinfan1996 Jul 28, 2023
a9885d2
Add use_projected_quad
hsinfan1996 Jul 28, 2023
ec50ff2
pylint
hsinfan1996 Jul 28, 2023
8d46860
Add tests; Minor fixes
hsinfan1996 Aug 6, 2023
ea68986
Fix docstrings
hsinfan1996 Aug 6, 2023
2b62712
Formatting
hsinfan1996 Aug 6, 2023
65ded8a
Remove virial massdef from CT backend
hsinfan1996 Aug 18, 2023
864337f
Update docstrings
hsinfan1996 Aug 20, 2023
f05a390
Naming consistency
hsinfan1996 Aug 23, 2023
1e6f164
Update tests
hsinfan1996 Aug 23, 2023
d291fcb
Rename arg to use_projected_quad
hsinfan1996 Aug 25, 2023
ffd891d
Add use_projected_quad to functional interface
hsinfan1996 Aug 25, 2023
d50fc2f
Use CCL v3.0.0 in GH Actions
hsinfan1996 Aug 25, 2023
2c44f0d
Demo how enable projected_quad
hsinfan1996 Aug 25, 2023
ce7003f
Fix typo in comments
hsinfan1996 Aug 25, 2023
2098ebf
Add title
hsinfan1996 Aug 25, 2023
761b738
Change python_requires to >=
hsinfan1996 Aug 26, 2023
64f19c5
Fix docstrings
hsinfan1996 Aug 26, 2023
71efa67
Fix docstrings
hsinfan1996 Aug 26, 2023
18e2387
update nbs to newer CLMM API
m-aguena Sep 7, 2023
54671eb
Update examples/other_compare_NFW_critical_massdef.ipynb
hsinfan1996 Sep 7, 2023
907b1bd
Update examples/Paper_v1.0/mass_bias_from_models.ipynb
hsinfan1996 Sep 7, 2023
2b2946f
Update examples/Paper_v1.0/validation_tests.ipynb
hsinfan1996 Sep 7, 2023
f3b22c7
Update version to 1.9.0
m-aguena Sep 15, 2023
7e30805
Update build_check.yml
hsinfan1996 Sep 15, 2023
c24857f
Update build_check.yml
hsinfan1996 Sep 15, 2023
11678c3
Update build_check.yml
hsinfan1996 Sep 15, 2023
439fca0
Revert build_check.yml
hsinfan1996 Sep 16, 2023
2efcd32
Use --override-channels
hsinfan1996 Sep 17, 2023
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 .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
conda install -c conda-forge cmake swig
git clone https://github.com/LSSTDESC/CCL
cd CCL
git checkout 1a351df
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/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