clenspy.lensing.LensingProfile

class clenspy.lensing.LensingProfile(z_cluster, m200, cosmology=None, concentration=4.0, model='NFW', include_2halo=True, backend_2halo='camb', z_source=1.0, halo_profile=None, two_halo=None, bias=None, k_grid=None)[source]

Bases: object

A unified class for weak lensing calculations, combining a 1-halo term (NfwProfile) with an optional linear-bias 2-halo term (TwoHaloTerm):

NOTE: masses are M_200m (200x the comoving mean matter density at z=0), inherited from NfwProfile – not M_200c.

NOTE: all quantities are h-free absolute units – mass in Msun, lengths in Mpc, Sigma and DeltaSigma in Msun/Mpc^2, wavenumbers in 1/Mpc.

\[\Sigma(R) = \Sigma_{\rm 1h}(R) + b(M)\, \rho_m\, \Sigma_{\rm 2h}(R)\]

where \(b(M)\) is the linear halo bias (BiasModel) and \(\rho_m = \Omega_{m,0}\,\rho_{c,0}\) is the present-day (comoving) mean matter density – no redshift dependence.

Parameters:
z_cluster

Redshift of the cluster.

Type:

float

m200

Halo mass M_200m [Msun], w.r.t. 200x the comoving mean matter density.

Type:

float

cosmology

Cosmology used for all calculations.

Type:

astropy.cosmology.Cosmology

concentration

Halo concentration c_200.

Type:

float

model

Halo profile model, normalised to lower case. See SUPPORTED_MODELS; currently only “nfw” is implemented.

Type:

str

include_2halo

Whether to add the 2-halo term to sigma/deltasigma/ fourier_profile.

Type:

bool

backend_2halo

PkGrid backend used for the 2-halo term’s P(k) (“camb” or “pyccl”).

Type:

str

z_source

Source redshift used for sigma_crit.

Type:

float

Notes

The constructor stores; it does not compute. Pkvec, two_halo_profile, bias_model, bias, halo_profile and sigma_crit are functools.cached_property, so LensingProfile(z_cluster=0.3, m200=1e14) costs nothing and only Pkvec starts a Boltzmann solver – on the first call that needs it. Pass two_halo=, bias= or halo_profile= to supply a collaborator instead, which is how a driver reuses one P(k) across many halos. Only _validate_inputs runs eagerly, so a bad redshift or mass still raises at construction rather than pages later.

deltasigma’s 2-halo term previously multiplied by a hardcoded 1e12 instead of self.rho_m (the factor sigma’s 2-halo term correctly uses - TwoHaloTerm.sigma/deltasigma are both derived from the same un-normalized xi(r) grid, so they need the same normalization). Confirmed this was wrong empirically (deltasigma came out ~1e10x larger than sigma, giving unphysical shear >> 1) and against tests/test_twohalo.py’s own cluster_toolkit-validated reference pattern, which uses TwoHaloTerm.deltasigma(...) * rho_m with no extra factor. Fixed to match.

__init__(z_cluster, m200, cosmology=None, concentration=4.0, model='NFW', include_2halo=True, backend_2halo='camb', z_source=1.0, halo_profile=None, two_halo=None, bias=None, k_grid=None)[source]
Parameters:
  • z_cluster (float) – Cluster (lens) redshift.

  • m200 (float) – Halo mass M_200m [Msun], w.r.t. 200x the comoving mean matter density.

  • cosmology (astropy.cosmology.Cosmology, optional) – Cosmology to use (default: fiducial_cosmology()).

  • concentration (float, optional) – Halo concentration c_200 (default: 4.0).

  • model (str, optional) – Halo profile model, case-insensitive and normalised to lower case. See SUPPORTED_MODELS; only “nfw” is implemented (default: “NFW”).

  • include_2halo (bool, optional) – Whether to add the 2-halo term (default: True). Nothing is built until an observable is evaluated – see the class Notes.

  • backend_2halo ({"camb", "pyccl"}, optional) – PkGrid backend for the 2-halo term’s P(k) (default: “camb”).

  • z_source (float, optional) – Source redshift, must exceed z_cluster (default: 1.0).

  • halo_profile (optional) – A pre-built 1-halo profile, e.g. NfwProfile. Built from model if omitted.

  • two_halo (optional) – A pre-built TwoHaloTerm. Built from k_grid and a fresh ~clenspy.cosmology.PkGrid if omitted – which is what runs the Boltzmann solver, so pass one to reuse a P(k).

  • bias (float, optional) – Linear halo bias \(b(M)\). Computed from the same P(k) as two_halo if omitted. Pass a number to fix it to a published value and skip that computation.

  • k_grid (array-like, optional) – Wavenumbers for the 2-halo term [1/Mpc]. Defaults to K_GRID_2HALO; see the note there for why that extent.

