From cbab50d6e4eea26976ec1b76488b8314692e93c0 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 11:47:21 +0200 Subject: [PATCH 01/13] add order0 --- clmm/theory/parent_class.py | 43 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index a2870b12d..15a764e37 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1183,18 +1183,24 @@ def eval_reduced_tangential_shear( {1-\beta_s(z)\kappa_{\infty}}N(z)\text{d}z} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Same approach as in Weighing the Giants - III (equation 6 in - Applegate et al. 2014; https://arxiv.org/abs/1208.0605). `z_src_info` must be - 'beta': + * ``order0`` : approach with all sources at the same redshift (Eq. 5 in + `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - * 'order2' : Same approach as in Cluster Mass Calibration at High - Redshift (equation 12 in Schrabback et al. 2017; - https://arxiv.org/abs/1611.03866). - `z_src_info` must be 'beta': + * ``order1`` : Same approach as in Weighing the Giants - III (Eq. 6 in + `Applegate et al. 2014 `_, + Eq. A2.4 from `Seitz & Schneider 1997 `_). + + .. math:: + g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} + {1-\left<\beta_s\right>\kappa_{\infty}} + + * ``order2`` : Same approach as in Cluster Mass Calibration at High + Redshift (Eq. 12 in `Schrabback et al. 2017 `_, + Eq. 7 in `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} @@ -1202,15 +1208,17 @@ def eval_reduced_tangential_shear( \left(1+\left(\frac{\left<\beta_s^2\right>} {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right) + **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. + * ``delta_z_cut`` (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) verbose : bool, optional @@ -1264,22 +1272,27 @@ def eval_reduced_tangential_shear( "z_src", r_proj, ) - elif approx in ("order1", "order2"): - beta_s_mean = z_src[0] + elif approx in ("order0", "order1", "order2"): gammat_inf = self._eval_tangential_shear_core(r_proj, z_cl, z_src=self.z_inf) kappa_inf = self._eval_convergence_core(r_proj, z_cl, z_src=self.z_inf) - gt = beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) + beta_s_mean = z_src[0] + beta_s_square_mean = z_src[1] + if approx == "order1": + gt = beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean/beta_s_mean * kappa_inf) + else: # for order0 and order2 + gt = beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) if approx == "order2": - beta_s_square_mean = z_src[1] gt *= ( 1.0 + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) * beta_s_mean * kappa_inf ) + else: + raise ValueError(f"approx={approx} not valid, must be None or orderN (N=0,1,2)") return gt From 33e07a8828b8c073cdc7205c534ca6ad7e5d0919 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 11:56:40 +0200 Subject: [PATCH 02/13] update documentation --- clmm/theory/parent_class.py | 193 ++++++++++++++++++------------------ 1 file changed, 97 insertions(+), 96 deletions(-) diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 15a764e37..8e46cdf5d 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -509,13 +509,13 @@ def set_halo_density_profile(self, halo_profile_model="nfw", massdef="mean", del Parameters ---------- halo_profile_model: str - Halo mass profile, supported options are 'nfw', 'einasto', 'hernquist' + Halo mass profile, supported options are ``nfw``, ``einasto``, ``hernquist`` (letter case independent) massdef: str - Mass definition, supported options are 'mean', 'critical', 'virial' + Mass definition, supported options are ``mean``, ``critical``, ``virial`` (letter case independent) delta_mdef: int - Overdensity number. No effect if massdef='virial'. + Overdensity number. No effect if ``massdef='virial'``. """ # make case independent validate_argument(locals(), "massdef", str) @@ -618,7 +618,7 @@ def eval_3d_density(self, r3d, z_cl, verbose=False): return self._eval_3d_density(r3d=r3d, z_cl=z_cl) def eval_critical_surface_density_eff(self, z_len, pzbins, pzpdf): - r"""Computes the 'effective critical surface density' + r"""Computes the effective critical surface density .. math:: \langle \Sigma_{\rm crit}^{-1}\rangle^{-1} = @@ -699,7 +699,7 @@ def eval_surface_density(self, r_proj, z_cl, r_mis=None, mis_from_backend=False, def eval_mean_surface_density( self, r_proj, z_cl, r_mis=None, mis_from_backend=False, verbose=False ): - 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 ---------- @@ -896,17 +896,17 @@ def eval_tangential_shear(self, r_proj, z_cl, z_src, z_src_info="discrete", verb Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). + ``z_src_info`` (see below). z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an - array or all sources are at the same redshift when `z_src` is a float. + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an + array or all sources are at the same redshift when ``z_src`` is a float. - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -920,7 +920,7 @@ def eval_tangential_shear(self, r_proj, z_cl, z_src, z_src_info="discrete", verb {D_S}\frac{D_\infty}{D_{L,\infty}}\right)^2 \right\rangle verbose : bool, optional - If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and + If True, the Einasto slope (``alpha_ein``) is printed out. Only availble for the NC and CCL backends. Returns @@ -984,17 +984,17 @@ def eval_convergence(self, r_proj, z_cl, z_src, z_src_info="discrete", verbose=F Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). + ``z_src_info`` (see below). z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an - array or all sources are at the same redshift when `z_src` is a float. + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an + array or all sources are at the same redshift when ``z_src`` is a float. - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1065,14 +1065,14 @@ def _pdz_weighted_avg(self, core, pdz_func, r_proj, z_cl, integ_kwargs=None): Galaxy cluster redshift integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. + ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) Returns ------- @@ -1141,21 +1141,21 @@ def eval_reduced_tangential_shear( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). + ``z_src_info`` (see below). z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an - array or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an + array or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimentional function (Used when `approx=None`). + * ``distribution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimentional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1170,11 +1170,12 @@ def eval_reduced_tangential_shear( approx : str, optional Type of computation to be made for reduced tangential shears, options are: + **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, reduced - tangential shear at each value of `r_proj` is calculated as + * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, reduced + tangential shear at each value of ``r_proj`` is calculated as .. math:: g_t @@ -1219,7 +1220,7 @@ def eval_reduced_tangential_shear( * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) * ``delta_z_cut`` (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1281,8 +1282,8 @@ def eval_reduced_tangential_shear( beta_s_square_mean = z_src[1] if approx == "order1": - gt = beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean/beta_s_mean * kappa_inf) - else: # for order0 and order2 + gt = beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean / beta_s_mean * kappa_inf) + else: # for order0 and order2 gt = beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) if approx == "order2": gt *= ( @@ -1319,21 +1320,21 @@ def eval_magnification( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). + ``z_src_info`` (see below). z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an - array or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an + array or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimentional function (Used when `approx=None`). + * ``distribution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimentional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1349,10 +1350,10 @@ def eval_magnification( approx : str, optional Type of computation to be made for magnifications, options are: - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification - at each value of `r_proj` is calculated as + * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification + at each value of ``r_proj`` is calculated as .. math:: \mu @@ -1363,32 +1364,32 @@ def eval_magnification( -\left(\beta_s(z)\gamma_{\infty}\right)^2}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Uses the weak lensing approximation of the magnification with up to - first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``order1`` : Uses the weak lensing approximation of the magnification with up to + first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu \approx 1 + 2 \left<\beta_s\right>\kappa_{\infty} - * 'order2' : Uses the weak lensing approximation of the magnification with up to - second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``order2`` : Uses the weak lensing approximation of the magnification with up to + second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu \approx 1 + 2 \left<\beta_s\right>\kappa_{\infty} + 3 \left<\beta_s^2\right>\kappa_{\infty}^2 + \left<\beta_s^2\right>\gamma_{\infty}^2 + **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy - when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy + when performing the sum. (default=``None``) + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. + ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1477,23 +1478,23 @@ def eval_magnification_bias( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). + ``z_src_info`` (see below). alpha : float Slope of the cummulative number count of background sources at a given magnitude z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an - array or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an + array or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimentional function (Used when `approx=None`). + * ``distribution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimentional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1509,10 +1510,10 @@ def eval_magnification_bias( approx : str, optional Type of computation to be made for magnification biases, options are: - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification - bias at each value of `r_proj` is calculated as + * ``None`` (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification + bias at each value of ``r_proj`` is calculated as .. math:: \mu^{\alpha-1} @@ -1524,17 +1525,15 @@ def eval_magnification_bias( -\left(\beta_s(z)\gamma_{\infty}\right)^2\right)^{\alpha-1}}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Uses the weak lensing approximation of the magnification bias with up - to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``order1`` : Uses the weak lensing approximation of the magnification bias with up + to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu^{\alpha-1} \approx 1 + \left(\alpha-1\right)\left(2 \left<\beta_s\right>\kappa_{\infty}\right) - * 'order2' : Uses the weak lensing approximation of the magnification bias with up - to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``order2`` : Uses the weak lensing approximation of the magnification bias with up + to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu^{\alpha-1} \approx @@ -1545,16 +1544,18 @@ def eval_magnification_bias( &+ \left(2\alpha-1\right)\left(\alpha-1\right) \left(\left<\beta_s^2\right>\kappa_{\infty}^2\right) + **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. + ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1651,8 +1652,8 @@ def eval_mass_in_radius(self, r3d, z_cl, verbose=False): The mass is calculated as .. math:: - M(<\text{r3d}) = M_{\Delta}\; - \frac{f\left(\frac{\text{r3d}}{r_{\Delta}/c_{\Delta}}\right)}{f(c_{\Delta})}, + M( Date: Fri, 10 Apr 2026 17:04:55 +0200 Subject: [PATCH 03/13] update tests --- clmm/theory/parent_class.py | 2 +- tests/test_theory.py | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 8e46cdf5d..61b9d2684 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1806,7 +1806,7 @@ def _validate_approx_z_src_info(self, loc_dict): "approx=None requires z_src_info='discrete' or 'distribution'," f" z_src_info='{z_src_info}' was provided." ) - elif approx in ("order1", "order2"): + elif approx in ("order0", "order1", "order2"): if z_src_info != "beta": raise ValueError( f"approx='{approx}' requires z_src_info='beta', " diff --git a/tests/test_theory.py b/tests/test_theory.py index 9b9d82565..9f66b21e1 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -663,6 +663,16 @@ def test_shear_convergence_unittests(modeling_data, profile_init): cfg = load_validation_config(halo_profile_model=profile_init) cosmo = cfg["cosmo"] + _gt_order0 = lambda beta_s_mean, gammat_inf, kappa_inf: ( + beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) + ) + _gt_order1 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( + beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean / beta_s_mean * kappa_inf) + ) + _gt_order2 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( + (1.0 + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) * beta_s_mean * kappa_inf) + * (beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf)) + ) if profile_init == "nfw" or modeling_data["nick"] in ["nc", "ccl"]: if profile_init == "nfw": reltol = modeling_data["theory_reltol"] @@ -830,20 +840,22 @@ def test_shear_convergence_unittests(modeling_data, profile_init): ) # reduced tangential shear + cfg_inf["GAMMA_PARAMS"]["approx"] = "order0" + assert_allclose( + theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), + _gt_order0(beta_s_mean, gammat_inf, kappa_inf), + 1.0e-10, + ) cfg_inf["GAMMA_PARAMS"]["approx"] = "order1" assert_allclose( theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), - beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf), + _gt_order1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) cfg_inf["GAMMA_PARAMS"]["approx"] = "order2" assert_allclose( theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), - ( - 1.0 - + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) * beta_s_mean * kappa_inf - ) - * (beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf)), + _gt_order2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) @@ -1103,18 +1115,14 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mod.eval_reduced_tangential_shear( *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order1" ), - beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf), + _gt_order1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) assert_allclose( mod.eval_reduced_tangential_shear( *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order2" ), - ( - 1.0 - + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) * beta_s_mean * kappa_inf - ) - * (beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf)), + _gt_order2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) @@ -1304,7 +1312,7 @@ def test_mass_conversion(modeling_data, profile_init): def test_delta_mdef_virial(modeling_data): if modeling_data["nick"] in ["nc", "ccl"]: cfg = load_validation_config() - cosmo = cfg['cosmo'] + cosmo = cfg["cosmo"] mod = theo.Modeling(massdef="virial") mod.set_cosmo(cosmo) assert_equal(mod._get_delta_mdef(0.1), 111) From 09ddcab112f178950b84312f75fdeddfb92eee3a Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 17:21:25 +0200 Subject: [PATCH 04/13] rename order->type --- clmm/theory/parent_class.py | 43 ++++++++++++++++----------------- tests/test_theory.py | 48 ++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 61b9d2684..40419f8ca 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1170,7 +1170,6 @@ def eval_reduced_tangential_shear( approx : str, optional Type of computation to be made for reduced tangential shears, options are: - **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. If ``z_src_info='discrete'``, full computation is made for each @@ -1184,14 +1183,14 @@ def eval_reduced_tangential_shear( {1-\beta_s(z)\kappa_{\infty}}N(z)\text{d}z} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * ``order0`` : approach with all sources at the same redshift (Eq. 5 in + * ``type0`` : approach with all sources at the same redshift (Eq. 5 in `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - * ``order1`` : Same approach as in Weighing the Giants - III (Eq. 6 in + * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in `Applegate et al. 2014 `_, Eq. A2.4 from `Seitz & Schneider 1997 `_). @@ -1199,7 +1198,7 @@ def eval_reduced_tangential_shear( g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - * ``order2`` : Same approach as in Cluster Mass Calibration at High + * ``type2`` : Same approach as in Cluster Mass Calibration at High Redshift (Eq. 12 in `Schrabback et al. 2017 `_, Eq. 7 in `Hoekstra et al 1998 `_). @@ -1209,7 +1208,7 @@ def eval_reduced_tangential_shear( \left(1+\left(\frac{\left<\beta_s^2\right>} {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right) - **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. integ_kwargs: None, dict Extra arguments for the redshift integration (when @@ -1273,7 +1272,7 @@ def eval_reduced_tangential_shear( "z_src", r_proj, ) - elif approx in ("order0", "order1", "order2"): + elif approx in ("type0", "type1", "type2"): gammat_inf = self._eval_tangential_shear_core(r_proj, z_cl, z_src=self.z_inf) kappa_inf = self._eval_convergence_core(r_proj, z_cl, z_src=self.z_inf) @@ -1281,11 +1280,11 @@ def eval_reduced_tangential_shear( beta_s_mean = z_src[0] beta_s_square_mean = z_src[1] - if approx == "order1": + if approx == "type1": gt = beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean / beta_s_mean * kappa_inf) - else: # for order0 and order2 + else: # for type0 and type2 gt = beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) - if approx == "order2": + if approx == "type2": gt *= ( 1.0 + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) @@ -1293,7 +1292,7 @@ def eval_reduced_tangential_shear( * kappa_inf ) else: - raise ValueError(f"approx={approx} not valid, must be None or orderN (N=0,1,2)") + raise ValueError(f"approx={approx} not valid, must be None or typeN (N=0,1,2)") return gt @@ -1364,13 +1363,13 @@ def eval_magnification( -\left(\beta_s(z)\gamma_{\infty}\right)^2}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * ``order1`` : Uses the weak lensing approximation of the magnification with up to + * ``type1`` : Uses the weak lensing approximation of the magnification with up to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu \approx 1 + 2 \left<\beta_s\right>\kappa_{\infty} - * ``order2`` : Uses the weak lensing approximation of the magnification with up to + * ``type2`` : Uses the weak lensing approximation of the magnification with up to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: @@ -1378,7 +1377,7 @@ def eval_magnification( + 3 \left<\beta_s^2\right>\kappa_{\infty}^2 + \left<\beta_s^2\right>\gamma_{\infty}^2 - **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. integ_kwargs: None, dict Extra arguments for the redshift integration (when @@ -1439,7 +1438,7 @@ def eval_magnification( "z_src", r_proj, ) - elif approx in ("order1", "order2"): + elif approx in ("type1", "type2"): beta_s_mean = z_src[0] kappa_inf = self._eval_convergence_core(r_proj, z_cl, z_src=self.z_inf) @@ -1447,7 +1446,7 @@ def eval_magnification( mu = 1 + 2 * beta_s_mean * kappa_inf - if approx == "order2": + if approx == "type2": beta_s_square_mean = z_src[1] # Taylor expansion with up to second-order terms mu += 3 * beta_s_square_mean * kappa_inf**2 + beta_s_square_mean * gammat_inf**2 @@ -1525,14 +1524,14 @@ def eval_magnification_bias( -\left(\beta_s(z)\gamma_{\infty}\right)^2\right)^{\alpha-1}}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * ``order1`` : Uses the weak lensing approximation of the magnification bias with up + * ``type1`` : Uses the weak lensing approximation of the magnification bias with up to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu^{\alpha-1} \approx 1 + \left(\alpha-1\right)\left(2 \left<\beta_s\right>\kappa_{\infty}\right) - * ``order2`` : Uses the weak lensing approximation of the magnification bias with up + * ``type2`` : Uses the weak lensing approximation of the magnification bias with up to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: @@ -1544,7 +1543,7 @@ def eval_magnification_bias( &+ \left(2\alpha-1\right)\left(\alpha-1\right) \left(\left<\beta_s^2\right>\kappa_{\infty}^2\right) - **Note**: if ``approx='order#'``, ``z_src_info`` must be ``beta``. + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. integ_kwargs: None, dict Extra arguments for the redshift integration (when @@ -1609,7 +1608,7 @@ def eval_magnification_bias( alpha=alpha, ) - elif approx in ("order1", "order2"): + elif approx in ("type1", "type2"): beta_s_mean = z_src[0] kappa_inf = self._eval_convergence_core(r_proj, z_cl, z_src=self.z_inf) @@ -1617,7 +1616,7 @@ def eval_magnification_bias( mu_bias = 1 + (alpha - 1) * (2 * beta_s_mean * kappa_inf) - if approx == "order2": + if approx == "type2": beta_s_square_mean = z_src[1] # Taylor expansion with up to second-order terms mu_bias += (alpha - 1) * (beta_s_square_mean * gammat_inf**2) + ( @@ -1790,7 +1789,7 @@ def _validate_approx_z_src_info(self, loc_dict): r"""Validation for compatility between approx and z_src_info. The conditions are: * approx=None: z_src_info must be 'discrete' or 'distribution' - * approx='order1' or 'order2': z_src_info must be 'beta' + * approx='type1' or 'type2': z_src_info must be 'beta' * approx=other: raises error Parameters @@ -1806,7 +1805,7 @@ def _validate_approx_z_src_info(self, loc_dict): "approx=None requires z_src_info='discrete' or 'distribution'," f" z_src_info='{z_src_info}' was provided." ) - elif approx in ("order0", "order1", "order2"): + elif approx in ("type0", "type1", "type2"): if z_src_info != "beta": raise ValueError( f"approx='{approx}' requires z_src_info='beta', " diff --git a/tests/test_theory.py b/tests/test_theory.py index 9f66b21e1..99e81e057 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -663,13 +663,13 @@ def test_shear_convergence_unittests(modeling_data, profile_init): cfg = load_validation_config(halo_profile_model=profile_init) cosmo = cfg["cosmo"] - _gt_order0 = lambda beta_s_mean, gammat_inf, kappa_inf: ( + _gt_type0 = lambda beta_s_mean, gammat_inf, kappa_inf: ( beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf) ) - _gt_order1 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( + _gt_type1 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( beta_s_mean * gammat_inf / (1.0 - beta_s_square_mean / beta_s_mean * kappa_inf) ) - _gt_order2 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( + _gt_type2 = lambda beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf: ( (1.0 + (beta_s_square_mean / (beta_s_mean * beta_s_mean) - 1.0) * beta_s_mean * kappa_inf) * (beta_s_mean * gammat_inf / (1.0 - beta_s_mean * kappa_inf)) ) @@ -803,14 +803,14 @@ def test_shear_convergence_unittests(modeling_data, profile_init): theo.compute_reduced_tangential_shear, cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"], - approx="order1", + approx="type1", ) assert_raises( ValueError, theo.compute_magnification, cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"], - approx="order1", + approx="type1", ) assert_raises( ValueError, @@ -818,7 +818,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"], alpha=2, - approx="order1", + approx="type1", ) # test z_src_info = 'beta' @@ -840,33 +840,33 @@ def test_shear_convergence_unittests(modeling_data, profile_init): ) # reduced tangential shear - cfg_inf["GAMMA_PARAMS"]["approx"] = "order0" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type0" assert_allclose( theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), - _gt_order0(beta_s_mean, gammat_inf, kappa_inf), + _gt_type0(beta_s_mean, gammat_inf, kappa_inf), 1.0e-10, ) - cfg_inf["GAMMA_PARAMS"]["approx"] = "order1" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type1" assert_allclose( theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), - _gt_order1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), + _gt_type1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) - cfg_inf["GAMMA_PARAMS"]["approx"] = "order2" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type2" assert_allclose( theo.compute_reduced_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), - _gt_order2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), + _gt_type2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) # magnification - cfg_inf["GAMMA_PARAMS"]["approx"] = "order1" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type1" assert_allclose( theo.compute_magnification(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), 1 + 2 * beta_s_mean * kappa_inf, 1.0e-10, ) - cfg_inf["GAMMA_PARAMS"]["approx"] = "order2" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type2" assert_allclose( theo.compute_magnification(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]), 1 @@ -877,13 +877,13 @@ def test_shear_convergence_unittests(modeling_data, profile_init): ) # magnification bias - cfg_inf["GAMMA_PARAMS"]["approx"] = "order1" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type1" assert_allclose( theo.compute_magnification_bias(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"], alpha=alpha), 1 + (alpha - 1) * (2 * beta_s_mean * kappa_inf), 1.0e-10, ) - cfg_inf["GAMMA_PARAMS"]["approx"] = "order2" + cfg_inf["GAMMA_PARAMS"]["approx"] = "type2" assert_allclose( theo.compute_magnification_bias(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"], alpha=alpha), 1 @@ -1113,16 +1113,16 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # Validate reduced tangential shear assert_allclose( mod.eval_reduced_tangential_shear( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order1" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "type1" ), - _gt_order1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), + _gt_type1(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) assert_allclose( mod.eval_reduced_tangential_shear( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order2" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "type2" ), - _gt_order2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), + _gt_type2(beta_s_mean, beta_s_square_mean, gammat_inf, kappa_inf), 1.0e-10, ) @@ -1130,14 +1130,14 @@ def test_shear_convergence_unittests(modeling_data, profile_init): alpha = -1.78 assert_allclose( mod.eval_magnification( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order1" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "type1" ), 1 + 2 * beta_s_mean * kappa_inf, 1.0e-10, ) assert_allclose( mod.eval_magnification( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "order2" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), "beta", "type2" ), 1 + 2 * beta_s_mean * kappa_inf @@ -1149,14 +1149,14 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # Validate magnification bias assert_allclose( mod.eval_magnification_bias( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), alpha, "beta", "order1" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), alpha, "beta", "type1" ), 1 + (alpha - 1) * (2 * beta_s_mean * kappa_inf), 1.0e-10, ) assert_allclose( mod.eval_magnification_bias( - *profile_pars[:2], (beta_s_mean, beta_s_square_mean), alpha, "beta", "order2" + *profile_pars[:2], (beta_s_mean, beta_s_square_mean), alpha, "beta", "type2" ), 1 + (alpha - 1) * (2 * beta_s_mean * kappa_inf) From 45f577059e8eda1b8ddcc88fec2830f7a1946e1d Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 17:25:35 +0200 Subject: [PATCH 05/13] bump version --- clmm/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clmm/__init__.py b/clmm/__init__.py index f1a42f5ef..adb901357 100644 --- a/clmm/__init__.py +++ b/clmm/__init__.py @@ -27,4 +27,4 @@ ) from .utils import compute_radial_averages, convert_units, make_bins -__version__ = "1.16.10" +__version__ = "1.17.0" From 2f783d5913bd521e53f024536f4bb3bbda0d93cf Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 18:11:00 +0200 Subject: [PATCH 06/13] update tests and docstrings --- clmm/theory/func_layer.py | 70 +++++++++++++++++++++---------------- tests/test_theory_parent.py | 6 ++-- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index 5d570cbed..5f08ff8de 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -900,10 +900,10 @@ def compute_reduced_tangential_shear( approx : str, optional Type of computation to be made for reduced tangential shears, options are: - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, reduced - tangential shear at each value of `r_proj` is calculated as + * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, reduced + tangential shear at each value of ``r_proj`` is calculated as .. math:: g_t @@ -912,18 +912,24 @@ def compute_reduced_tangential_shear( {1-\beta_s(z)\kappa_{\infty}}N(z)\text{d}z} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Same approach as in Weighing the Giants - III (equation 6 in - Applegate et al. 2014; https://arxiv.org/abs/1208.0605). - `z_src_info` must be 'beta': + * ``type0`` : approach with all sources at the same redshift (Eq. 5 in + `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - * 'order2' : Same approach as in Cluster Mass Calibration at High - Redshift (equation 12 in Schrabback et al. 2017; - https://arxiv.org/abs/1611.03866). - `z_src_info` must be 'beta': + * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in + `Applegate et al. 2014 `_, + Eq. A2.4 from `Seitz & Schneider 1997 `_). + + .. math:: + g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} + {1-\left<\beta_s\right>\kappa_{\infty}} + + * ``type2`` : Same approach as in Cluster Mass Calibration at High + Redshift (Eq. 12 in `Schrabback et al. 2017 `_, + Eq. 7 in `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} @@ -931,6 +937,8 @@ def compute_reduced_tangential_shear( \left(1+\left(\frac{\left<\beta_s^2\right>} {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right) + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when `approx=None, z_src_info='distribution'`). Possible keys are: @@ -1070,10 +1078,10 @@ def compute_magnification( approx : str, optional Type of computation to be made for magnifications, options are: - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification - at each value of `r_proj` is calculated as + * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification + at each value of ``r_proj`` is calculated as .. math:: \mu @@ -1084,22 +1092,22 @@ def compute_magnification( -\left(\beta_s(z)\gamma_{\infty}\right)^2}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Uses the weak lensing approximation of the magnification with up to - first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``type1`` : Uses the weak lensing approximation of the magnification with up to + first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu \approx 1 + 2 \left<\beta_s\right>\kappa_{\infty} - * 'order2' : Uses the weak lensing approximation of the magnification with up to - second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``type2`` : Uses the weak lensing approximation of the magnification with up to + second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu \approx 1 + 2 \left<\beta_s\right>\kappa_{\infty} + 3 \left<\beta_s^2\right>\kappa_{\infty}^2 + \left<\beta_s^2\right>\gamma_{\infty}^2 + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when `approx=None, z_src_info='distribution'`). Possible keys are: @@ -1252,10 +1260,10 @@ def compute_magnification_bias( approx : str, optional Type of computation to be made for magnification biases, options are: - * None (default): Requires `z_src_info` to be 'discrete' or 'distribution'. - If `z_src_info='discrete'`, full computation is made for each - `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification - bias at each value of `r_proj` is calculated as + * ``None`` (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. + If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification + bias at each value of ``r_proj`` is calculated as .. math:: \mu^{\alpha-1} @@ -1267,17 +1275,15 @@ def compute_magnification_bias( -\left(\beta_s(z)\gamma_{\infty}\right)^2\right)^{\alpha-1}}} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * 'order1' : Uses the weak lensing approximation of the magnification bias with up - to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - (`z_src_info` must be 'beta'): + * ``type1`` : Uses the weak lensing approximation of the magnification bias with up + to first-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu^{\alpha-1} \approx 1 + \left(\alpha-1\right)\left(2 \left<\beta_s\right>\kappa_{\infty}\right) - * 'order2' : Uses the weak lensing approximation of the magnification bias with up - to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}` - `z_src_info` must be 'beta': + * ``type2`` : Uses the weak lensing approximation of the magnification bias with up + to second-order terms in :math:`\kappa_{\infty}` or :math:`\gamma_{\infty}`: .. math:: \mu^{\alpha-1} \approx @@ -1288,6 +1294,8 @@ def compute_magnification_bias( &+ \left(2\alpha-1\right)\left(\alpha-1\right) \left(\left<\beta_s^2\right>\kappa_{\infty}^2\right) + **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. + integ_kwargs: None, dict Extra arguments for the redshift integration (when `approx=None, z_src_info='distribution'`). Possible keys are: diff --git a/tests/test_theory_parent.py b/tests/test_theory_parent.py index 65ae4e388..4b975ec68 100644 --- a/tests/test_theory_parent.py +++ b/tests/test_theory_parent.py @@ -37,11 +37,11 @@ def test_unimplemented(modeling_data): 0.3, (0.6, 0.4), "beta", - "order1", + "type1", ) assert_raises(NotImplementedError, mod.eval_magnification, [0.3], 0.3, 0.5) assert_raises( - NotImplementedError, mod.eval_magnification, [0.3], 0.3, (0.6, 0.4), "beta", "order1" + NotImplementedError, mod.eval_magnification, [0.3], 0.3, (0.6, 0.4), "beta", "type1" ) assert_raises(NotImplementedError, mod.eval_magnification_bias, [0.3], 0.3, 0.5, 3.0) assert_raises( @@ -52,7 +52,7 @@ def test_unimplemented(modeling_data): (0.6, 0.4), 3.0, "beta", - "order1", + "type1", ) From c53896aecb97f9c17d0a7f3a3a80c67eecb25357 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 18:13:12 +0200 Subject: [PATCH 07/13] fix black target version to py313 --- .github/workflows/build_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 80a4858bd..00d83c8d9 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -26,7 +26,7 @@ jobs: - name: Analysing the code formatting with black shell: bash -l {0} run: | - black --check --diff clmm + black --check --target-version py313 --diff clmm - name: Analysing the code import order with isort shell: bash -l {0} run: | From a8b48f2105b1b2575f0d85e7e399630cb068daf2 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 22:44:21 +0200 Subject: [PATCH 08/13] update docstrings --- clmm/theory/func_layer.py | 4 ++-- clmm/theory/parent_class.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index 5f08ff8de..7e07c4369 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -924,8 +924,8 @@ def compute_reduced_tangential_shear( Eq. A2.4 from `Seitz & Schneider 1997 `_). .. math:: - g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} - {1-\left<\beta_s\right>\kappa_{\infty}} + g_t\approx\frac{\langle\beta_s\rangle\gamma_\infty} + {1-\frac{\langle\beta_s^2\rangle}{\langle\beta_s\rangle}\kappa_\infty} * ``type2`` : Same approach as in Cluster Mass Calibration at High Redshift (Eq. 12 in `Schrabback et al. 2017 `_, diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 40419f8ca..dd79a1fe5 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1195,8 +1195,8 @@ def eval_reduced_tangential_shear( Eq. A2.4 from `Seitz & Schneider 1997 `_). .. math:: - g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} - {1-\left<\beta_s\right>\kappa_{\infty}} + g_t\approx\frac{\langle\beta_s\rangle\gamma_\infty} + {1-\frac{\langle\beta_s^2\rangle}{\langle\beta_s\rangle}\kappa_\infty} * ``type2`` : Same approach as in Cluster Mass Calibration at High Redshift (Eq. 12 in `Schrabback et al. 2017 `_, From 36177d5107571ca2ded06620f3cb194bd4f5bab2 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 22:49:44 +0200 Subject: [PATCH 09/13] remove --target-version from black and update docstrings --- .github/workflows/build_check.yml | 2 +- clmm/galaxycluster.py | 4 ++-- clmm/theory/generic.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build_check.yml b/.github/workflows/build_check.yml index 00d83c8d9..80a4858bd 100644 --- a/.github/workflows/build_check.yml +++ b/.github/workflows/build_check.yml @@ -26,7 +26,7 @@ jobs: - name: Analysing the code formatting with black shell: bash -l {0} run: | - black --check --target-version py313 --diff clmm + black --check --diff clmm - name: Analysing the code import order with isort shell: bash -l {0} run: | diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index a162804fe..4cb52d00a 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -448,8 +448,8 @@ def draw_gal_z_from_pdz(self, zcol_out="z", overwrite=False, nobj=1, xmin=None, if zcol_out in self.galcat.columns and overwrite is False: raise TypeError( - f"Column {zcol_out} already exists in galcat. \ - Set overwrite=True to overwrite or use other column name" + f"Column {zcol_out} already exists in galcat. " + "Set overwrite=True to overwrite or use other column name" ) zdata = self._get_input_galdata({"pzpdf": "pzpdf", "pzbins": "pzbins"}) diff --git a/clmm/theory/generic.py b/clmm/theory/generic.py index c4118f747..0124f6c56 100644 --- a/clmm/theory/generic.py +++ b/clmm/theory/generic.py @@ -66,8 +66,8 @@ def compute_magnification_bias_from_magnification(magnification, alpha): """ if np.any(np.array(magnification) < 0): warnings.warn( - "Magnification is negative for certain radii, \ - returning nan for magnification bias in this case." + "Magnification is negative for certain radii, " + "returning nan for magnification bias in this case." ) return np.array(magnification) ** (np.array([alpha]).T - 1) From 78fa2448d5b392dd95488733388b6baa517dc499 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Fri, 10 Apr 2026 23:30:13 +0200 Subject: [PATCH 10/13] fix docstrings with pylint --- clmm/theory/func_layer.py | 3 ++- clmm/theory/parent_class.py | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index 7e07c4369..fe84453e4 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -921,7 +921,8 @@ def compute_reduced_tangential_shear( * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in `Applegate et al. 2014 `_, - Eq. A2.4 from `Seitz & Schneider 1997 `_). + Eq. A2.4 from `Seitz & Schneider 1997 + `_). .. math:: g_t\approx\frac{\langle\beta_s\rangle\gamma_\infty} diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index dd79a1fe5..f0ea6b090 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1192,15 +1192,16 @@ def eval_reduced_tangential_shear( * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in `Applegate et al. 2014 `_, - Eq. A2.4 from `Seitz & Schneider 1997 `_). + Eq. A2.4 from `Seitz & Schneider 1997 + `_). .. math:: g_t\approx\frac{\langle\beta_s\rangle\gamma_\infty} {1-\frac{\langle\beta_s^2\rangle}{\langle\beta_s\rangle}\kappa_\infty} - * ``type2`` : Same approach as in Cluster Mass Calibration at High - Redshift (Eq. 12 in `Schrabback et al. 2017 `_, - Eq. 7 in `Hoekstra et al 1998 `_). + * ``type2`` : Same approach as in Cluster Mass Calibration at High Redshift + (Eq. 12 in `Schrabback et al. 2017 `_, Eq. + 7 in `Hoekstra et al 1998 `_). .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} @@ -1349,10 +1350,10 @@ def eval_magnification( approx : str, optional Type of computation to be made for magnifications, options are: - * None (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. - If ``z_src_info='discrete'``, full computation is made for each - ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification - at each value of ``r_proj`` is calculated as + * ``None`` (default): Requires ``z_src_info`` to be ``discrete`` or + ``distribution``. If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, + magnification at each value of ``r_proj`` is calculated as .. math:: \mu @@ -1509,10 +1510,10 @@ def eval_magnification_bias( approx : str, optional Type of computation to be made for magnification biases, options are: - * ``None`` (default): Requires ``z_src_info`` to be ``discrete`` or ``distribution``. - If ``z_src_info='discrete'``, full computation is made for each - ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, magnification - bias at each value of ``r_proj`` is calculated as + * ``None`` (default): Requires ``z_src_info`` to be ``discrete`` or + ``distribution``. If ``z_src_info='discrete'``, full computation is made for each + ``r_proj, z_src`` pair individually. If ``z_src_info='distribution'``, + magnification bias at each value of ``r_proj`` is calculated as .. math:: \mu^{\alpha-1} From 104bd2c9678cbfab0ca01d542a0ded2f462f6c24 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Sat, 11 Apr 2026 00:11:39 +0200 Subject: [PATCH 11/13] update nbs --- examples/demo_theory_functionality.ipynb | 28 ++++++++-------- ...mo_theory_functionality_diff_z_types.ipynb | 32 ++++++++----------- examples/demo_theory_functionality_oo.ipynb | 30 +++++++++-------- ...mple3_Fit_Halo_Mass_to_Shear_Catalog.ipynb | 8 ++--- .../Example4_Fit_Halo_mass_to_HSC_data.ipynb | 4 +-- .../Example5_Fit_Halo_mass_to_DES_data.ipynb | 4 +-- 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/examples/demo_theory_functionality.ipynb b/examples/demo_theory_functionality.ipynb index f3f420ab4..69146545b 100644 --- a/examples/demo_theory_functionality.ipynb +++ b/examples/demo_theory_functionality.ipynb @@ -49,9 +49,9 @@ "source": [ "import os\n", "\n", - "os.environ[\n", - " \"CLMM_MODELING_BACKEND\"\n", - "] = \"ccl\" # here you may choose ccl, nc (NumCosmo) or ct (cluster_toolkit)\n", + "os.environ[\"CLMM_MODELING_BACKEND\"] = (\n", + " \"ccl\" # here you may choose ccl, nc (NumCosmo) or ct (cluster_toolkit)\n", + ")\n", "import clmm\n", "import clmm.theory as m\n", "from clmm import Cosmology" @@ -111,7 +111,9 @@ "\n", "# source properties\n", "z_src = 2.0 # all sources in the same plan\n", - "z_distrib_func = clmm.utils.redshift_distributions.chang2013 # sources redshift following a distribution\n", + "z_distrib_func = (\n", + " clmm.utils.redshift_distributions.chang2013\n", + ") # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] }, @@ -166,7 +168,7 @@ " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", - " r_mis=0.2\n", + " r_mis=0.2,\n", ")" ] }, @@ -194,7 +196,7 @@ " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", - " r_mis=0.2\n", + " r_mis=0.2,\n", ")" ] }, @@ -330,7 +332,7 @@ " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", " z_src_info=\"beta\",\n", - " approx=\"order2\",\n", + " approx=\"type2\",\n", ")" ] }, @@ -368,9 +370,9 @@ "metadata": {}, "outputs": [], "source": [ - "plot_profile(r3d, Sigma, \"$\\\\Sigma_{\\\\rm 2d}$\", label='R_off = No miscentering')\n", - "plot_profile(r3d, Sigma_mis, \"$\\\\Sigma_{\\\\rm 2d}$\", label='R_off = 0.2 Mpc')\n", - "plt.axvline(0.2, linestyle=':', color='k')\n", + "plot_profile(r3d, Sigma, \"$\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = No miscentering\")\n", + "plot_profile(r3d, Sigma_mis, \"$\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = 0.2 Mpc\")\n", + "plt.axvline(0.2, linestyle=\":\", color=\"k\")\n", "plt.legend()" ] }, @@ -380,9 +382,9 @@ "metadata": {}, "outputs": [], "source": [ - "plot_profile(r3d, DeltaSigma, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label='No miscentering')\n", - "plot_profile(r3d, DeltaSigma_mis, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label='R_off = 0.2 Mpc')\n", - "plt.axvline(0.2, linestyle=':', color='k')\n", + "plot_profile(r3d, DeltaSigma, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label=\"No miscentering\")\n", + "plot_profile(r3d, DeltaSigma_mis, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = 0.2 Mpc\")\n", + "plt.axvline(0.2, linestyle=\":\", color=\"k\")\n", "plt.legend()" ] }, diff --git a/examples/demo_theory_functionality_diff_z_types.ipynb b/examples/demo_theory_functionality_diff_z_types.ipynb index 4b228ac93..4bf02d7fc 100644 --- a/examples/demo_theory_functionality_diff_z_types.ipynb +++ b/examples/demo_theory_functionality_diff_z_types.ipynb @@ -31,7 +31,7 @@ "import os\n", "\n", "## Uncomment the following line if you want to use a specific modeling backend among 'ct' (cluster-toolkit), 'ccl' (CCL) or 'nc' (Numcosmo). Default is 'ccl'\n", - "#os.environ['CLMM_MODELING_BACKEND'] = 'nc'" + "# os.environ['CLMM_MODELING_BACKEND'] = 'nc'" ] }, { @@ -255,14 +255,14 @@ "z_inf = 1000\n", "\n", "beta_s_mean_wts = clmm.utils.compute_beta_s_mean_from_weights(\n", - " source_catalog['z'],\n", + " source_catalog[\"z\"],\n", " cluster_z,\n", " z_inf,\n", " cosmo,\n", " shape_weights=None,\n", ")\n", "beta_s_square_mean_wts = clmm.utils.compute_beta_s_square_mean_from_weights(\n", - " source_catalog['z'],\n", + " source_catalog[\"z\"],\n", " cluster_z,\n", " z_inf,\n", " cosmo,\n", @@ -500,7 +500,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order1\"\n", + " approx=\"type1\",\n", ")" ] }, @@ -521,7 +521,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order2\"\n", + " approx=\"type2\",\n", ")" ] }, @@ -622,7 +622,7 @@ " cosmo,\n", " delta_mdef=500,\n", " massdef=\"critical\",\n", - " z_src_info=\"discrete\"\n", + " z_src_info=\"discrete\",\n", " )\n", " )\n", " for _r in rr\n", @@ -639,7 +639,7 @@ " cosmo,\n", " delta_mdef=500,\n", " massdef=\"critical\",\n", - " z_src_info=\"beta\"\n", + " z_src_info=\"beta\",\n", ")" ] }, @@ -652,9 +652,7 @@ "plot_cases(\n", " rr,\n", " base=(gammat_discrete, \"k.-\", dict(label=\"discrete\")),\n", - " others=(\n", - " (gammat_beta, \"b--\", dict(label=\"beta, no approx\")),\n", - " ),\n", + " others=((gammat_beta, \"b--\", dict(label=\"beta, no approx\")),),\n", " ylabel=\"$\\gamma_t$\",\n", ")" ] @@ -694,7 +692,7 @@ " cosmo,\n", " delta_mdef=500,\n", " massdef=\"critical\",\n", - " z_src_info=\"beta\"\n", + " z_src_info=\"beta\",\n", ")" ] }, @@ -707,9 +705,7 @@ "plot_cases(\n", " rr,\n", " base=(kappa_discrete, \"k.-\", dict(label=\"discrete\")),\n", - " others=(\n", - " (kappa_beta, \"b--\", dict(label=\"beta, no approx\")),\n", - " ),\n", + " others=((kappa_beta, \"b--\", dict(label=\"beta, no approx\")),),\n", " ylabel=\"$\\kappa_t$\",\n", ")" ] @@ -750,7 +746,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order1\"\n", + " approx=\"type1\",\n", ")\n", "\n", "mu_beta_2 = clmm.theory.compute_magnification(\n", @@ -763,7 +759,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order2\"\n", + " approx=\"type2\",\n", ")" ] }, @@ -824,7 +820,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order1\"\n", + " approx=\"type1\",\n", ")\n", "\n", "mu_bias_beta_2 = clmm.theory.compute_magnification_bias(\n", @@ -838,7 +834,7 @@ " delta_mdef=500,\n", " massdef=\"critical\",\n", " z_src_info=\"beta\",\n", - " approx=\"order2\"\n", + " approx=\"type2\",\n", ")" ] }, diff --git a/examples/demo_theory_functionality_oo.ipynb b/examples/demo_theory_functionality_oo.ipynb index ec99b219a..56197d8b7 100644 --- a/examples/demo_theory_functionality_oo.ipynb +++ b/examples/demo_theory_functionality_oo.ipynb @@ -43,9 +43,9 @@ "source": [ "import os\n", "\n", - "os.environ[\n", - " \"CLMM_MODELING_BACKEND\"\n", - "] = \"ccl\" # here you may choose ccl, nc (NumCosmo) or ct (cluster_toolkit)\n", + "os.environ[\"CLMM_MODELING_BACKEND\"] = (\n", + " \"ccl\" # here you may choose ccl, nc (NumCosmo) or ct (cluster_toolkit)\n", + ")\n", "\n", "import clmm\n", "from clmm import Cosmology" @@ -106,7 +106,9 @@ "\n", "# source properties\n", "z_src = 2.0 # all sources in the same plane\n", - "z_distrib_func = clmm.utils.redshift_distributions.chang2013 # sources redshift following a distribution\n", + "z_distrib_func = (\n", + " clmm.utils.redshift_distributions.chang2013\n", + ") # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] }, @@ -148,7 +150,7 @@ "beta_s_square_mean = clmm.utils.compute_beta_s_square_mean_from_distribution(**beta_kwargs)\n", "\n", "gt_z = moo.eval_reduced_tangential_shear(\n", - " r3d, z_cl, [beta_s_mean, beta_s_square_mean], z_src_info=\"beta\", approx=\"order2\"\n", + " r3d, z_cl, [beta_s_mean, beta_s_square_mean], z_src_info=\"beta\", approx=\"type2\"\n", ")\n", "\n", "mu = moo.eval_magnification(r3d, z_cl, z_src)\n", @@ -189,11 +191,11 @@ "metadata": {}, "outputs": [], "source": [ - "plot_profile(r3d, Sigma, \"$\\\\Sigma_{\\\\rm 2d}$\", label='R_off = No miscentering')\n", - "plot_profile(r3d, Sigma_mis, \"$\\\\Sigma_{\\\\rm 2d}$\", label='R_off = 0.2 Mpc')\n", - "plt.axvline(0.2, linestyle=':', color='k')\n", + "plot_profile(r3d, Sigma, \"$\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = No miscentering\")\n", + "plot_profile(r3d, Sigma_mis, \"$\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = 0.2 Mpc\")\n", + "plt.axvline(0.2, linestyle=\":\", color=\"k\")\n", "plt.legend()\n", - "plt.ylabel('$\\Sigma$ [$M_\\odot$ Mpc$^{-2}$]')" + "plt.ylabel(\"$\\Sigma$ [$M_\\odot$ Mpc$^{-2}$]\")" ] }, { @@ -202,12 +204,12 @@ "metadata": {}, "outputs": [], "source": [ - "plot_profile(r3d, DeltaSigma, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label='No miscentering')\n", - "plot_profile(r3d, DeltaSigma_mis, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label='R_off = 0.2 Mpc')\n", - "plt.axvline(0.2, linestyle=':', color='k')\n", + "plot_profile(r3d, DeltaSigma, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label=\"No miscentering\")\n", + "plot_profile(r3d, DeltaSigma_mis, \"$\\\\Delta\\\\Sigma_{\\\\rm 2d}$\", label=\"R_off = 0.2 Mpc\")\n", + "plt.axvline(0.2, linestyle=\":\", color=\"k\")\n", "plt.legend()\n", - "plt.ylabel('$\\Delta\\Sigma$ [$M_\\odot$ Mpc$^{-2}$]')\n", - "plt.savefig('miscentering.png')" + "plt.ylabel(\"$\\Delta\\Sigma$ [$M_\\odot$ Mpc$^{-2}$]\")\n", + "plt.savefig(\"miscentering.png\")" ] }, { diff --git a/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb b/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb index 2f7327588..1fb865c5c 100644 --- a/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb +++ b/examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_Catalog.ipynb @@ -439,7 +439,7 @@ "# clmm/theory/func_layer.py: compute_reduced_tangential_shear()\n", "# clmm/theory/parent_class.py: eval_reduced_tangential_shear()\n", "\n", - "# The method from Applegate et al. (2014), called 'order1' in CLMM.\n", + "# The method from Applegate et al. (2014), called 'type1' in CLMM.\n", "# The argument \"profile\" is only used to get the radius values r = profile['radius']\n", "# The default mass is M200m; use massdef='critical' for M200c.\n", "\n", @@ -477,12 +477,12 @@ "\n", "\n", "def model_reduced_tangential_shear_applegate14(logm, catalog, profile):\n", - " return _model_reduced_tangential_shear(logm, catalog, profile, approx=\"order1\")\n", + " return _model_reduced_tangential_shear(logm, catalog, profile, approx=\"type1\")\n", "\n", "\n", - "# Similarly, we also consider the method from Schrabback et al. (2018), called 'order2' in CLMM.\n", + "# Similarly, we also consider the method from Schrabback et al. (2018), called 'type2' in CLMM.\n", "def model_reduced_tangential_shear_schrabback18(logm, catalog, profile):\n", - " return _model_reduced_tangential_shear(logm, catalog, profile, approx=\"order2\")" + " return _model_reduced_tangential_shear(logm, catalog, profile, approx=\"type2\")" ] }, { diff --git a/examples/mass_fitting/Example4_Fit_Halo_mass_to_HSC_data.ipynb b/examples/mass_fitting/Example4_Fit_Halo_mass_to_HSC_data.ipynb index 74502f5c7..c41d2754a 100644 --- a/examples/mass_fitting/Example4_Fit_Halo_mass_to_HSC_data.ipynb +++ b/examples/mass_fitting/Example4_Fit_Halo_mass_to_HSC_data.ipynb @@ -422,7 +422,7 @@ " cluster.profile[\"gt\"],\n", " cluster.profile[\"gt_err\"],\n", " c=\"k\",\n", - " **errorbar_kwargs\n", + " **errorbar_kwargs,\n", ")\n", "ax.set_xlabel(\"r [Mpc]\", fontsize=10)\n", "ax.set_ylabel(r\"$g_t$\", fontsize=10)\n", @@ -460,7 +460,7 @@ " z_cluster=cluster_z, # Redshift of the cluster\n", " z_src=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", " z_src_info=\"beta\",\n", - " approx=\"order1\",\n", + " approx=\"type1\",\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " massdef=\"critical\",\n", diff --git a/examples/mass_fitting/Example5_Fit_Halo_mass_to_DES_data.ipynb b/examples/mass_fitting/Example5_Fit_Halo_mass_to_DES_data.ipynb index 3e24d6f69..bc7b860d7 100644 --- a/examples/mass_fitting/Example5_Fit_Halo_mass_to_DES_data.ipynb +++ b/examples/mass_fitting/Example5_Fit_Halo_mass_to_DES_data.ipynb @@ -362,7 +362,7 @@ " cluster.profile[\"gt\"],\n", " cluster.profile[\"gt_err\"],\n", " c=\"k\",\n", - " **errorbar_kwargs\n", + " **errorbar_kwargs,\n", ")\n", "ax.set_xlabel(\"R [Mpc]\", fontsize=10)\n", "ax.set_ylabel(r\"$g_t$\", fontsize=10)\n", @@ -406,7 +406,7 @@ " z_cluster=cluster_z, # Redshift of the cluster\n", " z_src=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", " z_src_info=\"beta\",\n", - " approx=\"order1\",\n", + " approx=\"type1\",\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " massdef=\"critical\",\n", From 1fca2e962e8e6b394c86e9260666694f42204b60 Mon Sep 17 00:00:00 2001 From: Michel Aguena Date: Mon, 13 Apr 2026 17:58:12 +0200 Subject: [PATCH 12/13] update docstrings --- clmm/theory/func_layer.py | 282 ++++++++++++++++++------------------ clmm/theory/parent_class.py | 25 ++-- 2 files changed, 153 insertions(+), 154 deletions(-) diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index fe84453e4..92fb40cfc 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -44,26 +44,26 @@ def compute_3d_density( Galaxy cluster concentration z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition; defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) @@ -140,26 +140,26 @@ def compute_surface_density( Galaxy cluster concentration z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition; defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) @@ -240,26 +240,26 @@ def compute_mean_surface_density( Galaxy cluster concentration z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition; defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. Option only + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo backend r_mis : float, optional Projected miscenter distance in :math:`M\!pc` @@ -332,26 +332,26 @@ def compute_excess_surface_density( Galaxy cluster concentration z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition; defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) @@ -420,7 +420,7 @@ def compute_excess_surface_density_2h( Projected radial position from the cluster center in :math:`M\!pc`. z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object halobias : float, optional Value of the halo bias @@ -487,7 +487,7 @@ def compute_surface_density_2h( Projected radial position from the cluster center in :math:`M\!pc`. z_cl: float Redshift of the cluster - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object halobias : float, optional Value of the halo bias @@ -540,7 +540,7 @@ def compute_critical_surface_density_eff(cosmo, z_cluster, pzbins, pzpdf, valida Parameters ---------- - cosmo : clmm.cosmology.Cosmology object + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object z_cluster : float Galaxy cluster redshift @@ -604,43 +604,43 @@ def compute_tangential_shear( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). - cosmo : clmm.cosmology.Cosmology object + ``z_src_info`` (see below). + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition. Defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an array - or all sources are at the same redshift when `z_src` is a float. + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an array + or all sources are at the same redshift when ``z_src`` is a float. - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimensional function. + * ``distrubution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimensional function. - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -729,43 +729,43 @@ def compute_convergence( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). - cosmo : clmm.cosmology.Cosmology object + ``z_src_info`` (see below). + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition. Defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an array - or all sources are at the same redshift when `z_src` is a float. + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an array + or all sources are at the same redshift when ``z_src`` is a float. - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimensional function. + * ``distrubution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimensional function. - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -847,44 +847,44 @@ def compute_reduced_tangential_shear( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). - cosmo : clmm.cosmology.Cosmology object + ``z_src_info`` (see below). + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition. Defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit 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. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an array - or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an array + or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimensional function (Used when `approx=None`). + * ``distrubution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimensional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -935,24 +935,24 @@ def compute_reduced_tangential_shear( .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - \left(1+\left(\frac{\left<\beta_s^2\right>} - {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right) + \left[1+\left(\frac{\left<\beta_s^2\right>} + {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right] **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) @@ -1026,44 +1026,44 @@ def compute_magnification( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). - cosmo : clmm.cosmology.Cosmology object + ``z_src_info`` (see below). + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition. Defaults to 200. halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an array - or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an array + or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimensional function (Used when `approx=None`). + * ``distrubution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimensional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1111,14 +1111,14 @@ def compute_magnification( integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and CCL @@ -1208,44 +1208,44 @@ def compute_magnification_bias( Galaxy cluster redshift z_src : array_like, float, function Information on the background source galaxy redshift(s). Value required depends on - `z_src_info` (see below). - cosmo : clmm.cosmology.Cosmology object + ``z_src_info`` (see below). + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` CLMM Cosmology object delta_mdef : int, optional Mass overdensity definition. Defaults to 200. alpha_ein : float, None, optional - If `halo_profile_model=='einasto'`, set the value of the Einasto slope. + If ``halo_profile_model=='einasto'``, set the value of the Einasto slope. Option only available for the NumCosmo and CCL backends. If None, use the default value of the backend. (0.25 for the NumCosmo backend and a cosmology-dependent value for the CCL backend.) halo_profile_model : str, optional Profile model parameterization (letter case independent): - * 'nfw' (default) - * 'einasto' - not in cluster_toolkit - * 'hernquist' - not in cluster_toolkit + * ``nfw`` (default) + * ``einasto`` - not in cluster_toolkit + * ``hernquist`` - not in cluster_toolkit massdef : str, optional Profile mass definition, with the following supported options (letter case independent): - * 'mean' (default) - * 'critical' - * 'virial' + * ``mean`` (default) + * ``critical`` + * ``virial`` z_src_info : str, optional - Type of redshift information provided by the `z_src` argument. + Type of redshift information provided by the ``z_src`` argument. The following supported options are: - * 'discrete' (default) : The redshift of sources is provided by `z_src`. - It can be individual redshifts for each source galaxy when `z_src` is an array - or all sources are at the same redshift when `z_src` is a float - (Used for `approx=None`). + * ``discrete`` (default) : The redshift of sources is provided by ``z_src``. + It can be individual redshifts for each source galaxy when ``z_src`` is an array + or all sources are at the same redshift when ``z_src`` is a float + (Used for ``approx=None``). - * 'distribution' : A redshift distribution function is provided by `z_src`. - `z_src` must be a one dimensional function (Used when `approx=None`). + * ``distrubution`` : A redshift distribution function is provided by ``z_src``. + ``z_src`` must be a one dimensional function (Used when ``approx=None``). - * 'beta' : The averaged lensing efficiency is provided by `z_src`. - `z_src` must be a tuple containing + * ``beta`` : The averaged lensing efficiency is provided by ``z_src``. + ``z_src`` must be a tuple containing ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`), the lensing efficiency and square of the lensing efficiency averaged over the galaxy redshift distribution repectively. @@ -1299,14 +1299,14 @@ def compute_magnification_bias( integ_kwargs: None, dict Extra arguments for the redshift integration (when - `approx=None, z_src_info='distribution'`). Possible keys are: + ``approx=None, z_src_info='distribution'``). Possible keys are: - * 'zmin' (None, float) : Minimum redshift to be set as the source of the galaxy + * ``zmin`` (None, float) : Minimum redshift to be set as the source of the galaxy when performing the sum. (default=None) - * 'zmax' (float) : Maximum redshift to be set as the source of the galaxy + * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) - * 'delta_z_cut' (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - `delta_z_cut` is ignored if `z_min` is already provided. (default=0.1) + * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) validate_input : bool, optional If True (default), the types of the arguments are checked before proceeding. diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index f0ea6b090..c4b90f8e6 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -47,7 +47,7 @@ class CLMModeling: Mass overdensity definition. halo_profile_model : str Profile model parameterization ("nfw", "einasto", "hernquist" - letter case independent) - cosmo: Cosmology + cosmo : :class:`~clmm.cosmology.parent_class.CLMMCosmology` Cosmology object hdpm: Object Backend object with halo profiles @@ -1072,7 +1072,7 @@ def _pdz_weighted_avg(self, core, pdz_func, r_proj, z_cl, integ_kwargs=None): * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. - ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) Returns ------- @@ -1206,8 +1206,8 @@ def eval_reduced_tangential_shear( .. math:: g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} {1-\left<\beta_s\right>\kappa_{\infty}} - \left(1+\left(\frac{\left<\beta_s^2\right>} - {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right) + \left[1+\left(\frac{\left<\beta_s^2\right>} + {\left<\beta_s\right>^2}-1\right)\left<\beta_s\right>\kappa_{\infty}\right] **Note**: if ``approx='type#'``, ``z_src_info`` must be ``beta``. @@ -1220,7 +1220,7 @@ def eval_reduced_tangential_shear( * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) * ``delta_z_cut`` (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1240,7 +1240,7 @@ def eval_reduced_tangential_shear( validate_argument(locals(), "z_cl", float, argmin=0) validate_argument(locals(), "z_src_info", str) validate_argument(locals(), "approx", str, none_ok=True) - self._validate_approx_z_src_info(locals()) + self._validate_approx_z_src_info(locals(), valid_approx=("type0", "type1", "type2")) self._validate_z_src(locals()) if self.halo_profile_model == "einasto" and verbose: @@ -1248,7 +1248,6 @@ def eval_reduced_tangential_shear( # functions _validate_z_src, _validate_approx_z_src_info already safekeeps from this error: # pylint: disable=possibly-used-before-assignment - if approx is None: if z_src_info == "distribution": gt = self._pdz_weighted_avg( @@ -1292,8 +1291,6 @@ def eval_reduced_tangential_shear( * beta_s_mean * kappa_inf ) - else: - raise ValueError(f"approx={approx} not valid, must be None or typeN (N=0,1,2)") return gt @@ -1389,7 +1386,7 @@ def eval_magnification( * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) * ``delta_z_cut`` (float) : Redshift cut so that ``zmin = z_cl + delta_z_cut``. - ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1555,7 +1552,7 @@ def eval_magnification_bias( * ``zmax`` (float) : Maximum redshift to be set as the source of the galaxy when performing the sum. (default=10.0) * ``delta_z_cut`` (float) : Redshift cut so that `zmin` = `z_cl` + `delta_z_cut`. - ``delta_z_cut`` is ignored if ``z_min`` is already provided. (default=0.1) + ``delta_z_cut`` is ignored if ``zmin`` is already provided. (default=0.1) verbose : bool, optional If True, the Einasto slope (alpha_ein) is printed out. Only availble for the NC and @@ -1786,7 +1783,7 @@ def _validate_z_src(self, loc_dict): else: raise ValueError(f"Unsupported z_src_info (='{loc_dict['z_src_info']}')") - def _validate_approx_z_src_info(self, loc_dict): + def _validate_approx_z_src_info(self, loc_dict, valid_approx=("type1", "type2")): r"""Validation for compatility between approx and z_src_info. The conditions are: * approx=None: z_src_info must be 'discrete' or 'distribution' @@ -1797,6 +1794,8 @@ def _validate_approx_z_src_info(self, loc_dict): ---------- locals_dict: dict Should be the call locals() + valid_approx: tuple + Valida possible values for approach. """ # check compatility between approx and z_src_info z_src_info, approx = loc_dict["z_src_info"], loc_dict["approx"] @@ -1806,7 +1805,7 @@ def _validate_approx_z_src_info(self, loc_dict): "approx=None requires z_src_info='discrete' or 'distribution'," f" z_src_info='{z_src_info}' was provided." ) - elif approx in ("type0", "type1", "type2"): + elif approx in valid_approx: if z_src_info != "beta": raise ValueError( f"approx='{approx}' requires z_src_info='beta', " From 82b16a67c88ea722f33f5d9a9ec659559d201264 Mon Sep 17 00:00:00 2001 From: Michel Date: Thu, 16 Apr 2026 18:08:53 +0200 Subject: [PATCH 13/13] hide type 0 --- clmm/theory/func_layer.py | 22 +++++++++++++--------- clmm/theory/parent_class.py | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index 92fb40cfc..9373d675c 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -912,15 +912,8 @@ def compute_reduced_tangential_shear( {1-\beta_s(z)\kappa_{\infty}}N(z)\text{d}z} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * ``type0`` : approach with all sources at the same redshift (Eq. 5 in - `Hoekstra et al 1998 `_). - - .. math:: - g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} - {1-\left<\beta_s\right>\kappa_{\infty}} - - * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in - `Applegate et al. 2014 `_, + * ``type1`` : First order expansion, the approach of Weighing the Giants - III (Eq. 6 + in `Applegate et al. 2014 `_, Eq. A2.4 from `Seitz & Schneider 1997 `_). @@ -968,6 +961,17 @@ def compute_reduced_tangential_shear( Reduced tangential shear """ + + # There is a type0 option for approx that does not really have a scientific application, + # but it is implemented (and hidden from the main documentation). + # We have to decide if it is going to be removed. + # * ``type0`` : approach with all sources at the same redshift (Eq. 5 in + # `Hoekstra et al 1998 `_). + # + # .. math:: + # g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} + # {1-\left<\beta_s\right>\kappa_{\infty}} + _modeling_object.validate_input = validate_input _modeling_object.set_cosmo(cosmo) _modeling_object.set_halo_density_profile( diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index c4b90f8e6..f7b8e6097 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -1183,16 +1183,9 @@ def eval_reduced_tangential_shear( {1-\beta_s(z)\kappa_{\infty}}N(z)\text{d}z} {\int_{z_{min}}^{z_{max}} N(z)\text{d}z} - * ``type0`` : approach with all sources at the same redshift (Eq. 5 in - `Hoekstra et al 1998 `_). - - .. math:: - g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} - {1-\left<\beta_s\right>\kappa_{\infty}} - - * ``type1`` : Same approach as in Weighing the Giants - III (Eq. 6 in - `Applegate et al. 2014 `_, - Eq. A2.4 from `Seitz & Schneider 1997 + * ``type1`` : First order expansion, the approach of Weighing the Giants - III (Eq. + 6 in `Applegate et al. 2014 `_, + Eq. A2.4 from `Seitz & Schneider 1997 `_). .. math:: @@ -1246,6 +1239,16 @@ def eval_reduced_tangential_shear( if self.halo_profile_model == "einasto" and verbose: print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") + # There is a type0 option for approx that does not really have a scientific application, + # but it is implemented (and hidden from the main documentation). + # We have to decide if it is going to be removed. + # * ``type0`` : approach with all sources at the same redshift (Eq. 5 in + # `Hoekstra et al 1998 `_). + # + # .. math:: + # g_t\approx\frac{\left<\beta_s\right>\gamma_{\infty}} + # {1-\left<\beta_s\right>\kappa_{\infty}} + # functions _validate_z_src, _validate_approx_z_src_info already safekeeps from this error: # pylint: disable=possibly-used-before-assignment if approx is None: