From a5c65c37047e84bb350a84610904f510012717f4 Mon Sep 17 00:00:00 2001 From: Celine Combet Date: Tue, 16 Jul 2024 08:37:02 +0200 Subject: [PATCH] Add miscentering as option of existing user functions --- clmm/theory/parent_class.py | 119 +++++++++--------------------------- 1 file changed, 29 insertions(+), 90 deletions(-) diff --git a/clmm/theory/parent_class.py b/clmm/theory/parent_class.py index 5bee7d4cc..f6e485f2d 100644 --- a/clmm/theory/parent_class.py +++ b/clmm/theory/parent_class.py @@ -538,31 +538,38 @@ def inv_sigmac(redshift): return 1.0 / _integ_pzfuncs(pzpdf, pzbins, kernel=inv_sigmac) - def eval_surface_density(self, r_proj, z_cl, verbose=False): + def eval_surface_density(self, r_proj, z_cl, r_mis=None, verbose=False): r"""Computes the surface mass density Parameters ---------- r_proj : array_like - Projected radial position from the cluster center in :math:`M\!pc`. + Projected radial position from the cluster center in :math:`M\!pc` z_cl: float Redshift of the cluster + r_mis : float, optional + Projected miscenter distance in :math:`M\!pc` Returns ------- numpy.ndarray, float 2D projected surface density in units of :math:`M_\odot\ Mpc^{-2}` + """ if self.validate_input: validate_argument(locals(), "r_proj", "float_array", argmin=0) validate_argument(locals(), "z_cl", float, argmin=0) - + if r_mis is not None: validate_argument(locals(), "r_mis", float, argmin=0) + if self.halo_profile_model == "einasto" and verbose: print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") - return self._eval_surface_density(r_proj=r_proj, z_cl=z_cl) + if r_mis is None: + return self._eval_surface_density(r_proj=r_proj, z_cl=z_cl) + else: + return self._eval_miscentered_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis=r_mis) - def eval_mean_surface_density(self, r_proj, z_cl, verbose=False): + def eval_mean_surface_density(self, r_proj, z_cl, r_mis=None, verbose=False): r"""Computes the mean value of surface density inside radius `r_proj` Parameters @@ -571,101 +578,29 @@ def eval_mean_surface_density(self, r_proj, z_cl, verbose=False): Projected radial position from the cluster center in :math:`M\!pc`. z_cl: float Redshift of the cluster - - Returns - ------- - numpy.ndarray, float - Mean surface density in units of :math:`M_\odot\ Mpc^{-2}`. - """ - if self.validate_input: - validate_argument(locals(), "r_proj", "float_array", argmin=0) - validate_argument(locals(), "z_cl", float, argmin=0) - - if self.halo_profile_model == "einasto" and verbose: - print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") - - return self._eval_mean_surface_density(r_proj=r_proj, z_cl=z_cl) - - def eval_excess_surface_density(self, r_proj, z_cl, verbose=False): - r"""Computes the excess surface density - - Parameters - ---------- - r_proj : array_like - Projected radial position from the cluster center in :math:`M\!pc`. - z_cl: float - Redshift of the cluster - - Returns - ------- - numpy.ndarray, float - Excess surface density in units of :math:`M_\odot\ Mpc^{-2}`. - """ - if self.validate_input: - validate_argument(locals(), "r_proj", "float_array", argmin=0) - validate_argument(locals(), "z_cl", float, argmin=0) - - if self.halo_profile_model == "einasto" and verbose: - print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") - - return self._eval_excess_surface_density(r_proj=r_proj, z_cl=z_cl) - - - def eval_miscentered_surface_density(self, r_proj, z_cl, r_mis, verbose=False): - r"""Computes the surface mass density - - Parameters - ---------- - r_proj : array_like - Projected radial position from the cluster center in :math:`M\!pc`. - z_cl: float - Redshift of the cluster - r_mis : float + r_mis : float, optional Projected miscenter distance in :math:`M\!pc`. - + Returns ------- numpy.ndarray, float - 2D projected surface density in units of :math:`M_\odot\ Mpc^{-2}` + Mean surface density in units of :math:`M_\odot\ Mpc^{-2}`. """ if self.validate_input: validate_argument(locals(), "r_proj", "float_array", argmin=0) - validate_argument(locals(), "r_mis", float, argmin=0) validate_argument(locals(), "z_cl", float, argmin=0) + if r_mis is not None: validate_argument(locals(), "r_mis", float, argmin=0) if self.halo_profile_model == "einasto" and verbose: print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") - return self._eval_miscentered_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis=r_mis) - - def eval_miscentered_mean_surface_density(self, r_proj, z_cl, r_mis, verbose=False): - r"""Computes the mean value of surface density inside radius `r_proj` - - Parameters - ---------- - r_proj : array_like - Projected radial position from the cluster center in :math:`M\!pc`. - z_cl: float - Redshift of the cluster - r_mis : float - Projected miscenter distance in :math:`M\!pc`. - - Returns - ------- - numpy.ndarray, float - Miscentered mean surface density in units of :math:`M_\odot\ Mpc^{-2}`. - """ - if self.validate_input: - validate_argument(locals(), "r_proj", "float_array", argmin=0) - validate_argument(locals(), "z_cl", float, argmin=0) - validate_argument(locals(), "r_mis", float, argmin=0) - - if self.halo_profile_model == "einasto" and verbose: - print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") + if r_mis is None: + return self._eval_mean_surface_density(r_proj=r_proj, z_cl=z_cl) + else: + return self._eval_miscentered_mean_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis=r_mis) - return self._eval_miscentered_mean_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis = r_mis) - def eval_miscentered_excess_surface_density(self, r_proj, z_cl, r_mis, verbose=False): + def eval_excess_surface_density(self, r_proj, z_cl, r_mis=None, verbose=False): r"""Computes the excess surface density Parameters @@ -674,23 +609,27 @@ def eval_miscentered_excess_surface_density(self, r_proj, z_cl, r_mis, verbose=F Projected radial position from the cluster center in :math:`M\!pc`. z_cl: float Redshift of the cluster - r_mis : float + r_mis : float, optional Projected miscenter distance in :math:`M\!pc`. Returns ------- numpy.ndarray, float - Miscentered excess surface density in units of :math:`M_\odot\ Mpc^{-2}`. + Excess surface density in units of :math:`M_\odot\ Mpc^{-2}`. """ if self.validate_input: validate_argument(locals(), "r_proj", "float_array", argmin=0) validate_argument(locals(), "z_cl", float, argmin=0) - validate_argument(locals(), "r_mis", float, argmin=0) + if r_mis is not None: validate_argument(locals(), "r_mis", float, argmin=0) if self.halo_profile_model == "einasto" and verbose: print(f"Einasto alpha = {self._get_einasto_alpha(z_cl=z_cl)}") - return self._eval_miscentered_excess_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis=r_mis) + if r_mis is None: + return self._eval_excess_surface_density(r_proj=r_proj, z_cl=z_cl) + else: + return self._eval_miscentered_excess_surface_density(r_proj=r_proj, z_cl=z_cl, r_mis=r_mis) + def eval_excess_surface_density_2h( self,