Return type:

None

Methods

__init__(z_cluster, m200[, cosmology, ...])

convergence(R)

Convergence (dimensionless).

deltasigma(R)

Excess surface density, in Msun/Mpc^2.

density(r)

3D density, in Msun/Mpc^3.

fourier_profile(k)

Intended: the mass-normalized Fourier transform \(u(k) \equiv \tilde\rho(k)/M\),

reduced_shear(R)

Reduced shear.

shear(R)

Tangential shear (dimensionless).

sigma(R)

Surface density, in Msun/Mpc^2.

Attributes

Pkvec

Linear P(k) on kvec at z_cluster [Mpc^3].

bias

Linear halo bias \(b(M_{200m})\), as supplied or computed.

bias_model

BiasModel on the same P(k) the 2-halo term uses.

halo_profile

as supplied, or built from model.

info

Return a summary dictionary of the profile parameters.

sigma_crit

\(\Sigma_{\rm crit}(z_l, z_s)\) [Msun/Mpc^2].

two_halo_profile

as supplied, or built from Pkvec.

property halo_profile

as supplied, or built from model.

Type:

The 1-halo profile

property Pkvec

Linear P(k) on kvec at z_cluster [Mpc^3]. Runs the solver.

property two_halo_profile

as supplied, or built from Pkvec.

Type:

The 2-halo term

property bias_model: BiasModel

BiasModel on the same P(k) the 2-halo term uses.

property bias: float

Linear halo bias \(b(M_{200m})\), as supplied or computed.

property sigma_crit: float

\(\Sigma_{\rm crit}(z_l, z_s)\) [Msun/Mpc^2].

deltasigma(R)[source]

Excess surface density, in Msun/Mpc^2.

\[\Delta\Sigma(R) = \Delta\Sigma_{\rm 1h}(R) + b(M)\, \Delta\Sigma_{\rm 2h}(R)\]

See the class Notes for a units caveat on the 2-halo term here.

Parameters:

R (float | ndarray)

Return type:

float | ndarray

sigma(R)[source]

Surface density, in Msun/Mpc^2.

\[\Sigma(R) = \Sigma_{\rm 1h}(R) + b(M)\, \rho_m\, \Sigma_{\rm 2h}(R)\]
Parameters:

R (float | ndarray)

Return type:

float | ndarray

density(r)[source]

3D density, in Msun/Mpc^3.

\[\rho(r) = \rho_{\rm 1h}(r) + \rho_m \left[1 + b(M)\, \xi_{\rm 2h}(r)\right]\]

where \(\xi_{\rm 2h}\) is the matter correlation function (TwoHaloTerm.xi).

Parameters:

r (float | ndarray)

Return type:

float | ndarray

shear(R)[source]

Tangential shear (dimensionless).

\[\gamma_t(R) = \frac{\Delta\Sigma(R)}{\Sigma_{\rm crit}}\]
Parameters:

R (float | ndarray)

Return type:

float | ndarray

convergence(R)[source]

Convergence (dimensionless).

\[\kappa(R) = \frac{\Sigma(R)}{\Sigma_{\rm crit}}\]
Parameters:

R (float | ndarray)

Return type:

float | ndarray

reduced_shear(R)[source]

Reduced shear.

\[g_t(R) = \frac{\gamma_t(R)}{1 - \kappa(R)}\]
Raises:

ValueError – If \(\kappa(R) \geq 1\) anywhere (the reduced-shear expansion is invalid in the strong-lensing regime).

Parameters:

R (float | ndarray)

Return type:

float | ndarray

fourier_profile(k)[source]

Intended: the mass-normalized Fourier transform \(u(k) \equiv \tilde\rho(k)/M\),

\[u(k) = u_{\rm 1h}(k) + \frac{b(M)}{M}\, P_{\rm 2h}(k).\]

NOTE: not what this currently returns. self.halo_profile.fourier(k) is \(\tilde\rho_{\rm 1h}(k)\) [Msun], not divided by m200 (see NfwProfile.fourier’s own NOTE) – while the 2-halo term here already is. The two terms are off by a factor of order \(M_{200}\) in scale, so the sum below is \(\tilde\rho_{\rm 1h}(k) + b(M)P_{\rm 2h}(k)/M\), not \(u(k)\): the 1-halo term dominates at every \(k\), and the 2-halo term is numerically swamped rather than combined. Divide self.halo_profile.fourier(k) by self.m200 to get the \(u(k)\) documented above; not fixed here since it changes this method’s public output.

Parameters:

k (float or np.ndarray) – Wavenumber [1/Mpc].

Returns:

float or np.ndarray – Scalar if k was scalar – see the NOTE for what it means.

Return type:

float | ndarray

property info: LensingProfileInfo

Return a summary dictionary of the profile parameters.