From ef88d5ae0ada2ac802ef3be00770c9f4ffbebc0a Mon Sep 17 00:00:00 2001 From: m-aguena Date: Tue, 23 May 2023 17:26:10 +0200 Subject: [PATCH 01/34] rename z_source->z_src --- clmm/dataops/__init__.py | 46 +++---- clmm/galaxycluster.py | 4 +- clmm/support/mock_data.py | 4 +- clmm/theory/func_layer.py | 116 +++++++++--------- ...e1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb | 14 +-- ...e2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb | 22 ++-- examples/NumCosmo/modeling_cmp_numcosmo.ipynb | 28 ++--- examples/Paper_v1.0/gt_and_use_case.ipynb | 8 +- examples/Paper_v1.0/mcmc.ipynb | 18 +-- .../demo_compute_deltasigma_weights.ipynb | 2 +- examples/demo_theory_functionality.ipynb | 14 +-- examples/demo_theory_functionality_oo.ipynb | 12 +- ...mple3_Fit_Halo_Mass_to_Shear_Catalog.ipynb | 4 +- .../Example4_Fit_Halo_mass_to_HSC_data.ipynb | 4 +- .../Example5_Fit_Halo_mass_to_DES_data.ipynb | 4 +- examples/other_flat_sky_limitations.ipynb | 8 +- ..._einasto_hernquist_benchmarks_fromNC.ipynb | 36 +++--- tests/test_clusterensemble.py | 4 +- tests/test_cosmo_parent.py | 10 +- tests/test_dataops.py | 50 ++++---- tests/test_galaxycluster.py | 38 +++--- tests/test_theory.py | 80 ++++++------ 22 files changed, 263 insertions(+), 263 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 4a2e3de44..a4c11af65 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -32,7 +32,7 @@ def compute_tangential_and_cross_components( is_deltasigma=False, cosmo=None, z_lens=None, - z_source=None, + z_src=None, sigma_c=None, use_pdz=False, pzbins=None, @@ -114,15 +114,15 @@ def compute_tangential_and_cross_components( z_lens: float, optional Redshift of the lens, required if `is_deltasigma` is True and `sigma_c` not provided. Not used if `sigma_c` is provided. - z_source: array, optional + z_src: array, optional Redshift of the source, required if `is_deltasigma` is True and `sigma_c` not provided. Not used if `sigma_c` is provided or `use_pdz=True`. sigma_c : float, optional Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`, - if provided, `cosmo`, `z_lens` and `z_source` are not used. + if provided, `cosmo`, `z_lens` and `z_src` are not used. use_pdz: bool Flag to use or not the source redshift p(z), required if `is_deltasigma` is True - and `sigma_c` not provided. If `False`, the point estimate provided by `z_source` is used. + and `sigma_c` not provided. If `False`, the point estimate provided by `z_src` is used. pzpdf : array, optional Photometric probablility density functions of the source galaxies, required if `is_deltasigma=True` and `use_pdz=True` and `sigma_c` not provided. @@ -154,7 +154,7 @@ def compute_tangential_and_cross_components( validate_argument(locals(), "geometry", str) validate_argument(locals(), "is_deltasigma", bool) validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True, none_ok=True) - validate_argument(locals(), "z_source", "float_array", argmin=0, eqmin=True, none_ok=True) + validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True, none_ok=True) validate_argument(locals(), "sigma_c", "float_array", none_ok=True) ra_source_, dec_source_, shear1_, shear2_ = arguments_consistency( [ra_source, dec_source, shear1, shear2], @@ -187,13 +187,13 @@ def compute_tangential_and_cross_components( if is_deltasigma: if sigma_c is None and use_pdz is False: # Need to verify that cosmology and redshifts are provided - if any(t_ is None for t_ in (z_lens, z_source, cosmo)): + if any(t_ is None for t_ in (z_lens, z_src, cosmo)): raise TypeError( "To compute DeltaSigma, please provide a " "i) cosmology, ii) redshift of lens and sources" ) - sigma_c = cosmo.eval_sigma_crit(z_lens, z_source) + sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) elif sigma_c is None: # Need to verify that cosmology, lens redshift, source redshift bins and @@ -216,7 +216,7 @@ def compute_tangential_and_cross_components( def compute_background_probability( - z_lens, z_source=None, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True + z_lens, z_src=None, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True ): r"""Probability for being a background galaxy @@ -224,14 +224,14 @@ def compute_background_probability( ---------- z_lens: float Redshift of the lens. - z_source: array, optional + z_src: array, optional Redshift of the source. Used only if pzpdf=pzbins=None. use_pdz: bool Flag to use or not the source redshif. If `False`, - the point estimate provided by `z_source` is used. + the point estimate provided by `z_src` is used. pzpdf : array, optional Photometric probablility density functions of the source galaxies. - Used instead of z_source if provided. + Used instead of z_src if provided. pzbins : array, optional Redshift axis on which the individual photoz pdf is tabulated. @@ -242,12 +242,12 @@ def compute_background_probability( """ if validate_input: validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True) - validate_argument(locals(), "z_source", "float_array", argmin=0, eqmin=True, none_ok=True) + validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True, none_ok=True) if use_pdz is False: - if z_source is None: - raise ValueError("z_source must be provided.") - p_background = np.array(z_source > z_lens, dtype=float) + if z_src is None: + raise ValueError("z_src must be provided.") + p_background = np.array(z_src > z_lens, dtype=float) else: if pzpdf is None or pzbins is None: raise ValueError("pzbins must be provided with pzpdf.") @@ -259,7 +259,7 @@ def compute_background_probability( def compute_galaxy_weights( z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=False, pzpdf=None, pzbins=None, @@ -315,16 +315,16 @@ def compute_galaxy_weights( ---------- z_lens: float Redshift of the lens. - z_source: array_like, optional + z_src: array_like, optional Redshift of the source (point estimate). Used only if `use_pdz=False`. cosmo: clmm.Comology object, None CLMM Cosmology object. use_pdz: bool Flag to use or not the source redshift p(z). If `False` (default) the point estimate - provided by `z_source` is used. + provided by `z_src` is used. pzpdf : array_like, optional Photometric probablility density functions of the source galaxies. - Used instead of z_source if `use_pdz=True` + Used instead of z_src if `use_pdz=True` pzbins : array_like, optional Redshift axis on which the individual photoz pdf is tabulated. Required if `use_pdz=True` use_shape_noise: bool @@ -357,7 +357,7 @@ def compute_galaxy_weights( """ if validate_input: validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True) - validate_argument(locals(), "z_source", "float_array", argmin=0, eqmin=True, none_ok=True) + validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True, none_ok=True) validate_argument(locals(), "use_pdz", bool) # validate_argument(locals(), 'pzpdf', 'float_array', none_ok=True) # validate_argument(locals(), 'pzbins', 'float_array', none_ok=True) @@ -380,12 +380,12 @@ def compute_galaxy_weights( else: if sigma_c is None and use_pdz is False: # Need to verify that cosmology and redshifts are provided - if any(t_ is None for t_ in (z_lens, z_source, cosmo)): + if any(t_ is None for t_ in (z_lens, z_src, cosmo)): raise TypeError( "To compute DeltaSigma, please provide a " "i) cosmology, ii) redshift of lens and sources" ) - sigma_c = cosmo.eval_sigma_crit(z_lens, z_source) + sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) elif sigma_c is None: # Need to verify that cosmology, lens redshift, source redshift bins and # source redshift pdf are provided @@ -402,7 +402,7 @@ def compute_galaxy_weights( w_ls_geo = 1.0 / sigma_c**2 # computing w_ls_shape - ngals = len(pzpdf) if use_pdz else len(z_source) + ngals = len(pzpdf) if use_pdz else len(z_src) err_e2 = np.zeros(ngals) if use_shape_noise: diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index cbd6e51e4..e386d76ab 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -308,7 +308,7 @@ def compute_background_probability( Probability for being a background galaxy """ cols = self._get_input_galdata( - {"pzpdf": "pzpdf", "pzbins": "pzbins"} if use_pdz else {"z_source": "z"} + {"pzpdf": "pzpdf", "pzbins": "pzbins"} if use_pdz else {"z_src": "z"} ) p_background = compute_background_probability( self.z, use_pdz=use_pdz, validate_input=self.validate_input, **cols @@ -374,7 +374,7 @@ def compute_galaxy_weights( if is_deltasigma: if "sigma_c" not in self.galcat.columns: self.add_critical_surface_density(cosmo, use_pdz=use_pdz) - col_dict.update({"z_source": "z", "sigma_c": "sigma_c"}) + col_dict.update({"z_src": "z", "sigma_c": "sigma_c"}) if use_shape_noise: col_dict.update( { diff --git a/clmm/support/mock_data.py b/clmm/support/mock_data.py index 8ef515f90..170b7c94b 100644 --- a/clmm/support/mock_data.py +++ b/clmm/support/mock_data.py @@ -392,7 +392,7 @@ def _generate_galaxy_catalog( mdelta=cluster_m, cdelta=cluster_c, z_cluster=cluster_z, - z_source=galaxy_catalog["ztrue"], + z_src=galaxy_catalog["ztrue"], cosmo=cosmo, delta_mdef=delta_so, halo_profile_model=halo_profile_model, @@ -407,7 +407,7 @@ def _generate_galaxy_catalog( mdelta=cluster_m, cdelta=cluster_c, z_cluster=cluster_z, - z_source=galaxy_catalog["ztrue"], + z_src=galaxy_catalog["ztrue"], cosmo=cosmo, delta_mdef=delta_so, halo_profile_model=halo_profile_model, diff --git a/clmm/theory/func_layer.py b/clmm/theory/func_layer.py index c3695453b..26c2786bf 100644 --- a/clmm/theory/func_layer.py +++ b/clmm/theory/func_layer.py @@ -525,7 +525,7 @@ def compute_tangential_shear( mdelta, cdelta, z_cluster, - z_source, + z_src, cosmo, delta_mdef=200, halo_profile_model="nfw", @@ -556,7 +556,7 @@ def compute_tangential_shear( Galaxy cluster NFW concentration. z_cluster : float Galaxy cluster redshift - z_source : array_like, float, function + 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 @@ -583,18 +583,18 @@ def compute_tangential_shear( 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_source` 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_source`. - It can be individual redshifts for each source galaxy when `z_source` is an array - or all sources are at the same redshift when `z_source` 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_source`. - `z_source` must be a one dimensional function. + * 'distribution' : 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_source`. - `z_source` 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. @@ -648,7 +648,7 @@ def compute_tangential_shear( tangential_shear = _modeling_object.eval_tangential_shear( r_proj, z_cluster, - z_source, + z_src, z_src_info=z_src_info, beta_kwargs=beta_kwargs, verbose=verbose, @@ -663,7 +663,7 @@ def compute_convergence( mdelta, cdelta, z_cluster, - z_source, + z_src, cosmo, delta_mdef=200, halo_profile_model="nfw", @@ -694,7 +694,7 @@ def compute_convergence( Galaxy cluster NFW concentration. z_cluster : float Galaxy cluster redshift - z_source : array_like, float, function + 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 @@ -721,18 +721,18 @@ def compute_convergence( 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_source` 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_source`. - It can be individual redshifts for each source galaxy when `z_source` is an array - or all sources are at the same redshift when `z_source` 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_source`. - `z_source` must be a one dimensional function. + * 'distribution' : 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_source`. - `z_source` 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. @@ -782,7 +782,7 @@ def compute_convergence( convergence = _modeling_object.eval_convergence( r_proj, z_cluster, - z_source, + z_src, z_src_info=z_src_info, beta_kwargs=beta_kwargs, verbose=verbose, @@ -797,7 +797,7 @@ def compute_reduced_tangential_shear( mdelta, cdelta, z_cluster, - z_source, + z_src, cosmo, delta_mdef=200, halo_profile_model="nfw", @@ -824,7 +824,7 @@ def compute_reduced_tangential_shear( Galaxy cluster NFW concentration. z_cluster : float Galaxy cluster redshift - z_source : array_like, float, function + 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 @@ -851,18 +851,18 @@ def compute_reduced_tangential_shear( 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_source` 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_source`. - It can be individual redshifts for each source galaxy when `z_source` is an array - or all sources are at the same redshift when `z_source` 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_source`. - `z_source` must be a one dimensional function. + * 'distribution' : 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_source`. - `z_source` 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. @@ -880,7 +880,7 @@ def compute_reduced_tangential_shear( * 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_source` pair individually. If `z_src_info='distribution'`, reduced + `r_proj, z_src` pair individually. If `z_src_info='distribution'`, reduced tangential shear at each value of `r_proj` is calculated as .. math:: @@ -952,7 +952,7 @@ def compute_reduced_tangential_shear( red_tangential_shear = _modeling_object.eval_reduced_tangential_shear( r_proj, z_cluster, - z_source, + z_src, z_src_info=z_src_info, approx=approx, beta_kwargs=beta_kwargs, @@ -968,7 +968,7 @@ def compute_magnification( mdelta, cdelta, z_cluster, - z_source, + z_src, cosmo, delta_mdef=200, halo_profile_model="nfw", @@ -995,7 +995,7 @@ def compute_magnification( Galaxy cluster NFW concentration. z_cluster : float Galaxy cluster redshift - z_source : array_like, float, function + 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 @@ -1022,18 +1022,18 @@ def compute_magnification( 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_source` 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_source`. - It can be individual redshifts for each source galaxy when `z_source` is an array - or all sources are at the same redshift when `z_source` 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_source`. - `z_source` must be a one dimensional function. + * 'distribution' : 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_source`. - `z_source` 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. @@ -1051,7 +1051,7 @@ def compute_magnification( * 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_source` pair individually. If `z_src_info='distribution'`, magnification + `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification at each value of `r_proj` is calculated as .. math:: @@ -1118,7 +1118,7 @@ def compute_magnification( magnification = _modeling_object.eval_magnification( r_proj, z_cluster, - z_source, + z_src, z_src_info=z_src_info, approx=approx, beta_kwargs=beta_kwargs, @@ -1135,7 +1135,7 @@ def compute_magnification_bias( mdelta, cdelta, z_cluster, - z_source, + z_src, cosmo, delta_mdef=200, halo_profile_model="nfw", @@ -1178,7 +1178,7 @@ def compute_magnification_bias( Galaxy cluster NFW concentration. z_cluster : float Galaxy cluster redshift - z_source : array_like, float, function + 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 @@ -1205,18 +1205,18 @@ def compute_magnification_bias( * 'virial' z_src_info : str, optional - Type of redshift information provided by the `z_source` 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_source`. - It can be individual redshifts for each source galaxy when `z_source` is an array - or all sources are at the same redshift when `z_source` 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_source`. - `z_source` must be a one dimensional function. + * 'distribution' : 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_source`. - `z_source` 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. @@ -1234,7 +1234,7 @@ def compute_magnification_bias( * 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_source` pair individually. If `z_src_info='distribution'`, magnification + `r_proj, z_src` pair individually. If `z_src_info='distribution'`, magnification bias at each value of `r_proj` is calculated as .. math:: @@ -1303,7 +1303,7 @@ def compute_magnification_bias( magnification_bias = _modeling_object.eval_magnification_bias( r_proj, z_cluster, - z_source, + z_src, alpha, z_src_info=z_src_info, approx=approx, diff --git a/examples/NumCosmo/Example1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb b/examples/NumCosmo/Example1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb index 2d963f0cd..1c6716138 100644 --- a/examples/NumCosmo/Example1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb +++ b/examples/NumCosmo/Example1_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb @@ -568,21 +568,21 @@ "source": [ "class GaussGammaT(Ncm.DataGaussDiag):\n", " z_cluster = GObject.Property(type=float, flags=GObject.PARAM_READWRITE)\n", - " z_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", + " z_src = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", " r_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", "\n", - " def __init__(self, z_cluster, r_source, z_source, gt_profile, moo=None):\n", + " def __init__(self, z_cluster, r_source, z_src, gt_profile, moo=None):\n", " Ncm.DataGaussDiag.__init__(self, n_points=len(gt_profile))\n", "\n", " self.moo = moo if moo else clmm.Modeling()\n", "\n", - " assert len(gt_profile) == len(z_source)\n", + " assert len(gt_profile) == len(z_src)\n", " assert len(gt_profile) == len(r_source)\n", "\n", " self.set_size(len(gt_profile))\n", "\n", " self.props.z_cluster = z_cluster\n", - " self.props.z_source = Ncm.Vector.new_array(z_source)\n", + " self.props.z_src = Ncm.Vector.new_array(z_src)\n", " self.props.r_source = Ncm.Vector.new_array(r_source)\n", "\n", " self.y.set_array(gt_profile)\n", @@ -611,7 +611,7 @@ " self.moo.eval_reduced_tangential_shear(\n", " self.props.r_source.dup_array(),\n", " self.props.z_cluster,\n", - " self.props.z_source.dup_array(),\n", + " self.props.z_src.dup_array(),\n", " )\n", " )\n", " return\n", @@ -643,8 +643,8 @@ "moo2.set_cosmo(cosmo)\n", "moo2.set_concentration(4.0)\n", "\n", - "ggt1 = GaussGammaT(z_cluster=cluster_z, r_source=r1, z_source=z1, gt_profile=gt_profile1, moo=moo1)\n", - "ggt2 = GaussGammaT(z_cluster=cluster_z, r_source=r2, z_source=z2, gt_profile=gt_profile2, moo=moo2)\n", + "ggt1 = GaussGammaT(z_cluster=cluster_z, r_source=r1, z_src=z1, gt_profile=gt_profile1, moo=moo1)\n", + "ggt2 = GaussGammaT(z_cluster=cluster_z, r_source=r2, z_src=z2, gt_profile=gt_profile2, moo=moo2)\n", "\n", "mset1 = ggt1.moo.get_mset()\n", "mset2 = ggt2.moo.get_mset()\n", diff --git a/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb b/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb index 2e1933930..2d4f0c5ab 100644 --- a/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb +++ b/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb @@ -444,7 +444,7 @@ "source": [ "class GaussGammaTErr(Ncm.DataGaussDiag):\n", " z_cluster = GObject.Property(type=float, flags=GObject.PARAM_READWRITE)\n", - " z_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", + " z_src = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", " r_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", " z_err = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", "\n", @@ -453,19 +453,19 @@ " self.moo = clmm.Modeling()\n", "\n", " def init_from_data(\n", - " self, z_cluster, r_source, z_source, gt_profile, gt_err, z_err=None, moo=None\n", + " self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None\n", " ):\n", " if moo:\n", " self.moo = moo\n", "\n", - " assert len(gt_profile) == len(z_source)\n", + " assert len(gt_profile) == len(z_src)\n", " assert len(gt_profile) == len(r_source)\n", " assert len(gt_profile) == len(gt_err)\n", "\n", " self.set_size(len(gt_profile))\n", "\n", " self.props.z_cluster = z_cluster\n", - " self.props.z_source = Ncm.Vector.new_array(z_source)\n", + " self.props.z_src = Ncm.Vector.new_array(z_src)\n", " self.props.r_source = Ncm.Vector.new_array(r_source)\n", " if z_err:\n", " self.props.r_source = Ncm.Vector.new_array(z_err)\n", @@ -496,7 +496,7 @@ " self.moo.eval_reduced_tangential_shear(\n", " self.props.r_source.dup_array(),\n", " self.props.z_cluster,\n", - " self.props.z_source.dup_array(),\n", + " self.props.z_src.dup_array(),\n", " )\n", " )\n", " return\n", @@ -536,7 +536,7 @@ "ggt1.init_from_data(\n", " z_cluster=cluster_z,\n", " r_source=profile1[\"radius\"],\n", - " z_source=profile1[\"z\"],\n", + " z_src=profile1[\"z\"],\n", " gt_profile=profile1[\"gt\"],\n", " gt_err=profile1[\"gt_err\"],\n", " moo=moo1,\n", @@ -544,7 +544,7 @@ "ggt2.init_from_data(\n", " z_cluster=cluster_z,\n", " r_source=profile2[\"radius\"],\n", - " z_source=profile2[\"z\"],\n", + " z_src=profile2[\"z\"],\n", " gt_profile=profile2[\"gt\"],\n", " gt_err=profile2[\"gt_err\"],\n", " moo=moo2,\n", @@ -552,7 +552,7 @@ "ggt3.init_from_data(\n", " z_cluster=cluster_z,\n", " r_source=profile3[\"radius\"],\n", - " z_source=profile3[\"z\"],\n", + " z_src=profile3[\"z\"],\n", " gt_profile=profile3[\"gt\"],\n", " gt_err=profile3[\"gt_err\"],\n", " moo=moo3,\n", @@ -806,7 +806,7 @@ "outputs": [], "source": [ "def create_nc_data_cluster_wl(\n", - " theta, g_t, z_source, z_cluster, cosmo, dist, sigma_z=None, sigma_g=None\n", + " theta, g_t, z_src, z_cluster, cosmo, dist, sigma_z=None, sigma_g=None\n", "):\n", " r = clmm.convert_units(theta, \"radians\", \"Mpc\", redshift=z_cluster, cosmo=cosmo)\n", " ga = Ncm.ObjArray.new()\n", @@ -819,11 +819,11 @@ "\n", " if sigma_z:\n", " gzgs = Nc.GalaxyRedshiftGauss()\n", - " z_obs = np.column_stack((z_source, (1.0 + z_source) * sigma_z))\n", + " z_obs = np.column_stack((z_src, (1.0 + z_src) * sigma_z))\n", " gzgs.set_obs(Ncm.Matrix.new_array(z_obs.flatten(), 2))\n", " else:\n", " gzgs = Nc.GalaxyRedshiftSpec()\n", - " gzgs.set_z(Ncm.Vector.new_array(z_source))\n", + " gzgs.set_z(Ncm.Vector.new_array(z_src))\n", "\n", " gwl = Nc.GalaxyWL(wl_dist=grsg, gz_dist=gzgs)\n", " ga.add(gwl)\n", diff --git a/examples/NumCosmo/modeling_cmp_numcosmo.ipynb b/examples/NumCosmo/modeling_cmp_numcosmo.ipynb index d7a2b5e3e..1e2accb3c 100644 --- a/examples/NumCosmo/modeling_cmp_numcosmo.ipynb +++ b/examples/NumCosmo/modeling_cmp_numcosmo.ipynb @@ -121,7 +121,7 @@ "cluster_concentration = 4.0\n", "z_max = 3.0\n", "z_cluster = 1.0\n", - "z_source = 2.0" + "z_src = 2.0" ] }, { @@ -446,8 +446,8 @@ } ], "source": [ - "Sigmac = pp.compute_critical_surface_density(cosmo_ccl, z_cluster=z_cluster, z_source=z_source)\n", - "nc_Sigmac = smd.sigma_critical(cosmo, z_source, z_cluster, z_cluster)\n", + "Sigmac = pp.compute_critical_surface_density(cosmo_ccl, z_cluster=z_cluster, z_src=z_src)\n", + "nc_Sigmac = smd.sigma_critical(cosmo, z_src, z_cluster, z_cluster)\n", "\n", "print(\"% 22.15g % 22.15g %e\" % (Sigmac, nc_Sigmac, Sigmac / nc_Sigmac - 1.0))" ] @@ -484,14 +484,14 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cluster,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo_ccl,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=\"nfw\",\n", " z_src_model=\"single_plane\",\n", ")\n", "\n", - "nc_gammat = np.array([smd.shear(dp, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d])\n", + "nc_gammat = np.array([smd.shear(dp, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d])\n", "\n", "fig, axs = compare(r3d, gammat, nc_gammat, x_name=\"radius [mpc]\", y_name=r\"{\\gamma_t}\")\n", "axs[0].set_xscale(\"log\")" @@ -529,7 +529,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cluster,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo_ccl,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=\"nfw\",\n", @@ -537,7 +537,7 @@ ")\n", "\n", "nc_kappa = np.array(\n", - " [smd.convergence(dp, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.convergence(dp, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "\n", "fig, axs = compare(r3d, kappa, nc_kappa, x_name=\"radius [mpc]\", y_name=r\"\\kappa\")\n", @@ -576,14 +576,14 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cluster,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo_ccl,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=\"nfw\",\n", " z_src_model=\"single_plane\",\n", ")\n", "nc_gt = np.array(\n", - " [smd.reduced_shear(dp, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.reduced_shear(dp, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "\n", "fig, axs = compare(r3d, gt, nc_gt, x_name=\"radius [mpc]\", y_name=r\"{g_t}\")\n", @@ -598,7 +598,7 @@ "outputs": [], "source": [ "nc_mu = np.array(\n", - " [smd.magnification(dp, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.magnification(dp, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")" ] }, @@ -639,15 +639,15 @@ "source": [ "config_dict = {\n", " \"dl\": dist.angular_diameter(cosmo, z_cluster) * cosmo.RH_Mpc(),\n", - " \"z_source\": z_source,\n", + " \"z_src\": z_src,\n", " \"cluster_mass\": cluster_mass,\n", " \"G[m3/km.s2]\": Ncm.C.G(),\n", " \"aexp_cluster\": 1.0 / (1.0 + z_cluster),\n", " \"density_profile_parametrization\": density_profile_parametrization,\n", - " \"ds\": dist.angular_diameter(cosmo, z_source) * cosmo.RH_Mpc(),\n", + " \"ds\": dist.angular_diameter(cosmo, z_src) * cosmo.RH_Mpc(),\n", " \"cosmo_Ob0\": cosmo_ccl[\"Omega_b0\"],\n", - " \"aexp_source\": 1.0 / (1.0 + z_source),\n", - " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_source) * cosmo.RH_Mpc(),\n", + " \"aexp_source\": 1.0 / (1.0 + z_src),\n", + " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_src) * cosmo.RH_Mpc(),\n", " \"z_cluster\": z_cluster,\n", " \"mass_Delta\": mass_Delta,\n", " \"lightspeed[km/s]\": Ncm.C.c() / 1000.0,\n", diff --git a/examples/Paper_v1.0/gt_and_use_case.ipynb b/examples/Paper_v1.0/gt_and_use_case.ipynb index a27f93b03..e2151870f 100644 --- a/examples/Paper_v1.0/gt_and_use_case.ipynb +++ b/examples/Paper_v1.0/gt_and_use_case.ipynb @@ -324,7 +324,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=np.mean(cluster.galcat[\"z\"]), # Mean value of source galaxies redshift\n", + " z_src=np.mean(cluster.galcat[\"z\"]), # Mean value of source galaxies redshift\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -368,7 +368,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=z_inf, # Redshift value at infinity\n", + " z_src=z_inf, # Redshift value at infinity\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -378,7 +378,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=z_inf, # Redshift value at infinity\n", + " z_src=z_inf, # Redshift value at infinity\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -420,7 +420,7 @@ " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", " # Redshift value of each source galaxy inside the radial bin\n", - " z_source=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", diff --git a/examples/Paper_v1.0/mcmc.ipynb b/examples/Paper_v1.0/mcmc.ipynb index d2c65d157..cca43b78b 100644 --- a/examples/Paper_v1.0/mcmc.ipynb +++ b/examples/Paper_v1.0/mcmc.ipynb @@ -442,7 +442,7 @@ "source": [ "class GaussGammaTErr(Ncm.DataGaussDiag):\n", " z_cluster = GObject.Property(type=float, flags=GObject.PARAM_READWRITE)\n", - " z_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", + " z_src = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", " r_source = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", " z_err = GObject.Property(type=Ncm.Vector, flags=GObject.PARAM_READWRITE)\n", "\n", @@ -451,19 +451,19 @@ " self.moo = clmm.Modeling()\n", "\n", " def init_from_data(\n", - " self, z_cluster, r_source, z_source, gt_profile, gt_err, z_err=None, moo=None\n", + " self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None\n", " ):\n", " if moo:\n", " self.moo = moo\n", "\n", - " assert len(gt_profile) == len(z_source)\n", + " assert len(gt_profile) == len(z_src)\n", " assert len(gt_profile) == len(r_source)\n", " assert len(gt_profile) == len(gt_err)\n", "\n", " self.set_size(len(gt_profile))\n", "\n", " self.props.z_cluster = z_cluster\n", - " self.props.z_source = Ncm.Vector.new_array(z_source)\n", + " self.props.z_src = Ncm.Vector.new_array(z_src)\n", " self.props.r_source = Ncm.Vector.new_array(r_source)\n", " if z_err:\n", " self.props.r_source = Ncm.Vector.new_array(z_err)\n", @@ -494,7 +494,7 @@ " self.moo.eval_reduced_tangential_shear(\n", " self.props.r_source.dup_array(),\n", " self.props.z_cluster,\n", - " self.props.z_source.dup_array(),\n", + " self.props.z_src.dup_array(),\n", " )\n", " )\n", " return\n", @@ -526,7 +526,7 @@ "ggt.init_from_data(\n", " z_cluster=cluster_z,\n", " r_source=cl.profile[\"radius\"],\n", - " z_source=cl.profile[\"z\"],\n", + " z_src=cl.profile[\"z\"],\n", " gt_profile=cl.profile[\"gt\"],\n", " gt_err=cl.profile[\"gt_err\"],\n", " moo=moo,\n", @@ -882,7 +882,7 @@ "outputs": [], "source": [ "def create_nc_data_cluster_wl(\n", - " theta, g_t, z_source, z_cluster, cosmo, dist, sigma_z=None, sigma_g=None\n", + " theta, g_t, z_src, z_cluster, cosmo, dist, sigma_z=None, sigma_g=None\n", "):\n", " r = clmm.convert_units(theta, \"radians\", \"Mpc\", redshift=z_cluster, cosmo=cosmo)\n", " ga = Ncm.ObjArray.new()\n", @@ -895,11 +895,11 @@ "\n", " if sigma_z:\n", " gzgs = Nc.GalaxyRedshiftGauss()\n", - " z_obs = np.column_stack((z_source, (1.0 + z_source) * sigma_z))\n", + " z_obs = np.column_stack((z_src, (1.0 + z_src) * sigma_z))\n", " gzgs.set_obs(Ncm.Matrix.new_array(z_obs.flatten(), 2))\n", " else:\n", " gzgs = Nc.GalaxyRedshiftSpec()\n", - " gzgs.set_z(Ncm.Vector.new_array(z_source))\n", + " gzgs.set_z(Ncm.Vector.new_array(z_src))\n", "\n", " gwl = Nc.GalaxyWL(wl_dist=grsg, gz_dist=gzgs)\n", " ga.add(gwl)\n", diff --git a/examples/demo_compute_deltasigma_weights.ipynb b/examples/demo_compute_deltasigma_weights.ipynb index 2ebdaeb7c..450099c20 100644 --- a/examples/demo_compute_deltasigma_weights.ipynb +++ b/examples/demo_compute_deltasigma_weights.ipynb @@ -178,7 +178,7 @@ "w_ls_true = compute_galaxy_weights(\n", " cluster_z,\n", " cosmo,\n", - " z_source=z_gal,\n", + " z_src=z_gal,\n", " shape_component1=noisy_data_z[\"e1\"],\n", " shape_component2=noisy_data_z[\"e2\"],\n", " shape_component1_err=noisy_data_z[\"e_err\"],\n", diff --git a/examples/demo_theory_functionality.ipynb b/examples/demo_theory_functionality.ipynb index c800d5811..1df966c70 100644 --- a/examples/demo_theory_functionality.ipynb +++ b/examples/demo_theory_functionality.ipynb @@ -113,7 +113,7 @@ "z_cl = 1.0\n", "\n", "# source properties\n", - "z_source = 2.0 # all sources in the same plan\n", + "z_src = 2.0 # all sources in the same plan\n", "z_distrib_func = clmm.redshift.distributions.chang2013 # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] @@ -190,7 +190,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", @@ -209,7 +209,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", @@ -228,7 +228,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", @@ -247,7 +247,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", @@ -267,7 +267,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_source,\n", + " z_src=z_src,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", @@ -293,7 +293,7 @@ " mdelta=cluster_mass,\n", " cdelta=cluster_concentration,\n", " z_cluster=z_cl,\n", - " z_source=z_distrib_func,\n", + " z_src=z_distrib_func,\n", " cosmo=cosmo,\n", " delta_mdef=mass_Delta,\n", " halo_profile_model=density_profile_parametrization,\n", diff --git a/examples/demo_theory_functionality_oo.ipynb b/examples/demo_theory_functionality_oo.ipynb index 27ad45bd9..6004d63ca 100644 --- a/examples/demo_theory_functionality_oo.ipynb +++ b/examples/demo_theory_functionality_oo.ipynb @@ -116,7 +116,7 @@ "z_cl = 1.0\n", "\n", "# source properties\n", - "z_source = 2.0 # all sources in the same plane\n", + "z_src = 2.0 # all sources in the same plane\n", "z_distrib_func = clmm.redshift.distributions.chang2013 # sources redshift following a distribution\n", "alpha = [2, -0.5]" ] @@ -138,17 +138,17 @@ "rho = moo.eval_3d_density(r3d, z_cl)\n", "Sigma = moo.eval_surface_density(r3d, z_cl)\n", "DeltaSigma = moo.eval_excess_surface_density(r3d, z_cl)\n", - "gammat = moo.eval_tangential_shear(r3d, z_cl, z_source)\n", - "kappa = moo.eval_convergence(r3d, z_cl, z_source)\n", + "gammat = moo.eval_tangential_shear(r3d, z_cl, z_src)\n", + "kappa = moo.eval_convergence(r3d, z_cl, z_src)\n", "\n", - "gt = moo.eval_reduced_tangential_shear(r3d, z_cl, z_source)\n", + "gt = moo.eval_reduced_tangential_shear(r3d, z_cl, z_src)\n", "# Lensing quantities assuming sources follow a given redshift distribution.\n", "gt_z = moo.eval_reduced_tangential_shear(\n", " r3d, z_cl, z_distrib_func, z_src_info=\"distribution\", approx=\"order2\"\n", ")\n", "\n", - "mu = moo.eval_magnification(r3d, z_cl, z_source)\n", - "mu_bias = moo.eval_magnification_bias(r3d, z_cl, z_source, alpha)" + "mu = moo.eval_magnification(r3d, z_cl, z_src)\n", + "mu_bias = moo.eval_magnification_bias(r3d, z_cl, z_src, alpha)" ] }, { 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 e3efcfc9b..0cbce9bb9 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 @@ -452,7 +452,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=clmm.redshift.distributions.chang2013, # We provide the redshift distribution (default: Chang et al. 2013) for calculating the beta_s statistics\n", + " z_src=clmm.redshift.distributions.chang2013, # We provide the redshift distribution (default: Chang et al. 2013) for calculating the beta_s statistics\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " # massdef='critical',\n", @@ -473,7 +473,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=clmm.redshift.distributions.chang2013, # We provide the redshift distribution (default: Chang et al. 2013) for calculating the beta_s statistics\n", + " z_src=clmm.redshift.distributions.chang2013, # We provide the redshift distribution (default: Chang et al. 2013) for calculating the beta_s statistics\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " # massdef='critical',\n", 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 45a76d5ec..0c423d25b 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 @@ -476,7 +476,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", + " z_src=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", " z_src_info=\"beta\",\n", " approx=\"order1\",\n", " cosmo=cosmo,\n", @@ -504,7 +504,7 @@ " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", " # Redshift value of each source galaxy inside the radial bin\n", - " z_source=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\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 a1439d1f7..3e24d6f69 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 @@ -404,7 +404,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", + " z_src=(bs_mean, bs2_mean), # tuple of (bs_mean, bs2_mean)\n", " z_src_info=\"beta\",\n", " approx=\"order1\",\n", " cosmo=cosmo,\n", @@ -432,7 +432,7 @@ " cdelta=concentration, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", " # Redshift value of each source galaxy inside the radial bin\n", - " z_source=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " massdef=\"critical\",\n", diff --git a/examples/other_flat_sky_limitations.ipynb b/examples/other_flat_sky_limitations.ipynb index 75a9b2ea6..4447c592b 100644 --- a/examples/other_flat_sky_limitations.ipynb +++ b/examples/other_flat_sky_limitations.ipynb @@ -371,7 +371,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=np.mean(cluster.galcat[\"z\"]), # Mean value of source galaxies redshift\n", + " z_src=np.mean(cluster.galcat[\"z\"]), # Mean value of source galaxies redshift\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -415,7 +415,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=z_inf, # Redshift value at infinity\n", + " z_src=z_inf, # Redshift value at infinity\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -425,7 +425,7 @@ " mdelta=10**logm, # Mass of the cluster [M_sun]\n", " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", - " z_source=z_inf, # Redshift value at infinity\n", + " z_src=z_inf, # Redshift value at infinity\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", @@ -467,7 +467,7 @@ " cdelta=4, # Concentration of the cluster\n", " z_cluster=cluster_z, # Redshift of the cluster\n", " # Redshift value of each source galaxy inside the radial bin\n", - " z_source=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", " cosmo=cosmo,\n", " delta_mdef=200,\n", " halo_profile_model=\"nfw\",\n", diff --git a/tests/data/numcosmo/generate_einasto_hernquist_benchmarks_fromNC.ipynb b/tests/data/numcosmo/generate_einasto_hernquist_benchmarks_fromNC.ipynb index d7c41f1ea..c1ab306fb 100644 --- a/tests/data/numcosmo/generate_einasto_hernquist_benchmarks_fromNC.ipynb +++ b/tests/data/numcosmo/generate_einasto_hernquist_benchmarks_fromNC.ipynb @@ -107,7 +107,7 @@ "cluster_concentration = 4.0\n", "z_max = 3.0\n", "z_cluster = 1.0\n", - "z_source = 2.0" + "z_src = 2.0" ] }, { @@ -487,23 +487,23 @@ "metadata": {}, "outputs": [], "source": [ - "nc_Sigmac = smd.sigma_critical(cosmo, z_source, z_cluster, z_cluster)\n", + "nc_Sigmac = smd.sigma_critical(cosmo, z_src, z_cluster, z_cluster)\n", "\n", "nc_rho_ein = np.array([nc_ein.eval_density(cosmo, r3d_i, z_cluster) for r3d_i in r3d])\n", "nc_Sigma_ein = np.array([smd.sigma(nc_ein, cosmo, r3d_i, z_cluster) for r3d_i in r3d])\n", "nc_SigmaMean_ein = np.array([smd.sigma_mean(nc_ein, cosmo, r3d_i, z_cluster) for r3d_i in r3d])\n", "nc_DeltaSigma_ein = nc_SigmaMean_ein - nc_Sigma_ein\n", "nc_gammat_ein = np.array(\n", - " [smd.shear(nc_ein, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.shear(nc_ein, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_kappa_ein = np.array(\n", - " [smd.convergence(nc_ein, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.convergence(nc_ein, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_gt_ein = np.array(\n", - " [smd.reduced_shear(nc_ein, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.reduced_shear(nc_ein, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_mu_ein = np.array(\n", - " [smd.magnification(nc_ein, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.magnification(nc_ein, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")" ] }, @@ -525,16 +525,16 @@ "nc_SigmaMean_her = np.array([smd.sigma_mean(nc_her, cosmo, r3d_i, z_cluster) for r3d_i in r3d])\n", "nc_DeltaSigma_her = nc_SigmaMean_her - nc_Sigma_her\n", "nc_gammat_her = np.array(\n", - " [smd.shear(nc_her, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.shear(nc_her, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_kappa_her = np.array(\n", - " [smd.convergence(nc_her, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.convergence(nc_her, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_gt_her = np.array(\n", - " [smd.reduced_shear(nc_her, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.reduced_shear(nc_her, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")\n", "nc_mu_her = np.array(\n", - " [smd.magnification(nc_her, cosmo, r3d_i, z_source, z_cluster, z_cluster) for r3d_i in r3d]\n", + " [smd.magnification(nc_her, cosmo, r3d_i, z_src, z_cluster, z_cluster) for r3d_i in r3d]\n", ")" ] }, @@ -601,15 +601,15 @@ "source": [ "config_dict_ein = {\n", " \"dl\": dist.angular_diameter(cosmo, z_cluster) * cosmo.RH_Mpc(),\n", - " \"z_source\": z_source,\n", + " \"z_src\": z_src,\n", " \"cluster_mass\": cluster_mass,\n", " \"G[m3/km.s2]\": Ncm.C.G(),\n", " \"aexp_cluster\": 1.0 / (1.0 + z_cluster),\n", " \"density_profile_parametrization\": \"einasto\",\n", - " \"ds\": dist.angular_diameter(cosmo, z_source) * cosmo.RH_Mpc(),\n", + " \"ds\": dist.angular_diameter(cosmo, z_src) * cosmo.RH_Mpc(),\n", " \"cosmo_Ob0\": cosmo_ccl[\"Omega_b0\"],\n", - " \"aexp_source\": 1.0 / (1.0 + z_source),\n", - " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_source) * cosmo.RH_Mpc(),\n", + " \"aexp_source\": 1.0 / (1.0 + z_src),\n", + " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_src) * cosmo.RH_Mpc(),\n", " \"z_cluster\": z_cluster,\n", " \"mass_Delta\": mass_Delta,\n", " \"lightspeed[km/s]\": Ncm.C.c() / 1000.0,\n", @@ -637,15 +637,15 @@ "source": [ "config_dict_her = {\n", " \"dl\": dist.angular_diameter(cosmo, z_cluster) * cosmo.RH_Mpc(),\n", - " \"z_source\": z_source,\n", + " \"z_src\": z_src,\n", " \"cluster_mass\": cluster_mass,\n", " \"G[m3/km.s2]\": Ncm.C.G(),\n", " \"aexp_cluster\": 1.0 / (1.0 + z_cluster),\n", " \"density_profile_parametrization\": \"hernquist\",\n", - " \"ds\": dist.angular_diameter(cosmo, z_source) * cosmo.RH_Mpc(),\n", + " \"ds\": dist.angular_diameter(cosmo, z_src) * cosmo.RH_Mpc(),\n", " \"cosmo_Ob0\": cosmo_ccl[\"Omega_b0\"],\n", - " \"aexp_source\": 1.0 / (1.0 + z_source),\n", - " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_source) * cosmo.RH_Mpc(),\n", + " \"aexp_source\": 1.0 / (1.0 + z_src),\n", + " \"dsl\": dist.angular_diameter_z1_z2(cosmo, z_cluster, z_src) * cosmo.RH_Mpc(),\n", " \"z_cluster\": z_cluster,\n", " \"mass_Delta\": mass_Delta,\n", " \"lightspeed[km/s]\": Ncm.C.c() / 1000.0,\n", diff --git a/tests/test_clusterensemble.py b/tests/test_clusterensemble.py index 7751d7bb6..63c3d3958 100644 --- a/tests/test_clusterensemble.py +++ b/tests/test_clusterensemble.py @@ -23,7 +23,7 @@ def test_cluster_ensemble(): ra_source = [120.1, 119.9] dec_source = [41.9, 42.2] theta_source = [0.0025, 0.015] - z_source = [1.0, 2.0] + z_src = [1.0, 2.0] shear1 = [0.2, 0.4] shear2 = [0.3, 0.5] w_ls = [1.0e-30, 1.0e-31] @@ -33,7 +33,7 @@ def test_cluster_ensemble(): names = ("ra", "dec", "theta", "w_ls", "e1", "e2", "z") galcat = clmm.GCData( - [ra_source, dec_source, theta_source, w_ls, shear1, shear2, z_source], names=names + [ra_source, dec_source, theta_source, w_ls, shear1, shear2, z_src], names=names ) # create cluster cluster = clmm.GalaxyCluster( diff --git a/tests/test_cosmo_parent.py b/tests/test_cosmo_parent.py index b65666e97..67de814db 100644 --- a/tests/test_cosmo_parent.py +++ b/tests/test_cosmo_parent.py @@ -269,7 +269,7 @@ def test_eval_sigma_crit(modeling_data): cosmo, testcase, _ = load_validation_config() assert_allclose( - cosmo.eval_sigma_crit(testcase["z_cluster"], testcase["z_source"]), + cosmo.eval_sigma_crit(testcase["z_cluster"], testcase["z_src"]), testcase["nc_Sigmac"], reltol, ) @@ -278,7 +278,7 @@ def test_eval_sigma_crit(modeling_data): assert_raises(ValueError, cosmo.eval_sigma_crit, 0.2, -0.3) # Check behaviour when sources are in front of the lens z_cluster = 0.3 - z_source = 0.2 - assert_allclose(cosmo.eval_sigma_crit(z_cluster, z_source), np.inf, 1.0e-10) - z_source = [0.2, 0.12, 0.25] - assert_allclose(cosmo.eval_sigma_crit(z_cluster, z_source), [np.inf, np.inf, np.inf], 1.0e-10) + z_src = 0.2 + assert_allclose(cosmo.eval_sigma_crit(z_cluster, z_src), np.inf, 1.0e-10) + z_src = [0.2, 0.12, 0.25] + assert_allclose(cosmo.eval_sigma_crit(z_cluster, z_src), [np.inf, np.inf, np.inf], 1.0e-10) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index aae203de5..b55fd897a 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -457,7 +457,7 @@ def test_compute_tangential_and_cross_components(modeling_data): is_deltasigma=True, cosmo=None, z_lens=z_lens, - z_source=gals["z"], + z_src=gals["z"], ) assert_raises( TypeError, @@ -471,7 +471,7 @@ def test_compute_tangential_and_cross_components(modeling_data): is_deltasigma=True, cosmo=cosmo, z_lens=None, - z_source=gals["z"], + z_src=gals["z"], ) assert_raises( TypeError, @@ -485,7 +485,7 @@ def test_compute_tangential_and_cross_components(modeling_data): is_deltasigma=True, cosmo=cosmo, z_lens=z_lens, - z_source=None, + z_src=None, ) # test missing info for use_pdz=True @@ -502,7 +502,7 @@ def test_compute_tangential_and_cross_components(modeling_data): use_pdz=True, cosmo=cosmo, z_lens=z_lens, - z_source=None, + z_src=None, ) # Trying to got through line 173 of dataops/__init__.py @@ -517,7 +517,7 @@ def test_compute_tangential_and_cross_components(modeling_data): use_pdz=True, cosmo=cosmo, z_lens=z_lens, - z_source=None, + z_src=None, pzbins=[[0.55, 0.6, 0.65, 0.7, 0.75]], pzpdf=[[0.01, 1, 0.01, 0.001, 0.0001]], ) @@ -534,7 +534,7 @@ def test_compute_tangential_and_cross_components(modeling_data): is_deltasigma=True, cosmo=cosmo, z_lens=z_lens, - z_source=gals["z"], + z_src=gals["z"], geometry=geometry, ) assert_allclose( @@ -587,11 +587,11 @@ def test_compute_tangential_and_cross_components(modeling_data): def test_compute_background_probability(): """test for compute background probability""" z_lens = 0.1 - z_source = np.array([0.22, 0.35, 1.7]) + z_src = np.array([0.22, 0.35, 1.7]) # true redshift p_bkg = da.compute_background_probability( - z_lens, z_source=z_source, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True + z_lens, z_src=z_src, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True ) expected = np.array([1.0, 1.0, 1.0]) assert_allclose(p_bkg, expected, **TOLERANCE) @@ -599,7 +599,7 @@ def test_compute_background_probability(): ValueError, da.compute_background_probability, z_lens, - z_source=None, + z_src=None, use_pdz=False, pzpdf=None, pzbins=None, @@ -608,13 +608,13 @@ def test_compute_background_probability(): # photoz + deltasigma pzbin = np.linspace(0.0001, 5, 100) - pzbins = [pzbin for i in range(z_source.size)] - pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_source] + pzbins = [pzbin for i in range(z_src.size)] + pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] assert_raises( ValueError, da.compute_background_probability, z_lens, - z_source=z_source, + z_src=z_src, use_pdz=True, pzpdf=None, pzbins=pzbins, @@ -626,7 +626,7 @@ def test_compute_galaxy_weights(): """test for compute galaxy weights""" cosmo = clmm.Cosmology(H0=71.0, Omega_dm0=0.265 - 0.0448, Omega_b0=0.0448, Omega_k0=0.0) z_lens = 0.1 - z_source = [0.22, 0.35, 1.7] + z_src = [0.22, 0.35, 1.7] shape_component1 = np.array([0.143, 0.063, -0.171]) shape_component2 = np.array([-0.011, 0.012, -0.250]) shape_component1_err = np.array([0.11, 0.01, 0.2]) @@ -636,7 +636,7 @@ def test_compute_galaxy_weights(): weights = da.compute_galaxy_weights( z_lens, cosmo, - z_source=z_source, + z_src=z_src, use_pdz=False, pzpdf=None, pzbins=None, @@ -654,12 +654,12 @@ def test_compute_galaxy_weights(): # photoz + deltasigma pzbin = np.linspace(0.0001, 5, 100) - pzbins = [pzbin for i in range(len(z_source))] - pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_source] + pzbins = [pzbin for i in range(len(z_src))] + pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] weights = da.compute_galaxy_weights( z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -679,11 +679,11 @@ def test_compute_galaxy_weights(): # photoz + deltasigma - shared bins pzbin = np.linspace(0.0001, 5, 100) pzbins = pzbin - pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_source] + pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] weights = da.compute_galaxy_weights( z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -704,7 +704,7 @@ def test_compute_galaxy_weights(): weights = da.compute_galaxy_weights( z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -725,7 +725,7 @@ def test_compute_galaxy_weights(): weights = da.compute_galaxy_weights( z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -748,7 +748,7 @@ def test_compute_galaxy_weights(): da.compute_galaxy_weights, z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -768,7 +768,7 @@ def test_compute_galaxy_weights(): da.compute_galaxy_weights, z_lens, cosmo, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, @@ -785,7 +785,7 @@ def test_compute_galaxy_weights(): da.compute_galaxy_weights, z_lens, cosmo=None, - z_source=None, + z_src=None, use_pdz=False, pzpdf=pzpdf, pzbins=pzbins, @@ -803,7 +803,7 @@ def test_compute_galaxy_weights(): da.compute_galaxy_weights, z_lens, cosmo=None, - z_source=None, + z_src=None, use_pdz=True, pzpdf=pzpdf, pzbins=pzbins, diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index a3987255f..b9c674d9f 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -140,12 +140,12 @@ def test_print_gc(): def test_integrity_of_lensfuncs(): """test integrity of lensfuncs""" ra_source, dec_source = [120.1, 119.9, 119.9], [41.9, 42.2, 42.2] - id_source, z_source = [1, 2, 3], [1, 1, 1] + id_source, z_src = [1, 2, 3], [1, 1, 1] shape_component1 = np.array([0.143, 0.063, -0.171]) shape_component2 = np.array([-0.011, 0.012, -0.250]) galcat = GCData( - [ra_source, dec_source, z_source, id_source, shape_component1, shape_component2], + [ra_source, dec_source, z_src, id_source, shape_component1, shape_component2], names=("ra", "dec", "z", "id", "e1", "e2"), ) galcat_noz = GCData([ra_source, dec_source, id_source], names=("ra", "dec", "id")) @@ -168,8 +168,8 @@ def test_integrity_of_lensfuncs(): pzbins = np.linspace(0.0001, 5, 100) cluster = clmm.GalaxyCluster(unique_id="1", ra=161.3, dec=34.0, z=0.3, galcat=galcat) cluster.galcat.pzpdf_info["zbins"] = pzbins - cluster.galcat["pzbins"] = [pzbins for i in range(len(z_source))] - cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_source] + cluster.galcat["pzbins"] = [pzbins for i in range(len(z_src))] + cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_src] for pztype in ("individual_bins", "shared_bins"): cluster.galcat.pzpdf_info["type"] = pztype @@ -183,14 +183,14 @@ def test_integrity_of_lensfuncs(): def test_integrity_of_probfuncs(): """test integrity of prob funcs""" ra_source, dec_source = [120.1, 119.9, 119.9], [41.9, 42.2, 42.2] - id_source, z_sources = [1, 2, 3], [1, 1, 1] + id_source, z_srcs = [1, 2, 3], [1, 1, 1] cluster = clmm.GalaxyCluster( unique_id="1", ra=161.3, dec=34.0, z=0.3, galcat=GCData( - [ra_source, dec_source, z_sources, id_source], names=("ra", "dec", "z", "id") + [ra_source, dec_source, z_srcs, id_source], names=("ra", "dec", "z", "id") ), ) # true redshift @@ -202,8 +202,8 @@ def test_integrity_of_probfuncs(): assert_raises(TypeError, cluster.compute_background_probability, use_photoz=True) pzbins = np.linspace(0.0001, 5, 1000) cluster.galcat.pzpdf_info["zbins"] = pzbins - cluster.galcat["pzbins"] = [pzbins for i in range(len(z_sources))] - cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.01) for z in z_sources] + cluster.galcat["pzbins"] = [pzbins for i in range(len(z_srcs))] + cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.01) for z in z_srcs] for pztype in ("individual_bins", "shared_bins"): cluster.galcat.pzpdf_info["type"] = pztype cluster.compute_background_probability(use_pdz=True, p_background_name="p_bkg_pz") @@ -214,7 +214,7 @@ def test_integrity_of_weightfuncs(): """test integrity of weight funcs""" cosmo = clmm.Cosmology(H0=71.0, Omega_dm0=0.265 - 0.0448, Omega_b0=0.0448, Omega_k0=0.0) z_lens = 0.1 - z_source = [0.22, 0.35, 1.7] + z_src = [0.22, 0.35, 1.7] shape_component1 = np.array([0.143, 0.063, -0.171]) shape_component2 = np.array([-0.011, 0.012, -0.250]) shape_component1_err = np.array([0.11, 0.01, 0.2]) @@ -231,7 +231,7 @@ def test_integrity_of_weightfuncs(): shape_component2, shape_component1_err, shape_component2_err, - z_source, + z_src, ], names=("e1", "e2", "e1_err", "e2_err", "z"), ), @@ -245,8 +245,8 @@ def test_integrity_of_weightfuncs(): # photoz + deltasigma pzbins = np.linspace(0.0001, 5, 100) cluster.galcat.pzpdf_info["zbins"] = pzbins - cluster.galcat["pzbins"] = [pzbins for i in range(len(z_source))] - cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_source] + cluster.galcat["pzbins"] = [pzbins for i in range(len(z_src))] + cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_src] for pztype in ("individual_bins", "shared_bins"): cluster.galcat.pzpdf_info["type"] = pztype cluster.compute_galaxy_weights( @@ -271,11 +271,11 @@ def test_integrity_of_weightfuncs(): def test_pzpdf_random_draw(): """test draw_gal_z_from_pdz""" z_lens = 0.1 - z_source = [0.22, 0.35, 1.7] + z_src = [0.22, 0.35, 1.7] shape_component1 = np.array([0.143, 0.063, -0.171]) shape_component2 = np.array([-0.011, 0.012, -0.250]) cluster_kwargs = dict(unique_id="1", ra=161.3, dec=34.0, z=z_lens) - gcat_args = [shape_component1, shape_component2, z_source] + gcat_args = [shape_component1, shape_component2, z_src] gcat_kwargs = {"names": ("e1", "e2", "z")} # set up photoz @@ -288,19 +288,19 @@ def test_pzpdf_random_draw(): assert_raises(TypeError, cluster.draw_gal_z_from_pdz) cluster.galcat.pzpdf_info["zbins"] = pzbins - cluster.galcat["pzbins"] = [pzbins for i in range(len(z_source))] + cluster.galcat["pzbins"] = [pzbins for i in range(len(z_src))] assert_raises(TypeError, cluster.draw_gal_z_from_pdz) cluster.galcat.pzpdf_info.pop("zbins") cluster.galcat.remove_column("pzbins") cluster.galcat["pzpdf"] = [ - multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_source + multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_src ] assert_raises(TypeError, cluster.draw_gal_z_from_pdz) # add pzbins back to galcat cluster.galcat.pzpdf_info["zbins"] = pzbins - cluster.galcat["pzbins"] = [pzbins for i in range(len(z_source))] + cluster.galcat["pzbins"] = [pzbins for i in range(len(z_src))] # test raising TypeError when the name of the new column is already in cluster.galcat # also test default overwrite=False and zcol_out='z' assert_raises(TypeError, cluster.draw_gal_z_from_pdz) @@ -349,7 +349,7 @@ def test_plot_profiles(): ra_lens, dec_lens, z_lens = 120.0, 42.0, 0.5 ra_source = [120.1, 119.9] dec_source = [41.9, 42.2] - z_source = [1.0, 2.0] + z_src = [1.0, 2.0] shear1 = [0.2, 0.4] shear2 = [0.3, 0.5] # Set up radial values @@ -362,7 +362,7 @@ def test_plot_profiles(): dec=dec_lens, z=z_lens, galcat=GCData( - [ra_source, dec_source, shear1, shear2, z_source], names=("ra", "dec", "e1", "e2", "z") + [ra_source, dec_source, shear1, shear2, z_src], names=("ra", "dec", "e1", "e2", "z") ), ) cluster.compute_tangential_and_cross_components() diff --git a/tests/test_theory.py b/tests/test_theory.py index 526e865b8..84558279a 100644 --- a/tests/test_theory.py +++ b/tests/test_theory.py @@ -94,7 +94,7 @@ def load_validation_config(halo_profile_model=None): "mdelta": testcase["cluster_mass"], "cdelta": testcase["cluster_concentration"], "z_cluster": testcase["z_cluster"], - "z_source": testcase["z_source"], + "z_src": testcase["z_src"], "delta_mdef": testcase["mass_Delta"], "halo_profile_model": testcase["density_profile_parametrization"], "z_src_info": "discrete", @@ -102,7 +102,7 @@ def load_validation_config(halo_profile_model=None): return { "TEST_CASE": testcase, - "z_source": testcase["z_source"], + "z_src": testcase["z_src"], "cosmo": cosmo, "cosmo_pars": {k.replace("cosmo_", ""): v for k, v in testcase.items() if "cosmo_" in k}, "RHO_PARAMS": RHO_PARAMS, @@ -450,7 +450,7 @@ def helper_physics_functions(func, additional_kwargs={}): "mdelta": 1.0e15, "cdelta": 4.0, "z_cluster": 0.2, - "z_source": 0.45, + "z_src": 0.45, "cosmo": theo.Cosmology(Omega_dm0=0.25, Omega_b0=0.05, H0=70.0), } kwargs.update(additional_kwargs) @@ -524,19 +524,19 @@ def test_shear_convergence_unittests(modeling_data, profile_init): cfg_inf = load_validation_config() # compute some values - cfg_inf["GAMMA_PARAMS"]["z_source"] = 1000.0 + cfg_inf["GAMMA_PARAMS"]["z_src"] = 1000.0 beta_s_mean = compute_beta_s_mean( - cfg_inf["GAMMA_PARAMS"]["z_cluster"], cfg_inf["GAMMA_PARAMS"]["z_source"], cosmo + cfg_inf["GAMMA_PARAMS"]["z_cluster"], cfg_inf["GAMMA_PARAMS"]["z_src"], cosmo ) beta_s_square_mean = compute_beta_s_square_mean( - cfg_inf["GAMMA_PARAMS"]["z_cluster"], cfg_inf["GAMMA_PARAMS"]["z_source"], cosmo + cfg_inf["GAMMA_PARAMS"]["z_cluster"], cfg_inf["GAMMA_PARAMS"]["z_src"], cosmo ) gammat_inf = theo.compute_tangential_shear(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]) kappa_inf = theo.compute_convergence(cosmo=cosmo, **cfg_inf["GAMMA_PARAMS"]) # test z_src = chang2013 distribution - cfg_inf["GAMMA_PARAMS"]["z_source"] = chang2013 + cfg_inf["GAMMA_PARAMS"]["z_src"] = chang2013 cfg_inf["GAMMA_PARAMS"]["z_src_info"] = "distribution" # store original values @@ -739,7 +739,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # test z_src_info = 'beta' beta_s_mean, beta_s_square_mean = 0.9, 0.6 - cfg_inf["GAMMA_PARAMS"]["z_source"] = (beta_s_mean, beta_s_square_mean) + cfg_inf["GAMMA_PARAMS"]["z_src"] = (beta_s_mean, beta_s_square_mean) cfg_inf["GAMMA_PARAMS"]["z_src_info"] = "beta" # tangential shear assert_allclose( @@ -813,7 +813,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # First, check for a array of radius and single source z radius = np.logspace(-2, 2, 10) z_cluster = 0.3 - z_source = 0.2 + z_src = 0.2 assert_allclose( theo.compute_convergence( @@ -821,7 +821,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), np.zeros(len(radius)), @@ -833,7 +833,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), np.zeros(len(radius)), @@ -845,7 +845,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), np.zeros(len(radius)), @@ -857,7 +857,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), np.ones(len(radius)), @@ -870,7 +870,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), np.ones(len(radius)), @@ -879,17 +879,17 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # Second, check a single radius and array of source z radius = 1.0 - z_source = [0.25, 0.1, 0.14, 0.02] + z_src = [0.25, 0.1, 0.14, 0.02] assert_allclose( theo.compute_convergence( radius, mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), - np.zeros(len(z_source)), + np.zeros(len(z_src)), 1.0e-10, ) assert_allclose( @@ -898,10 +898,10 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), - np.zeros(len(z_source)), + np.zeros(len(z_src)), 1.0e-10, ) assert_allclose( @@ -910,10 +910,10 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), - np.zeros(len(z_source)), + np.zeros(len(z_src)), 1.0e-10, ) assert_allclose( @@ -922,10 +922,10 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), - np.ones(len(z_source)), + np.ones(len(z_src)), 1.0e-10, ) assert_allclose( @@ -935,10 +935,10 @@ def test_shear_convergence_unittests(modeling_data, profile_init): mdelta=1.0e15, cdelta=4.0, z_cluster=z_cluster, - z_source=z_source, + z_src=z_src, cosmo=cosmo, ), - np.ones(len(z_source)), + np.ones(len(z_src)), 1.0e-10, ) @@ -973,7 +973,7 @@ def test_shear_convergence_unittests(modeling_data, profile_init): profile_pars = [ cfg["GAMMA_PARAMS"]["r_proj"], cfg["GAMMA_PARAMS"]["z_cluster"], - cfg["GAMMA_PARAMS"]["z_source"], + cfg["GAMMA_PARAMS"]["z_src"], ] # Validate tangential shear gammat = mod.eval_tangential_shear(*profile_pars) @@ -1090,49 +1090,49 @@ def test_shear_convergence_unittests(modeling_data, profile_init): # First, check for a array of radius and single source z radius = np.logspace(-2, 2, 10) z_cluster = 0.3 - z_source = 0.2 + z_src = 0.2 assert_allclose( - mod.eval_convergence(radius, z_cluster, z_source), np.zeros(len(radius)), 1.0e-10 + mod.eval_convergence(radius, z_cluster, z_src), np.zeros(len(radius)), 1.0e-10 ) assert_allclose( - mod.eval_tangential_shear(radius, z_cluster, z_source), np.zeros(len(radius)), 1.0e-10 + mod.eval_tangential_shear(radius, z_cluster, z_src), np.zeros(len(radius)), 1.0e-10 ) assert_allclose( - mod.eval_reduced_tangential_shear(radius, z_cluster, z_source), + mod.eval_reduced_tangential_shear(radius, z_cluster, z_src), np.zeros(len(radius)), 1.0e-10, ) assert_allclose( - mod.eval_magnification(radius, z_cluster, z_source), np.ones(len(radius)), 1.0e-10 + mod.eval_magnification(radius, z_cluster, z_src), np.ones(len(radius)), 1.0e-10 ) assert_allclose( - mod.eval_magnification_bias(radius, z_cluster, z_source, alpha), + mod.eval_magnification_bias(radius, z_cluster, z_src, alpha), np.ones(len(radius)), 1.0e-10, ) # Second, check a single radius and array of source z radius = 1.0 - z_source = [0.25, 0.1, 0.14, 0.02] + z_src = [0.25, 0.1, 0.14, 0.02] assert_allclose( - mod.eval_convergence(radius, z_cluster, z_source), np.zeros(len(z_source)), 1.0e-10 + mod.eval_convergence(radius, z_cluster, z_src), np.zeros(len(z_src)), 1.0e-10 ) assert_allclose( - mod.eval_tangential_shear(radius, z_cluster, z_source), np.zeros(len(z_source)), 1.0e-10 + mod.eval_tangential_shear(radius, z_cluster, z_src), np.zeros(len(z_src)), 1.0e-10 ) assert_allclose( - mod.eval_reduced_tangential_shear(radius, z_cluster, z_source), - np.zeros(len(z_source)), + mod.eval_reduced_tangential_shear(radius, z_cluster, z_src), + np.zeros(len(z_src)), 1.0e-10, ) assert_allclose( - mod.eval_magnification(radius, z_cluster, z_source), np.ones(len(z_source)), 1.0e-10 + mod.eval_magnification(radius, z_cluster, z_src), np.ones(len(z_src)), 1.0e-10 ) assert_allclose( - mod.eval_magnification_bias(radius, z_cluster, z_source, alpha), - np.ones(len(z_source)), + mod.eval_magnification_bias(radius, z_cluster, z_src, alpha), + np.ones(len(z_src)), 1.0e-10, ) From f2522d904ee03be0b1f931ad11e80bd694907479 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Tue, 23 May 2023 19:29:51 +0200 Subject: [PATCH 02/34] rm internal computation of sigma_c from compute_tangential_and_cross_components and compute_galaxy_weights --- clmm/dataops/__init__.py | 148 ++++++--------------------------------- 1 file changed, 23 insertions(+), 125 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index a4c11af65..422c373eb 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -17,6 +17,7 @@ from ..redshift import ( _integ_pzfuncs, compute_for_good_redshifts, + _validate_data_z_src, ) from ..theory import compute_critical_surface_density_eff @@ -29,14 +30,7 @@ def compute_tangential_and_cross_components( shear1, shear2, geometry="curve", - is_deltasigma=False, - cosmo=None, - z_lens=None, - z_src=None, - sigma_c=None, - use_pdz=False, - pzbins=None, - pzpdf=None, + sigma_c=1.0, validate_input=True, ): r"""Computes tangential- and cross- components for shear or ellipticity @@ -105,30 +99,10 @@ def compute_tangential_and_cross_components( geometry: str, optional Sky geometry to compute angular separation. Options are curve (uses astropy) or flat. - is_deltasigma: bool - If `True`, the tangential and cross components returned are multiplied by Sigma_crit. - Results in units of :math:`M_\odot\ Mpc^{-2}` - cosmo: clmm.Cosmology, optional - Required if `is_deltasigma` is True and `sigma_c` not provided. - Not used if `sigma_c` is provided. - z_lens: float, optional - Redshift of the lens, required if `is_deltasigma` is True and `sigma_c` not provided. - Not used if `sigma_c` is provided. - z_src: array, optional - Redshift of the source, required if `is_deltasigma` is True and `sigma_c` not provided. - Not used if `sigma_c` is provided or `use_pdz=True`. sigma_c : float, optional - Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`, - if provided, `cosmo`, `z_lens` and `z_src` are not used. - use_pdz: bool - Flag to use or not the source redshift p(z), required if `is_deltasigma` is True - and `sigma_c` not provided. If `False`, the point estimate provided by `z_src` is used. - pzpdf : array, optional - Photometric probablility density functions of the source galaxies, required if - `is_deltasigma=True` and `use_pdz=True` and `sigma_c` not provided. - pzbins : array, optional - Redshift axis on which the individual photoz pdf is tabulated, required if - `is_deltasigma=True` and `use_pdz=True` and `sigma_c` not provided. + Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`. If sigma_c!=1, + the tangential and cross components returned are overdensities (Delta Sigma). + Results in units of :math:`M_\odot\ Mpc^{-2}` validate_input: bool Validade each input argument @@ -152,10 +126,7 @@ def compute_tangential_and_cross_components( validate_argument(locals(), "shear1", "float_array") validate_argument(locals(), "shear2", "float_array") validate_argument(locals(), "geometry", str) - validate_argument(locals(), "is_deltasigma", bool) - validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True, none_ok=True) - validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True, none_ok=True) - validate_argument(locals(), "sigma_c", "float_array", none_ok=True) + validate_argument(locals(), "sigma_c", "float_array") ra_source_, dec_source_, shear1_, shear2_ = arguments_consistency( [ra_source, dec_source, shear1, shear2], names=("Ra", "Dec", "Shear1", "Shear2"), @@ -182,41 +153,16 @@ def compute_tangential_and_cross_components( # Compute the tangential and cross shears tangential_comp = _compute_tangential_shear(shear1_, shear2_, phi) cross_comp = _compute_cross_shear(shear1_, shear2_, phi) - # If the is_deltasigma flag is True, multiply the results by Sigma_crit. - if is_deltasigma: - if sigma_c is None and use_pdz is False: - # Need to verify that cosmology and redshifts are provided - if any(t_ is None for t_ in (z_lens, z_src, cosmo)): - raise TypeError( - "To compute DeltaSigma, please provide a " - "i) cosmology, ii) redshift of lens and sources" - ) - - sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) - - elif sigma_c is None: - # Need to verify that cosmology, lens redshift, source redshift bins and - # source redshift pdf are provided - if any(t_ is None for t_ in (z_lens, cosmo, pzbins, pzpdf)): - raise TypeError( - "To compute DeltaSigma using the redshift pdz of the sources, " - "please provide a " - "i) cosmology, ii) lens redshift, iii) source redshift bins and" - "iv) source redshift pdf" - ) - - sigma_c = compute_critical_surface_density_eff( - cosmo, z_lens, pzbins=pzbins, pzpdf=pzpdf - ) + # If the is_deltasigma flag is True, multiply the results by Sigma_crit. + tangential_comp *= sigma_c + cross_comp *= sigma_c - tangential_comp *= sigma_c - cross_comp *= sigma_c return angsep, tangential_comp, cross_comp def compute_background_probability( - z_lens, z_src=None, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True + z_lens, z_src=None, z_src_info=None, pzpdf=None, pzbins=None, validate_input=True ): r"""Probability for being a background galaxy @@ -226,14 +172,6 @@ def compute_background_probability( Redshift of the lens. z_src: array, optional Redshift of the source. Used only if pzpdf=pzbins=None. - use_pdz: bool - Flag to use or not the source redshif. If `False`, - the point estimate provided by `z_src` is used. - pzpdf : array, optional - Photometric probablility density functions of the source galaxies. - Used instead of z_src if provided. - pzbins : array, optional - Redshift axis on which the individual photoz pdf is tabulated. Returns ------- @@ -259,18 +197,13 @@ def compute_background_probability( def compute_galaxy_weights( z_lens, cosmo, - z_src=None, - use_pdz=False, - pzpdf=None, - pzbins=None, use_shape_noise=False, shape_component1=None, shape_component2=None, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=False, - sigma_c=None, + sigma_c=1.0, validate_input=True, ): r"""Computes the individual lens-source pair weights @@ -315,18 +248,8 @@ def compute_galaxy_weights( ---------- z_lens: float Redshift of the lens. - z_src: array_like, optional - Redshift of the source (point estimate). Used only if `use_pdz=False`. cosmo: clmm.Comology object, None CLMM Cosmology object. - use_pdz: bool - Flag to use or not the source redshift p(z). If `False` (default) the point estimate - provided by `z_src` is used. - pzpdf : array_like, optional - Photometric probablility density functions of the source galaxies. - Used instead of z_src if `use_pdz=True` - pzbins : array_like, optional - Redshift axis on which the individual photoz pdf is tabulated. Required if `use_pdz=True` use_shape_noise: bool If `True` shape noise is included in the weight computation. It then requires `shape_componenet{1,2}` to be provided. Default: False. @@ -345,8 +268,9 @@ def compute_galaxy_weights( shape_component2_err: array_like The measurement error on the 2nd-component of ellipticity of the source galaxies, used if `use_shape_error=True` - is_deltasigma: bool - Indicates whether it is the excess surface density or the tangential shear + sigma_c : float, optional + Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`. If sigma_c!=1, + weights are based on the excess surface density instead of tangential shear. validate_input: bool Validade each input argument @@ -357,16 +281,12 @@ def compute_galaxy_weights( """ if validate_input: validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True) - validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True, none_ok=True) - validate_argument(locals(), "use_pdz", bool) - # validate_argument(locals(), 'pzpdf', 'float_array', none_ok=True) - # validate_argument(locals(), 'pzbins', 'float_array', none_ok=True) validate_argument(locals(), "shape_component1", "float_array", none_ok=True) validate_argument(locals(), "shape_component2", "float_array", none_ok=True) validate_argument(locals(), "shape_component1_err", "float_array", none_ok=True) validate_argument(locals(), "shape_component2_err", "float_array", none_ok=True) validate_argument(locals(), "use_shape_noise", bool) - validate_argument(locals(), "is_deltasigma", bool) + validate_argument(locals(), "sigma_c", "float_array") arguments_consistency( [shape_component1, shape_component2], names=("shape_component1", "shape_component2"), @@ -374,36 +294,10 @@ def compute_galaxy_weights( ) # computing w_ls_geo - - if is_deltasigma is False: - w_ls_geo = 1.0 - else: - if sigma_c is None and use_pdz is False: - # Need to verify that cosmology and redshifts are provided - if any(t_ is None for t_ in (z_lens, z_src, cosmo)): - raise TypeError( - "To compute DeltaSigma, please provide a " - "i) cosmology, ii) redshift of lens and sources" - ) - sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) - elif sigma_c is None: - # Need to verify that cosmology, lens redshift, source redshift bins and - # source redshift pdf are provided - if any(t_ is None for t_ in (z_lens, cosmo, pzbins, pzpdf)): - raise TypeError( - "To compute DeltaSigma using the redshift pdz of the sources, " - "please provide a " - "i) cosmology, ii) lens redshift, iii) source redshift bins and" - "iv) source redshift pdf" - ) - sigma_c = compute_critical_surface_density_eff( - cosmo, z_lens, pzbins=pzbins, pzpdf=pzpdf - ) - w_ls_geo = 1.0 / sigma_c**2 + w_ls_geo = 1.0 / sigma_c**2 # computing w_ls_shape - ngals = len(pzpdf) if use_pdz else len(z_src) - err_e2 = np.zeros(ngals) + err_e2 = 0 if use_shape_noise: if shape_component1 is None or shape_component2 is None: @@ -420,8 +314,12 @@ def compute_galaxy_weights( ) err_e2 += shape_component1_err**2 err_e2 += shape_component2_err**2 - w_ls_shape = np.ones(ngals) - w_ls_shape[err_e2 > 0] = 1.0 / err_e2[err_e2 > 0] + + if hasattr(err_e2, "__len__"): + w_ls_shape = np.ones(err_e2) + w_ls_shape[err_e2 > 0] = 1.0 / err_e2[err_e2 > 0] + else: + w_ls_shape = 1.0 / err_e2 if err_e2 > 0 else 1.0 w_ls = w_ls_shape * w_ls_geo From d7ee7780231164d61944d1743751b39b38c280bc Mon Sep 17 00:00:00 2001 From: m-aguena Date: Wed, 24 May 2023 13:16:43 +0200 Subject: [PATCH 03/34] rm unnecessary use_pdz args in GalaxyCluster --- clmm/galaxycluster.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index cbd6e51e4..dd0dfec94 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -277,7 +277,6 @@ def compute_tangential_and_cross_components( dec_lens=self.dec, geometry=geometry, is_deltasigma=is_deltasigma, - use_pdz=use_pdz, validate_input=self.validate_input, **cols, ) @@ -369,12 +368,10 @@ def compute_galaxy_weights( """ # input cols col_dict = {} - if use_pdz: - col_dict.update({"pzpdf": "pzpdf", "pzbins": "pzbins"}) if is_deltasigma: if "sigma_c" not in self.galcat.columns: self.add_critical_surface_density(cosmo, use_pdz=use_pdz) - col_dict.update({"z_source": "z", "sigma_c": "sigma_c"}) + col_dict.update({"sigma_c": "sigma_c"}) if use_shape_noise: col_dict.update( { @@ -395,7 +392,6 @@ def compute_galaxy_weights( w_ls = compute_galaxy_weights( self.z, cosmo, - use_pdz=use_pdz, use_shape_noise=use_shape_noise, use_shape_error=use_shape_error, is_deltasigma=is_deltasigma, From 7c65958a2f9924e0c595ff4c94bfd7919e5a3b09 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Wed, 24 May 2023 13:17:21 +0200 Subject: [PATCH 04/34] update examples/demo_compute_deltasigma_weights.ipynb --- .../demo_compute_deltasigma_weights.ipynb | 87 +++++++++++++++---- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/examples/demo_compute_deltasigma_weights.ipynb b/examples/demo_compute_deltasigma_weights.ipynb index 2ebdaeb7c..ff98eeac5 100644 --- a/examples/demo_compute_deltasigma_weights.ipynb +++ b/examples/demo_compute_deltasigma_weights.ipynb @@ -55,6 +55,7 @@ "from clmm import GalaxyCluster\n", "from clmm.dataops import compute_galaxy_weights, compute_background_probability\n", "from clmm.support import mock_data as mock\n", + "from clmm.theory import compute_critical_surface_density_eff\n", "\n", "clmm.__version__" ] @@ -163,9 +164,19 @@ "id": "747e99bf", "metadata": {}, "source": [ - "#### using the functional interface\n", + "#### Using the functional interface\n", "\n", - "Here, we use the true source redshifts stored in `z_gal`" + "First, we need to compute $\\Sigma_{\\rm crit}$. Here, we use the true source redshifts stored in `z_gal`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3432e008", + "metadata": {}, + "outputs": [], + "source": [ + "sigma_c = cosmo.eval_sigma_crit(cluster_z, z_gal)" ] }, { @@ -178,14 +189,7 @@ "w_ls_true = compute_galaxy_weights(\n", " cluster_z,\n", " cosmo,\n", - " z_source=z_gal,\n", - " shape_component1=noisy_data_z[\"e1\"],\n", - " shape_component2=noisy_data_z[\"e2\"],\n", - " shape_component1_err=noisy_data_z[\"e_err\"],\n", - " shape_component2_err=noisy_data_z[\"e_err\"],\n", - " use_pdz=False,\n", - " pzpdf=None,\n", - " pzbins=None,\n", + " sigma_c=sigma_c,\n", " use_shape_noise=False,\n", " is_deltasigma=True,\n", ")" @@ -196,7 +200,7 @@ "id": "206a9562", "metadata": {}, "source": [ - "#### or as a method of the `GalaxyCluster` object\n", + "#### As a method of the `GalaxyCluster` object\n", "As a method of the `GalaxyCluster` object, `compute_galaxy_weights` uses the content of the `z` column of the object's `galcat` table as the source redshift point estimates. Given that mock data was generated with a photoz error, this point estimate is different from the true redshift used in the cell above." ] }, @@ -225,16 +229,67 @@ "id": "5f288e2c-32cc-4f35-8744-c66c073b3024", "metadata": {}, "source": [ + "When considering the photo-z distribution, we can compute the weight based on an effective critical surface density:\n", + "\n", + "$$\n", + "w_{\\rm ls} = \\Sigma_{\\rm crit}^{\\rm eff}(z_l)^{-2},\n", "$$\n", - "w_{\\rm ls} = \\left(\\int_{z_l}^{+\\infty}\\Sigma_{\\rm crit}(z_l, z)^{-1}p(z) dz\\right)^2\n", + "\n", + "where\n", + "\n", + "$$\n", + "\\Sigma_{\\rm crit}^{\\rm eff}(z_l) = \\left(\\int_{z_l}^{+\\infty}\\Sigma_{\\rm crit}(z_l, z)^{-1}p(z) dz\\right)^{-1}.\n", "$$" ] }, + { + "cell_type": "markdown", + "id": "6355d76b", + "metadata": {}, + "source": [ + "#### Using the functional interface\n", + "\n", + "First, we need to compute $\\Sigma_{\\rm crit}^{\\rm eff}$. Here, we use the true source redshifts stored in `z_gal`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0dbbfa25", + "metadata": {}, + "outputs": [], + "source": [ + "sigma_c_eff = compute_critical_surface_density_eff(\n", + " cosmo=cosmo,\n", + " z_cluster=cluster_z,\n", + " pzbins=noisy_data_z[\"pzbins\"],\n", + " pzpdf=noisy_data_z[\"pzpdf\"],\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aee36658", + "metadata": {}, + "outputs": [], + "source": [ + "w_ls_photoz = compute_galaxy_weights(\n", + " cluster_z,\n", + " cosmo,\n", + " sigma_c=sigma_c_eff,\n", + " use_shape_noise=False,\n", + " is_deltasigma=True,\n", + ")" + ] + }, { "cell_type": "markdown", "id": "5285a1a7-e990-4d83-a418-15e04d80a948", "metadata": {}, "source": [ + "#### As a method of the `GalaxyCluster` object\n", + "\n", "When used as a method of the `GalaxyCluster` object, with `use_pdz=True`, `compute_galaxy_weights` uses the content of the `pzpdf` and `pzbins` columns of the `galcat` table. It will return an error if those do not exist." ] }, @@ -304,7 +359,7 @@ "metadata": {}, "source": [ "$$\n", - "w_{\\rm ls} = \\frac{\\left(\\int_{z_l}^{+\\infty}\\Sigma_{\\rm crit}(z_l, z)^{-1}p(z) dz\\right)^2}{\\sigma_{\\rm shapenoise}^2 + \\sigma^2_{\\rm shape\\ error}}\n", + "w_{\\rm ls} = \\frac{\\Sigma_{\\rm crit}^{\\rm eff}(z_l, z)^{-2}}{\\sigma_{\\rm shapenoise}^2 + \\sigma^2_{\\rm shape\\ error}}\n", "$$" ] }, @@ -357,13 +412,13 @@ "source": [ "### $\\Sigma_c$ metadata\n", "\n", - "As seen above, the weights are computed either using the standard definition of $\\Sigma_c^{\\rm std}$, using point estimate redshift, or the effective definition based on the inverse $\\Sigma_c^{\\rm eff}$ averaged over the redshift PDF $p(z)$:\n", + "As seen above, the weights are computed either using the standard definition of $\\Sigma_{\\rm crit}^{\\rm std}$, using point estimate redshift, or the effective definition based on the inverse $\\Sigma_c^{\\rm eff}$ averaged over the redshift PDF $p(z)$:\n", "\n", "$$ \n", - "\\Sigma_c^{\\rm std}\\equiv\\Sigma_{\\rm crit}(z_l, z_s) \\;\\;{\\rm and}\\;\\; \\Sigma_c^{\\rm eff}\\equiv\\left( \\int \\Sigma_{\\rm crit}(z_l, z)^{-1} p(z) dz\\right)^{-1}\n", + "\\Sigma_{\\rm crit}^{\\rm std}\\equiv\\Sigma_{\\rm crit}(z_l, z_s) \\;\\;{\\rm and}\\;\\; \\Sigma_{\\rm crit}^{\\rm eff}\\equiv\\left( \\int \\Sigma_{\\rm crit}(z_l, z)^{-1} p(z) dz\\right)^{-1}\n", "$$\n", "\n", - "To keep track of what definition of $\\Sigma_c$ was used, `standard` or `effective` the user may look into the `galcat` metadata " + "To keep track of what definition of $\\Sigma_{\\rm crit}$ was used, `standard` or `effective` the user may look into the `galcat` metadata " ] }, { From 78a94987525412b3f0cf67565c03c76c7a88237e Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 11:35:15 +0200 Subject: [PATCH 05/34] create _validate_data_z_src func --- clmm/dataops/__init__.py | 1 - clmm/redshift/tools.py | 77 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 422c373eb..ffe6debf5 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -17,7 +17,6 @@ from ..redshift import ( _integ_pzfuncs, compute_for_good_redshifts, - _validate_data_z_src, ) from ..theory import compute_critical_surface_density_eff diff --git a/clmm/redshift/tools.py b/clmm/redshift/tools.py index 82ffd670e..8fe27550d 100644 --- a/clmm/redshift/tools.py +++ b/clmm/redshift/tools.py @@ -4,6 +4,8 @@ from scipy.integrate import simps from scipy.interpolate import interp1d +from ..utils import validate_argument + def _integ_pzfuncs(pzpdf, pzbins, zmin=0.0, zmax=5, kernel=lambda z: 1.0, ngrid=1000): r""" @@ -116,3 +118,78 @@ def compute_for_good_redshifts( else: res = function(**kwargs) return res + + +def _validate_theory_z_src(loc_dict): + r"""Validation for z_src according to z_src_info. The conditions are: + + * z_src_info='discrete' : z_src must be array or float. + * z_src_info='distribution' : z_src must be a one dimentional function. + * z_src_info='beta' : z_src must be a tuple containing + ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`). + + Also, if approx is provided and not None, z_src_info must be 'distribution' or 'beta'. + + Parameters + ---------- + locals_dict: dict + Should be the call locals() + """ + if loc_dict["z_src_info"] == "discrete": + validate_argument(loc_dict, "z_src", "float_array", argmin=0) + elif loc_dict["z_src_info"] == "distribution": + validate_argument(loc_dict, "z_src", "function", none_ok=False) + beta_kwargs = {} if loc_dict["beta_kwargs"] is None else loc_dict["beta_kwargs"] + _def_keys = ["zmin", "zmax", "delta_z_cut"] + if any(key not in _def_keys for key in beta_kwargs): + raise KeyError( + f"beta_kwargs must contain only {_def_keys} keys, " + f" {beta_kwargs.keys()} provided." + ) + elif loc_dict["z_src_info"] == "beta": + validate_argument(loc_dict, "z_src", "array") + beta_info = { + "beta_s_mean": loc_dict["z_src"][0], + "beta_s_square_mean": loc_dict["z_src"][1], + } + validate_argument(beta_info, "beta_s_mean", "float_array") + validate_argument(beta_info, "beta_s_square_mean", "float_array") + if loc_dict.get("approx") and loc_dict["z_src_info"] not in ( + "distribution", + "beta", + ): + approx, z_src_info = loc_dict["approx"], loc_dict["z_src_info"] + raise ValueError( + f"approx='{approx}' requires z_src_info='distribution' or 'beta', " + f"z_src_info='{z_src_info}' was provided." + ) + + +def _validate_data_z_src(loc_dict): + r"""Validation for z_src according to z_src_info. The conditions are: + + * z_src_info='discrete' : z_src must be array or float. + * z_src_info='pdf' : z_src must be a one dimentional function. + * z_src_info='quantile' : z_src must be a tuple containing + ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`). + + Also, if approx is provided and not None, z_src_info must be 'distribution' or 'beta'. + + Parameters + ---------- + locals_dict: dict + Should be the call locals() + """ + if loc_dict["z_src_info"] == "discrete": + validate_argument(loc_dict, "z_src", "float_array", argmin=0) + elif loc_dict["z_src_info"] == "pdf": + validate_argument(loc_dict, "z_src", "function", none_ok=False) + integ_kwargs = {} if loc_dict["integ_kwargs"] is None else loc_dict["integ_kwargs"] + _def_keys = ["zmin", "zmax", "delta_z_cut"] + if any(key not in _def_keys for key in integ_kwargs): + raise KeyError( + f"integ_kwargs must contain only {_def_keys} keys, " + f" {integ_kwargs.keys()} provided." + ) + elif z_src_info == "quantile": + validate_argument(loc_dict, "z_src", "float_array") From 5ac9cbaca3b162ce69ba1339dce237d8c4c15f26 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:53:06 +0200 Subject: [PATCH 06/34] update compute_background_probability --- clmm/dataops/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index ffe6debf5..d018e970c 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -161,9 +161,16 @@ def compute_tangential_and_cross_components( def compute_background_probability( - z_lens, z_src=None, z_src_info=None, pzpdf=None, pzbins=None, validate_input=True + z_lens, z_src=None, use_pdz=False, pzpdf=None, pzbins=None, validate_input=True ): - r"""Probability for being a background galaxy + r"""Probability for being a background galaxy, defined by: + + .. math:: + P(z_s > z_l) = \int_{z_l}^{+\infty} dz_s p_{\text{photoz}}(z_s), + + when the photometric probability density functions ($p p_{\text{photoz}}(z_s)$) are provided. + In the case of true redshifts, it returns 1 if :math:`z_s > z_l` else returns 0. + Parameters ---------- From 4ca0399c17eda6621f627a0dbf79548b95bb7c03 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:53:51 +0200 Subject: [PATCH 07/34] update docstring of compute_background_probability --- clmm/dataops/__init__.py | 47 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index d018e970c..6c0f9e9be 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -201,15 +201,13 @@ def compute_background_probability( def compute_galaxy_weights( - z_lens, - cosmo, + sigma_c, use_shape_noise=False, shape_component1=None, shape_component2=None, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - sigma_c=1.0, validate_input=True, ): r"""Computes the individual lens-source pair weights @@ -217,45 +215,36 @@ def compute_galaxy_weights( The weights :math:`w_{ls}` express as : :math:`w_{ls} = w_{ls, \text{geo}} \times w_{ls, \text{shape}}`, following E. S. Sheldon et al. (2003), arXiv:astro-ph/0312036: - 1. The geometrical weight :math:`w_{ls, \text{geo}}` depends on lens and source redshift - information. When considering only redshift point estimates, the weights read + 1. When computed for tangential shear, the geometrical weights :math:`w_{ls, \text{geo}}` are + equal to 1. When compute for $\Delta \Sigma$, it depends on lens and source redshift information + via the critical surface density. It can be expressed as: .. math:: - w_{ls, \text{geo}} = \Sigma_c(\text{cosmo}, z_l, z_{\text{src}})^{-2}\;. + w_{ls, \text{geo}} = \Sigma_{\rm crit}(z_l, z_{\text{src}})^{-2}\;. + + when only redshift point estimates are provided, or as: - If the redshift pdf of each source, :math:`p_{\text{photoz}}(z_s)`, is known, - the weights are computed instead as .. math:: - w_{ls, \text{geo}} = \left[\int_{\delta + z_l} dz_s p_{\text{photoz}}(z_s) - \Sigma_c(\text{cosmo}, z_l, z_s)^{-1}\right]^2 + w_{ls, \text{geo}} = \Sigma_{\rm crit}^{\rm eff}(z_l, z_{\text{src}})^{-2} + = \left[\int_{\delta + z_l} dz_s p_{\text{photoz}}(z_s) + \Sigma_{\rm crit}(z_l, z_s)^{-1}\right]^2 - for the tangential shear, the weights :math:`w_{ls, \text{geo}}` are 1. + when the redshift pdf of each source, :math:`p_{\text{photoz}}(z_s)`, is known. 2. The shape weight :math:`w_{ls,{\text{shape}}}` depends on shapenoise and/or shape measurement errors .. math:: - w_{ls, \text{shape}} = 1/(\sigma_{\text{shapenoise}}^2 + + w_{ls, \text{shape}}^{-1} = (\sigma_{\text{shapenoise}}^2 + \sigma_{\text{measurement}}^2) - 3. The probability for a galaxy to be in the background of the cluster is defined by: - - .. math:: - P(z_s > z_l) = \int_{z_l}^{+\infty} dz_s p_{\text{photoz}}(z_s) - - The function return the probability for a galaxy to be in the background of the cluster; - if photometric probability density functions are provoded, the function computes the above - integral. In the case of true redshifts, it returns 1 if :math:`z_s > z_l` else returns 0. - - Parameters ---------- - z_lens: float - Redshift of the lens. - cosmo: clmm.Comology object, None - CLMM Cosmology object. + sigma_c : float, optional + Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. + Should be equal to 1 if weights for tangential shear are being computed. use_shape_noise: bool If `True` shape noise is included in the weight computation. It then requires `shape_componenet{1,2}` to be provided. Default: False. @@ -274,9 +263,6 @@ def compute_galaxy_weights( shape_component2_err: array_like The measurement error on the 2nd-component of ellipticity of the source galaxies, used if `use_shape_error=True` - sigma_c : float, optional - Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`. If sigma_c!=1, - weights are based on the excess surface density instead of tangential shear. validate_input: bool Validade each input argument @@ -286,13 +272,12 @@ def compute_galaxy_weights( Individual lens source pair weights """ if validate_input: - validate_argument(locals(), "z_lens", float, argmin=0, eqmin=True) + validate_argument(locals(), "sigma_c", "float_array") validate_argument(locals(), "shape_component1", "float_array", none_ok=True) validate_argument(locals(), "shape_component2", "float_array", none_ok=True) validate_argument(locals(), "shape_component1_err", "float_array", none_ok=True) validate_argument(locals(), "shape_component2_err", "float_array", none_ok=True) validate_argument(locals(), "use_shape_noise", bool) - validate_argument(locals(), "sigma_c", "float_array") arguments_consistency( [shape_component1, shape_component2], names=("shape_component1", "shape_component2"), From d65d30aa2e4a6331dc418d491fc39c706354d7f7 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:53:59 +0200 Subject: [PATCH 08/34] fix minor bug --- clmm/dataops/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 6c0f9e9be..0c2789ffe 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -307,7 +307,7 @@ def compute_galaxy_weights( err_e2 += shape_component2_err**2 if hasattr(err_e2, "__len__"): - w_ls_shape = np.ones(err_e2) + w_ls_shape = np.ones(len(err_e2)) w_ls_shape[err_e2 > 0] = 1.0 / err_e2[err_e2 > 0] else: w_ls_shape = 1.0 / err_e2 if err_e2 > 0 else 1.0 From 3834e6bb7cc66e7c6c1d2bc621bba108d1e34188 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:55:27 +0200 Subject: [PATCH 09/34] update GalaxyCluster.compute_galaxy_weights --- clmm/galaxycluster.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index dc0b2de51..3d144f9a6 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -276,7 +276,6 @@ def compute_tangential_and_cross_components( ra_lens=self.ra, dec_lens=self.dec, geometry=geometry, - is_deltasigma=is_deltasigma, validate_input=self.validate_input, **cols, ) @@ -387,14 +386,13 @@ def compute_galaxy_weights( } ) cols = self._get_input_galdata(col_dict) + if not is_deltasigma: + cols["sigma_c"] = 1.0 # computes weights w_ls = compute_galaxy_weights( - self.z, - cosmo, use_shape_noise=use_shape_noise, use_shape_error=use_shape_error, - is_deltasigma=is_deltasigma, validate_input=self.validate_input, **cols, ) From c9fd36abd288b9db854f1fc4dd4fde44349136e2 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:56:12 +0200 Subject: [PATCH 10/34] fix import in clmm/redshift/tools.py --- clmm/redshift/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clmm/redshift/tools.py b/clmm/redshift/tools.py index 8fe27550d..628cf37d0 100644 --- a/clmm/redshift/tools.py +++ b/clmm/redshift/tools.py @@ -4,7 +4,7 @@ from scipy.integrate import simps from scipy.interpolate import interp1d -from ..utils import validate_argument +from ..utils.validation import validate_argument def _integ_pzfuncs(pzpdf, pzbins, zmin=0.0, zmax=5, kernel=lambda z: 1.0, ngrid=1000): From f0af206379e73dabd210fc00d577aedd40528450 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:56:41 +0200 Subject: [PATCH 11/34] update z_src in .json files --- tests/data/numcosmo/config.json | 2 +- tests/data/numcosmo/config_einasto_benchmarks.json | 2 +- tests/data/numcosmo/config_hernquist_benchmarks.json | 2 +- tests/data/numcosmo/config_old_units.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/data/numcosmo/config.json b/tests/data/numcosmo/config.json index c81716df1..c38ce5e87 100644 --- a/tests/data/numcosmo/config.json +++ b/tests/data/numcosmo/config.json @@ -1 +1 @@ -{"dl": 1696.50282336234, "z_source": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "nfw", "ds": 1767.4306833378118, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962517, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435031.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} \ No newline at end of file +{"dl": 1696.50282336234, "z_src": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "nfw", "ds": 1767.4306833378118, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962517, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435031.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} diff --git a/tests/data/numcosmo/config_einasto_benchmarks.json b/tests/data/numcosmo/config_einasto_benchmarks.json index 0d6f949fb..dd201b9aa 100644 --- a/tests/data/numcosmo/config_einasto_benchmarks.json +++ b/tests/data/numcosmo/config_einasto_benchmarks.json @@ -1 +1 @@ -{"dl": 1696.502823362356, "z_source": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "einasto", "ds": 1767.4306833377823, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962118, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435132.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16, "alpha_einasto": 0.3683247081598754} \ No newline at end of file +{"dl": 1696.502823362356, "z_src": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "einasto", "ds": 1767.4306833377823, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962118, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435132.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16, "alpha_einasto": 0.3683247081598754} diff --git a/tests/data/numcosmo/config_hernquist_benchmarks.json b/tests/data/numcosmo/config_hernquist_benchmarks.json index bc425840c..59eb97c68 100644 --- a/tests/data/numcosmo/config_hernquist_benchmarks.json +++ b/tests/data/numcosmo/config_hernquist_benchmarks.json @@ -1 +1 @@ -{"dl": 1696.502823362356, "z_source": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "hernquist", "ds": 1767.4306833377823, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962118, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435132.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} \ No newline at end of file +{"dl": 1696.502823362356, "z_src": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "aexp_cluster": 0.5, "density_profile_parametrization": "hernquist", "ds": 1767.4306833377823, "cosmo_Ob0": 0.049, "aexp_source": 0.3333333333333333, "dsl": 636.4288010962118, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 67.66, "cluster_concentration": 4.0, "cosmo_Om0": 0.31240715689016263, "cosmo_Odm0": 0.262, "nc_Sigmac": 2722127302435132.5, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} diff --git a/tests/data/numcosmo/config_old_units.json b/tests/data/numcosmo/config_old_units.json index 42ae6f974..b483a268d 100644 --- a/tests/data/numcosmo/config_old_units.json +++ b/tests/data/numcosmo/config_old_units.json @@ -1 +1 @@ -{"dl": 1177679548.8532429, "z_source": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "nc_cor_factor": 1.0, "aexp_cluster": 0.5, "density_profile_parametrization": "nfw", "ds": 1241373844.9905102, "cosmo_Ob0": 0.045, "aexp_source": 0.3333333333333333, "dsl": 456254145.7550621, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 70.0, "cluster_concentration": 4.0, "cosmo_Om0": 0.27, "nc_Sigmac": 3841.8383445955924, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} \ No newline at end of file +{"dl": 1177679548.8532429, "z_src": 2.0, "cluster_mass": 1000000000000000.0, "G[m3/km.s2]": 6.6743e-11, "nc_cor_factor": 1.0, "aexp_cluster": 0.5, "density_profile_parametrization": "nfw", "ds": 1241373844.9905102, "cosmo_Ob0": 0.045, "aexp_source": 0.3333333333333333, "dsl": 456254145.7550621, "z_cluster": 1.0, "mass_Delta": 200, "lightspeed[km/s]": 299792.458, "cosmo_H0": 70.0, "cluster_concentration": 4.0, "cosmo_Om0": 0.27, "nc_Sigmac": 3841.8383445955924, "Msun[kg]": 1.988409870698051e+30, "pc_to_m": 3.085677581491367e+16} From 86673e5f6fb18f84d0a974b17d8022df99163930 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 13:57:09 +0200 Subject: [PATCH 12/34] update tests for new api --- tests/test_dataops.py | 196 +++++++----------------------------------- 1 file changed, 32 insertions(+), 164 deletions(-) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index b55fd897a..ab8e98c3a 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -6,6 +6,7 @@ from clmm import GCData from scipy.stats import multivariate_normal import clmm.dataops as da +from clmm.theory import compute_critical_surface_density_eff TOLERANCE = {"rtol": 1.0e-7, "atol": 1.0e-7} @@ -444,85 +445,25 @@ def test_compute_tangential_and_cross_components(modeling_data): # Check behaviour for the deltasigma option. cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025) - # test missing info for is_deltasigma=True - assert_raises( - TypeError, - da.compute_tangential_and_cross_components, - ra_lens=ra_lens, - dec_lens=dec_lens, - ra_source=gals["ra"], - dec_source=gals["dec"], - shear1=gals["e1"], - shear2=gals["e2"], - is_deltasigma=True, - cosmo=None, - z_lens=z_lens, - z_src=gals["z"], - ) - assert_raises( - TypeError, - da.compute_tangential_and_cross_components, - ra_lens=ra_lens, - dec_lens=dec_lens, - ra_source=gals["ra"], - dec_source=gals["dec"], - shear1=gals["e1"], - shear2=gals["e2"], - is_deltasigma=True, - cosmo=cosmo, - z_lens=None, - z_src=gals["z"], - ) - assert_raises( - TypeError, - da.compute_tangential_and_cross_components, - ra_lens=ra_lens, - dec_lens=dec_lens, - ra_source=gals["ra"], - dec_source=gals["dec"], - shear1=gals["e1"], - shear2=gals["e2"], - is_deltasigma=True, - cosmo=cosmo, - z_lens=z_lens, - z_src=None, - ) - - # test missing info for use_pdz=True - assert_raises( - TypeError, - da.compute_tangential_and_cross_components, - ra_lens=ra_lens, - dec_lens=dec_lens, - ra_source=gals["ra"], - dec_source=gals["dec"], - shear1=gals["e1"], - shear2=gals["e2"], - is_deltasigma=True, - use_pdz=True, - cosmo=cosmo, - z_lens=z_lens, - z_src=None, - ) - # Trying to got through line 173 of dataops/__init__.py - da.compute_tangential_and_cross_components( - ra_lens=ra_lens, - dec_lens=dec_lens, - ra_source=gals["ra"][0], - dec_source=gals["dec"][0], - shear1=gals["e1"][0], - shear2=gals["e2"][0], - is_deltasigma=True, - use_pdz=True, - cosmo=cosmo, - z_lens=z_lens, - z_src=None, - pzbins=[[0.55, 0.6, 0.65, 0.7, 0.75]], - pzpdf=[[0.01, 1, 0.01, 0.001, 0.0001]], - ) + # da.compute_tangential_and_cross_components( + # ra_lens=ra_lens, + # dec_lens=dec_lens, + # ra_source=gals["ra"][0], + # dec_source=gals["dec"][0], + # shear1=gals["e1"][0], + # shear2=gals["e2"][0], + # is_deltasigma=True, + # use_pdz=True, + # cosmo=cosmo, + # z_lens=z_lens, + # z_src=None, + # pzbins=[[0.55, 0.6, 0.65, 0.7, 0.75]], + # pzpdf=[[0.01, 1, 0.01, 0.001, 0.0001]], + # ) # check values for DeltaSigma + sigma_c = cosmo.eval_sigma_crit(z_lens, gals["z"]) for geometry, expected in geo_tests: angsep_DS, tDS, xDS = da.compute_tangential_and_cross_components( ra_lens=ra_lens, @@ -531,10 +472,7 @@ def test_compute_tangential_and_cross_components(modeling_data): dec_source=gals["dec"], shear1=gals["e1"], shear2=gals["e2"], - is_deltasigma=True, - cosmo=cosmo, - z_lens=z_lens, - z_src=gals["z"], + sigma_c=sigma_c, geometry=geometry, ) assert_allclose( @@ -633,20 +571,15 @@ def test_compute_galaxy_weights(): shape_component2_err = np.array([0.14, 0.16, 0.21]) # true redshift + deltasigma + sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) weights = da.compute_galaxy_weights( - z_lens, - cosmo, - z_src=z_src, - use_pdz=False, - pzpdf=None, - pzbins=None, + sigma_c, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, use_shape_error=False, shape_component1_err=shape_component1_err, shape_component2_err=shape_component2_err, - is_deltasigma=True, validate_input=True, ) expected = np.array([4.58644320e-31, 9.68145632e-31, 5.07260777e-31]) @@ -656,20 +589,20 @@ def test_compute_galaxy_weights(): pzbin = np.linspace(0.0001, 5, 100) pzbins = [pzbin for i in range(len(z_src))] pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] - weights = da.compute_galaxy_weights( - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, + sigma_c_eff = compute_critical_surface_density_eff( + cosmo=cosmo, + z_cluster=z_lens, pzbins=pzbins, + pzpdf=pzpdf, + ) + weights = da.compute_galaxy_weights( + sigma_c_eff, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=True, validate_input=True, ) @@ -681,19 +614,13 @@ def test_compute_galaxy_weights(): pzbins = pzbin pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] weights = da.compute_galaxy_weights( - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, + sigma_c_eff, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=True, validate_input=True, ) @@ -702,19 +629,13 @@ def test_compute_galaxy_weights(): # test with noise weights = da.compute_galaxy_weights( - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, + sigma_c_eff, use_shape_noise=True, shape_component1=shape_component1, shape_component2=shape_component2, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=True, validate_input=True, ) @@ -723,19 +644,13 @@ def test_compute_galaxy_weights(): # test with is_deltasigma=False and geometric weights only weights = da.compute_galaxy_weights( - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, + sigma_c=1.0, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=False, validate_input=True, ) @@ -746,19 +661,13 @@ def test_compute_galaxy_weights(): assert_raises( ValueError, da.compute_galaxy_weights, - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, + sigma_c_eff, use_shape_noise=True, shape_component1=None, shape_component2=None, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=False, validate_input=True, ) @@ -766,52 +675,11 @@ def test_compute_galaxy_weights(): assert_raises( ValueError, da.compute_galaxy_weights, - z_lens, - cosmo, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, + sigma_c_eff, use_shape_noise=False, use_shape_error=True, shape_component1_err=None, shape_component2_err=None, - is_deltasigma=False, - validate_input=True, - ) - - assert_raises( - TypeError, - da.compute_galaxy_weights, - z_lens, - cosmo=None, - z_src=None, - use_pdz=False, - pzpdf=pzpdf, - pzbins=pzbins, - use_shape_noise=True, - shape_component1=None, - shape_component2=None, - use_shape_error=False, - shape_component1_err=None, - shape_component2_err=None, - is_deltasigma=True, - validate_input=True, - ) - assert_raises( - TypeError, - da.compute_galaxy_weights, - z_lens, - cosmo=None, - z_src=None, - use_pdz=True, - pzpdf=pzpdf, - pzbins=pzbins, - use_shape_noise=False, - use_shape_error=False, - shape_component1_err=None, - shape_component2_err=None, - is_deltasigma=True, validate_input=True, ) From 4e35820b917540f824f14ee2a15a51631e75a409 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 14:14:54 +0200 Subject: [PATCH 13/34] rm unused funcs --- clmm/redshift/tools.py | 77 ------------------------------------------ 1 file changed, 77 deletions(-) diff --git a/clmm/redshift/tools.py b/clmm/redshift/tools.py index 628cf37d0..82ffd670e 100644 --- a/clmm/redshift/tools.py +++ b/clmm/redshift/tools.py @@ -4,8 +4,6 @@ from scipy.integrate import simps from scipy.interpolate import interp1d -from ..utils.validation import validate_argument - def _integ_pzfuncs(pzpdf, pzbins, zmin=0.0, zmax=5, kernel=lambda z: 1.0, ngrid=1000): r""" @@ -118,78 +116,3 @@ def compute_for_good_redshifts( else: res = function(**kwargs) return res - - -def _validate_theory_z_src(loc_dict): - r"""Validation for z_src according to z_src_info. The conditions are: - - * z_src_info='discrete' : z_src must be array or float. - * z_src_info='distribution' : z_src must be a one dimentional function. - * z_src_info='beta' : z_src must be a tuple containing - ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`). - - Also, if approx is provided and not None, z_src_info must be 'distribution' or 'beta'. - - Parameters - ---------- - locals_dict: dict - Should be the call locals() - """ - if loc_dict["z_src_info"] == "discrete": - validate_argument(loc_dict, "z_src", "float_array", argmin=0) - elif loc_dict["z_src_info"] == "distribution": - validate_argument(loc_dict, "z_src", "function", none_ok=False) - beta_kwargs = {} if loc_dict["beta_kwargs"] is None else loc_dict["beta_kwargs"] - _def_keys = ["zmin", "zmax", "delta_z_cut"] - if any(key not in _def_keys for key in beta_kwargs): - raise KeyError( - f"beta_kwargs must contain only {_def_keys} keys, " - f" {beta_kwargs.keys()} provided." - ) - elif loc_dict["z_src_info"] == "beta": - validate_argument(loc_dict, "z_src", "array") - beta_info = { - "beta_s_mean": loc_dict["z_src"][0], - "beta_s_square_mean": loc_dict["z_src"][1], - } - validate_argument(beta_info, "beta_s_mean", "float_array") - validate_argument(beta_info, "beta_s_square_mean", "float_array") - if loc_dict.get("approx") and loc_dict["z_src_info"] not in ( - "distribution", - "beta", - ): - approx, z_src_info = loc_dict["approx"], loc_dict["z_src_info"] - raise ValueError( - f"approx='{approx}' requires z_src_info='distribution' or 'beta', " - f"z_src_info='{z_src_info}' was provided." - ) - - -def _validate_data_z_src(loc_dict): - r"""Validation for z_src according to z_src_info. The conditions are: - - * z_src_info='discrete' : z_src must be array or float. - * z_src_info='pdf' : z_src must be a one dimentional function. - * z_src_info='quantile' : z_src must be a tuple containing - ( :math:`\langle \beta_s \rangle, \langle \beta_s^2 \rangle`). - - Also, if approx is provided and not None, z_src_info must be 'distribution' or 'beta'. - - Parameters - ---------- - locals_dict: dict - Should be the call locals() - """ - if loc_dict["z_src_info"] == "discrete": - validate_argument(loc_dict, "z_src", "float_array", argmin=0) - elif loc_dict["z_src_info"] == "pdf": - validate_argument(loc_dict, "z_src", "function", none_ok=False) - integ_kwargs = {} if loc_dict["integ_kwargs"] is None else loc_dict["integ_kwargs"] - _def_keys = ["zmin", "zmax", "delta_z_cut"] - if any(key not in _def_keys for key in integ_kwargs): - raise KeyError( - f"integ_kwargs must contain only {_def_keys} keys, " - f" {integ_kwargs.keys()} provided." - ) - elif z_src_info == "quantile": - validate_argument(loc_dict, "z_src", "float_array") From 24f21a24a91ab453b991452119b67aa2b576bee7 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 14:15:12 +0200 Subject: [PATCH 14/34] update tests --- tests/test_dataops.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index ab8e98c3a..6301d0090 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -521,6 +521,10 @@ def test_compute_tangential_and_cross_components(modeling_data): err_msg="Cross Shear not correct when using cluster method", ) + # test basic weights functionality + cluster.compute_galaxy_weights() + expected = np.array([1.0, 1.0]) + assert_allclose(cluster.galcat["w_ls"], expected, **TOLERANCE) def test_compute_background_probability(): """test for compute background probability""" From 6f72adb8393e5bba58867a1efe0705fe6fbdebf1 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 14:16:02 +0200 Subject: [PATCH 15/34] fix fmts --- clmm/__init__.py | 2 +- .../NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb | 4 +--- examples/Paper_v1.0/mcmc.ipynb | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/clmm/__init__.py b/clmm/__init__.py index 6855e28e7..f558499ac 100644 --- a/clmm/__init__.py +++ b/clmm/__init__.py @@ -26,4 +26,4 @@ ) from . import support -__version__ = '1.8.0' +__version__ = "1.8.0" diff --git a/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb b/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb index 2d4f0c5ab..aab95262e 100644 --- a/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb +++ b/examples/NumCosmo/Example2_Fit_Halo_Mass_to_Shear_Catalog_NC.ipynb @@ -452,9 +452,7 @@ " Ncm.DataGaussDiag.__init__(self, n_points=0)\n", " self.moo = clmm.Modeling()\n", "\n", - " def init_from_data(\n", - " self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None\n", - " ):\n", + " def init_from_data(self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None):\n", " if moo:\n", " self.moo = moo\n", "\n", diff --git a/examples/Paper_v1.0/mcmc.ipynb b/examples/Paper_v1.0/mcmc.ipynb index cca43b78b..caa0393ca 100644 --- a/examples/Paper_v1.0/mcmc.ipynb +++ b/examples/Paper_v1.0/mcmc.ipynb @@ -450,9 +450,7 @@ " Ncm.DataGaussDiag.__init__(self, n_points=0)\n", " self.moo = clmm.Modeling()\n", "\n", - " def init_from_data(\n", - " self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None\n", - " ):\n", + " def init_from_data(self, z_cluster, r_source, z_src, gt_profile, gt_err, z_err=None, moo=None):\n", " if moo:\n", " self.moo = moo\n", "\n", From c976981b74fbf49a4750e1ccaadc9f878156b73a Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 14:18:53 +0200 Subject: [PATCH 16/34] rm commented part --- tests/test_dataops.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index 6301d0090..9b72890dc 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -445,23 +445,6 @@ def test_compute_tangential_and_cross_components(modeling_data): # Check behaviour for the deltasigma option. cosmo = clmm.Cosmology(H0=70.0, Omega_dm0=0.275, Omega_b0=0.025) - # Trying to got through line 173 of dataops/__init__.py - # da.compute_tangential_and_cross_components( - # ra_lens=ra_lens, - # dec_lens=dec_lens, - # ra_source=gals["ra"][0], - # dec_source=gals["dec"][0], - # shear1=gals["e1"][0], - # shear2=gals["e2"][0], - # is_deltasigma=True, - # use_pdz=True, - # cosmo=cosmo, - # z_lens=z_lens, - # z_src=None, - # pzbins=[[0.55, 0.6, 0.65, 0.7, 0.75]], - # pzpdf=[[0.01, 1, 0.01, 0.001, 0.0001]], - # ) - # check values for DeltaSigma sigma_c = cosmo.eval_sigma_crit(z_lens, gals["z"]) for geometry, expected in geo_tests: @@ -526,6 +509,7 @@ def test_compute_tangential_and_cross_components(modeling_data): expected = np.array([1.0, 1.0]) assert_allclose(cluster.galcat["w_ls"], expected, **TOLERANCE) + def test_compute_background_probability(): """test for compute background probability""" z_lens = 0.1 From 02c768e7abc52c9544b91bbc0cb8bb8f37676393 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 25 May 2023 19:26:39 +0200 Subject: [PATCH 17/34] make sigma_c=None for gamma components --- clmm/dataops/__init__.py | 32 ++++++++++++++++++-------------- tests/test_dataops.py | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 0c2789ffe..9fb5f7e08 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -29,7 +29,7 @@ def compute_tangential_and_cross_components( shear1, shear2, geometry="curve", - sigma_c=1.0, + sigma_c=None, validate_input=True, ): r"""Computes tangential- and cross- components for shear or ellipticity @@ -98,10 +98,10 @@ def compute_tangential_and_cross_components( geometry: str, optional Sky geometry to compute angular separation. Options are curve (uses astropy) or flat. - sigma_c : float, optional - Critical surface density in units of :math:`M_\odot\ Mpc^{-2}`. If sigma_c!=1, - the tangential and cross components returned are overdensities (Delta Sigma). - Results in units of :math:`M_\odot\ Mpc^{-2}` + sigma_c : None, array_like + Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. + If equals to None, shear components are returned, else $\Delta \Sigma$ components + are returned. validate_input: bool Validade each input argument @@ -125,7 +125,7 @@ def compute_tangential_and_cross_components( validate_argument(locals(), "shear1", "float_array") validate_argument(locals(), "shear2", "float_array") validate_argument(locals(), "geometry", str) - validate_argument(locals(), "sigma_c", "float_array") + validate_argument(locals(), "sigma_c", "float_array", none_ok=True) ra_source_, dec_source_, shear1_, shear2_ = arguments_consistency( [ra_source, dec_source, shear1, shear2], names=("Ra", "Dec", "Shear1", "Shear2"), @@ -153,9 +153,9 @@ def compute_tangential_and_cross_components( tangential_comp = _compute_tangential_shear(shear1_, shear2_, phi) cross_comp = _compute_cross_shear(shear1_, shear2_, phi) - # If the is_deltasigma flag is True, multiply the results by Sigma_crit. - tangential_comp *= sigma_c - cross_comp *= sigma_c + if sigma_c is not None: + tangential_comp *= sigma_c + cross_comp *= sigma_c return angsep, tangential_comp, cross_comp @@ -201,7 +201,7 @@ def compute_background_probability( def compute_galaxy_weights( - sigma_c, + sigma_c=None, use_shape_noise=False, shape_component1=None, shape_component2=None, @@ -242,9 +242,10 @@ def compute_galaxy_weights( Parameters ---------- - sigma_c : float, optional + sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. - Should be equal to 1 if weights for tangential shear are being computed. + If equals to None, weights are computed for shear, else weights are computed for + $\Delta \Sigma$. use_shape_noise: bool If `True` shape noise is included in the weight computation. It then requires `shape_componenet{1,2}` to be provided. Default: False. @@ -272,12 +273,13 @@ def compute_galaxy_weights( Individual lens source pair weights """ if validate_input: - validate_argument(locals(), "sigma_c", "float_array") + validate_argument(locals(), "sigma_c", "float_array", none_ok=True) validate_argument(locals(), "shape_component1", "float_array", none_ok=True) validate_argument(locals(), "shape_component2", "float_array", none_ok=True) validate_argument(locals(), "shape_component1_err", "float_array", none_ok=True) validate_argument(locals(), "shape_component2_err", "float_array", none_ok=True) validate_argument(locals(), "use_shape_noise", bool) + validate_argument(locals(), "use_shape_error", bool) arguments_consistency( [shape_component1, shape_component2], names=("shape_component1", "shape_component2"), @@ -285,7 +287,9 @@ def compute_galaxy_weights( ) # computing w_ls_geo - w_ls_geo = 1.0 / sigma_c**2 + w_ls_geo = 1.0 + if sigma_c is not None: + w_ls_geo /= sigma_c**2 # computing w_ls_shape err_e2 = 0 diff --git a/tests/test_dataops.py b/tests/test_dataops.py index 6301d0090..9bdbedc21 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -648,7 +648,7 @@ def test_compute_galaxy_weights(): # test with is_deltasigma=False and geometric weights only weights = da.compute_galaxy_weights( - sigma_c=1.0, + sigma_c=None, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, From 75ca0521bb13527f9f53d35c3cdb6a42659d6def Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 10:47:12 +0200 Subject: [PATCH 18/34] rm is_deltasigma from docstring --- clmm/dataops/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 9fb5f7e08..db78e0332 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -69,17 +69,15 @@ def compute_tangential_and_cross_components( g_t =& -\left( g_1\cos\left(2\phi\right)+g_2\sin\left(2\phi\right)\right)\\ g_x =& g_1 \sin\left(2\phi\right)-g_2\cos\left(2\phi\right) - Finally, and if requested by the user throught the `is_deltasigma` flag, an estimate of the + Finally, if the critical surface density (:math:`\Sigma_c`) is provided, an estimate of the excess surface density :math:`\widehat{\Delta\Sigma}` is obtained from .. math:: \widehat{\Delta\Sigma_{t,x}} = g_{t,x} \times \Sigma_c(cosmo, z_l, z_{\text{src}}) - where :math:`\Sigma_c` is the critical surface density that depends on the cosmology and on - the lens and source redshifts. If :math:`g_{t,x}` correspond to the shear, the above - expression is an accurate. However, if :math:`g_{t,x}` correspond to ellipticities or reduced - shear, this expression only gives an estimate :math:`\widehat{\Delta\Sigma_{t,x}}`, valid only - in the weak lensing regime. + If :math:`g_{t,x}` correspond to the shear, the above expression is an accurate. However, if + :math:`g_{t,x}` correspond to ellipticities or reduced shear, this expression only gives an + estimate :math:`\widehat{\Delta\Sigma_{t,x}}`, valid only in the weak lensing regime. Parameters ---------- From 75675c03d84e2228f7d4565405dae845c3165bb9 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 10:48:36 +0200 Subject: [PATCH 19/34] update docstring --- clmm/dataops/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index db78e0332..353109dc8 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -218,15 +218,15 @@ def compute_galaxy_weights( via the critical surface density. It can be expressed as: .. math:: - w_{ls, \text{geo}} = \Sigma_{\rm crit}(z_l, z_{\text{src}})^{-2}\;. + w_{ls, \text{geo}} = \Sigma_\text{crit}(z_l, z_{\text{src}})^{-2}\;. when only redshift point estimates are provided, or as: .. math:: - w_{ls, \text{geo}} = \Sigma_{\rm crit}^{\rm eff}(z_l, z_{\text{src}})^{-2} + w_{ls, \text{geo}} = \Sigma_\text{crit}^\text{eff}(z_l, z_{\text{src}})^{-2} = \left[\int_{\delta + z_l} dz_s p_{\text{photoz}}(z_s) - \Sigma_{\rm crit}(z_l, z_s)^{-1}\right]^2 + \Sigma_\text{crit}(z_l, z_s)^{-1}\right]^2 when the redshift pdf of each source, :math:`p_{\text{photoz}}(z_s)`, is known. From 13368e0fd8f56e335836a9094e9420ed37fc150f Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 11:05:06 +0200 Subject: [PATCH 20/34] update docstrings --- clmm/dataops/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 353109dc8..f25c18e1b 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -69,11 +69,11 @@ def compute_tangential_and_cross_components( g_t =& -\left( g_1\cos\left(2\phi\right)+g_2\sin\left(2\phi\right)\right)\\ g_x =& g_1 \sin\left(2\phi\right)-g_2\cos\left(2\phi\right) - Finally, if the critical surface density (:math:`\Sigma_c`) is provided, an estimate of the + Finally, if the critical surface density (:math:`\Sigma_\text{crit}`) is provided, an estimate of the excess surface density :math:`\widehat{\Delta\Sigma}` is obtained from .. math:: - \widehat{\Delta\Sigma_{t,x}} = g_{t,x} \times \Sigma_c(cosmo, z_l, z_{\text{src}}) + \widehat{\Delta\Sigma_{t,x}} = g_{t,x} \times \Sigma_\text{crit}(z_l, z_{\text{src}}) If :math:`g_{t,x}` correspond to the shear, the above expression is an accurate. However, if :math:`g_{t,x}` correspond to ellipticities or reduced shear, this expression only gives an @@ -98,7 +98,7 @@ def compute_tangential_and_cross_components( Options are curve (uses astropy) or flat. sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. - If equals to None, shear components are returned, else $\Delta \Sigma$ components + If equals to None, shear components are returned, else :math:`\Delta \Sigma` components are returned. validate_input: bool Validade each input argument @@ -164,9 +164,9 @@ def compute_background_probability( r"""Probability for being a background galaxy, defined by: .. math:: - P(z_s > z_l) = \int_{z_l}^{+\infty} dz_s p_{\text{photoz}}(z_s), + P(z_s > z_l) = \int_{z_l}^{+\infty} dz_s \; p_{\text{photoz}}(z_s), - when the photometric probability density functions ($p p_{\text{photoz}}(z_s)$) are provided. + when the photometric probability density functions (:math:`p_{\text{photoz}}(z_s)`) are provided. In the case of true redshifts, it returns 1 if :math:`z_s > z_l` else returns 0. @@ -213,9 +213,9 @@ def compute_galaxy_weights( The weights :math:`w_{ls}` express as : :math:`w_{ls} = w_{ls, \text{geo}} \times w_{ls, \text{shape}}`, following E. S. Sheldon et al. (2003), arXiv:astro-ph/0312036: - 1. When computed for tangential shear, the geometrical weights :math:`w_{ls, \text{geo}}` are - equal to 1. When compute for $\Delta \Sigma$, it depends on lens and source redshift information - via the critical surface density. It can be expressed as: + 1. If computed for shear, the geometrical weights :math:`w_{ls, \text{geo}}` are equal to 1. If + computed for :math:`\Delta \Sigma`, it depends on lens and source redshift information via the + critical surface density. This component can be expressed as: .. math:: w_{ls, \text{geo}} = \Sigma_\text{crit}(z_l, z_{\text{src}})^{-2}\;. @@ -225,7 +225,7 @@ def compute_galaxy_weights( .. math:: w_{ls, \text{geo}} = \Sigma_\text{crit}^\text{eff}(z_l, z_{\text{src}})^{-2} - = \left[\int_{\delta + z_l} dz_s p_{\text{photoz}}(z_s) + = \left[\int_{\delta + z_l} dz_s \; p_{\text{photoz}}(z_s) \Sigma_\text{crit}(z_l, z_s)^{-1}\right]^2 when the redshift pdf of each source, :math:`p_{\text{photoz}}(z_s)`, is known. @@ -234,8 +234,8 @@ def compute_galaxy_weights( measurement errors .. math:: - w_{ls, \text{shape}}^{-1} = (\sigma_{\text{shapenoise}}^2 + - \sigma_{\text{measurement}}^2) + w_{ls, \text{shape}}^{-1} = \sigma_{\text{shapenoise}}^2 + + \sigma_{\text{measurement}}^2 Parameters @@ -243,7 +243,7 @@ def compute_galaxy_weights( sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. If equals to None, weights are computed for shear, else weights are computed for - $\Delta \Sigma$. + :math:`\Delta \Sigma`. use_shape_noise: bool If `True` shape noise is included in the weight computation. It then requires `shape_componenet{1,2}` to be provided. Default: False. From 0122f9f0845b0f0554855d41d1139993bbb5b50f Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 11:43:34 +0200 Subject: [PATCH 21/34] force recomputation of sigma_c in GalaxyCluster when use_pdz flag is changed --- clmm/galaxycluster.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index 3d144f9a6..244d3d68a 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -114,7 +114,7 @@ def _repr_html_(self): f"
{self.galcat._html_table()}" ) - def add_critical_surface_density(self, cosmo, use_pdz=False): + def add_critical_surface_density(self, cosmo, use_pdz=False, force=False): r"""Computes the critical surface density for each galaxy in `galcat`. It only runs if input cosmo != galcat cosmo or if `sigma_c` not in `galcat`. @@ -128,6 +128,8 @@ def add_critical_surface_density(self, cosmo, use_pdz=False): `sigma_c` is computed as 1/<1/Sigma_crit>, where the average is performed using the individual galaxy redshift pdf. In that case, the `galcat` table should have pzbins` and `pzpdf` columns. + force : bool + Force recomputation of sigma_c. Returns ------- @@ -135,7 +137,13 @@ def add_critical_surface_density(self, cosmo, use_pdz=False): """ if cosmo is None: raise TypeError("To compute Sigma_crit, please provide a cosmology") - if cosmo.get_desc() != self.galcat.meta["cosmo"] or "sigma_c" not in self.galcat.columns: + sigmac_type_required = "effective" if use_pdz else "standard" + if ( + cosmo.get_desc() != self.galcat.meta["cosmo"] + or "sigma_c" not in self.galcat.columns + or self.galcat.meta.get("sigmac_type", None) != sigmac_type_required + or force + ): if self.z is None: raise TypeError("Cluster's redshift is None. Cannot compute Sigma_crit") if not use_pdz and "z" not in self.galcat.columns: @@ -149,7 +157,7 @@ def add_critical_surface_density(self, cosmo, use_pdz=False): ) self.galcat.update_cosmo(cosmo, overwrite=True) - if use_pdz is False: + if not use_pdz: self.galcat["sigma_c"] = cosmo.eval_sigma_crit(self.z, self.galcat["z"]) self.galcat.meta["sigmac_type"] = "standard" else: @@ -368,8 +376,7 @@ def compute_galaxy_weights( # input cols col_dict = {} if is_deltasigma: - if "sigma_c" not in self.galcat.columns: - self.add_critical_surface_density(cosmo, use_pdz=use_pdz) + self.add_critical_surface_density(cosmo, use_pdz=use_pdz) col_dict.update({"sigma_c": "sigma_c"}) if use_shape_noise: col_dict.update( From bd4d6b6f16d5618bf1a56ef1ef3d091cfb88ebe4 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 13:44:45 +0200 Subject: [PATCH 22/34] separate sigma_c and sigma_c_eff in galcat --- clmm/galaxycluster.py | 46 +++++++++++++++++++------------------ tests/test_galaxycluster.py | 3 ++- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index 244d3d68a..06a9176f1 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -137,11 +137,10 @@ def add_critical_surface_density(self, cosmo, use_pdz=False, force=False): """ if cosmo is None: raise TypeError("To compute Sigma_crit, please provide a cosmology") - sigmac_type_required = "effective" if use_pdz else "standard" + sigmac_colname = "sigma_c_eff" if use_pdz else "sigma_c" if ( cosmo.get_desc() != self.galcat.meta["cosmo"] - or "sigma_c" not in self.galcat.columns - or self.galcat.meta.get("sigmac_type", None) != sigmac_type_required + or sigmac_colname not in self.galcat.columns or force ): if self.z is None: @@ -158,18 +157,17 @@ def add_critical_surface_density(self, cosmo, use_pdz=False, force=False): self.galcat.update_cosmo(cosmo, overwrite=True) if not use_pdz: - self.galcat["sigma_c"] = cosmo.eval_sigma_crit(self.z, self.galcat["z"]) - self.galcat.meta["sigmac_type"] = "standard" + self.galcat[sigmac_colname] = cosmo.eval_sigma_crit(self.z, self.galcat["z"]) else: zdata = self._get_input_galdata({"pzpdf": "pzpdf", "pzbins": "pzbins"}) - self.galcat["sigma_c"] = compute_critical_surface_density_eff( + self.galcat[sigmac_colname] = compute_critical_surface_density_eff( cosmo=cosmo, z_cluster=self.z, pzbins=zdata["pzbins"], pzpdf=zdata["pzpdf"], validate_input=self.validate_input, ) - self.galcat.meta["sigmac_type"] = "effective" + return sigmac_colname def _get_input_galdata(self, col_dict): """ @@ -266,18 +264,16 @@ def compute_tangential_and_cross_components( Cross shear (or assimilated quantity) for each source galaxy """ # Check is all the required data is available - cols = self._get_input_galdata( - { - "ra_source": "ra", - "dec_source": "dec", - "shear1": shape_component1, - "shear2": shape_component2, - } - ) - + col_dict = { + "ra_source": "ra", + "dec_source": "dec", + "shear1": shape_component1, + "shear2": shape_component2, + } if is_deltasigma: - self.add_critical_surface_density(cosmo, use_pdz=use_pdz) - cols["sigma_c"] = self.galcat["sigma_c"] + sigmac_colname = self.add_critical_surface_density(cosmo, use_pdz=use_pdz) + col_dict.update({"sigma_c": sigmac_colname}) + cols = self._get_input_galdata(col_dict) # compute shears angsep, tangential_comp, cross_comp = compute_tangential_and_cross_components( @@ -291,6 +287,10 @@ def compute_tangential_and_cross_components( self.galcat["theta"] = angsep self.galcat[tan_component] = tangential_comp self.galcat[cross_component] = cross_comp + if is_deltasigma: + sigmac_type = "effective" if use_pdz else "standard" + self.galcat.meta[f"{tan_component}_sigmac_type"] = sigmac_type + self.galcat.meta[f"{cross_component}_sigmac_type"] = sigmac_type return angsep, tangential_comp, cross_comp def compute_background_probability( @@ -376,8 +376,8 @@ def compute_galaxy_weights( # input cols col_dict = {} if is_deltasigma: - self.add_critical_surface_density(cosmo, use_pdz=use_pdz) - col_dict.update({"sigma_c": "sigma_c"}) + sigmac_colname = self.add_critical_surface_density(cosmo, use_pdz=use_pdz) + col_dict.update({"sigma_c": sigmac_colname}) if use_shape_noise: col_dict.update( { @@ -393,8 +393,6 @@ def compute_galaxy_weights( } ) cols = self._get_input_galdata(col_dict) - if not is_deltasigma: - cols["sigma_c"] = 1.0 # computes weights w_ls = compute_galaxy_weights( @@ -405,6 +403,10 @@ def compute_galaxy_weights( ) if add: self.galcat[weight_name] = w_ls + if is_deltasigma: + self.galcat.meta[f"{weight_name}_sigmac_type"] = ( + "effective" if use_pdz else "standard" + ) return w_ls def draw_gal_z_from_pdz(self, zcol_out="z", overwrite=False, nobj=1, xmin=None, xmax=None): diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index b9c674d9f..61ac6fba5 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -177,7 +177,8 @@ def test_integrity_of_lensfuncs(): cluster.compute_tangential_and_cross_components( is_deltasigma=True, use_pdz=True, cosmo=cosmo, add=True ) - assert_equal(cluster.galcat.meta["sigmac_type"], "effective") + for comp_name in ("et", "ex"): + assert_equal(cluster.galcat.meta[f"{comp_name}_sigmac_type"], "effective") def test_integrity_of_probfuncs(): From 200a6aa45f3e55f3a627f4973fa34a420cef5070 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 13:49:26 +0200 Subject: [PATCH 23/34] update examples/demo_compute_deltasigma_weights.ipynb --- .../demo_compute_deltasigma_weights.ipynb | 79 +++++++++---------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/examples/demo_compute_deltasigma_weights.ipynb b/examples/demo_compute_deltasigma_weights.ipynb index ff98eeac5..fb5a62fa9 100644 --- a/examples/demo_compute_deltasigma_weights.ipynb +++ b/examples/demo_compute_deltasigma_weights.ipynb @@ -123,20 +123,7 @@ "z_gal = noisy_data_z[\"ztrue\"]\n", "# add redshift dependency on shape measurement error\n", "noisy_data_z[\"e_err\"] = noisy_data_z[\"e_err\"] * (1 + 0.4 * noisy_data_z[\"ztrue\"])\n", - "cl0 = GalaxyCluster(\"mock_cluster\", cluster_ra, cluster_dec, cluster_z, noisy_data_z)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "71a6f518-f910-4d5e-b5a5-7c9d82366b86", - "metadata": {}, - "outputs": [], - "source": [ - "args = (\"mock_cluster\", cluster_ra, cluster_dec, cluster_z, noisy_data_z)\n", - "cl1 = GalaxyCluster(*args)\n", - "cl2 = GalaxyCluster(*args)\n", - "cl3 = GalaxyCluster(*args)" + "cluster = GalaxyCluster(\"mock_cluster\", cluster_ra, cluster_dec, cluster_z, noisy_data_z)" ] }, { @@ -187,11 +174,8 @@ "outputs": [], "source": [ "w_ls_true = compute_galaxy_weights(\n", - " cluster_z,\n", - " cosmo,\n", " sigma_c=sigma_c,\n", " use_shape_noise=False,\n", - " is_deltasigma=True,\n", ")" ] }, @@ -211,7 +195,7 @@ "metadata": {}, "outputs": [], "source": [ - "w_ls_point = cl0.compute_galaxy_weights(\n", + "w_ls_point = cluster.compute_galaxy_weights(\n", " use_pdz=False, weight_name=\"w_ls_point\", cosmo=cosmo, is_deltasigma=True, add=True\n", ")" ] @@ -262,7 +246,7 @@ "sigma_c_eff = compute_critical_surface_density_eff(\n", " cosmo=cosmo,\n", " z_cluster=cluster_z,\n", - " pzbins=noisy_data_z[\"pzbins\"],\n", + " pzbins=noisy_data_z.pzpdf_info[\"zbins\"],\n", " pzpdf=noisy_data_z[\"pzpdf\"],\n", ")" ] @@ -275,11 +259,8 @@ "outputs": [], "source": [ "w_ls_photoz = compute_galaxy_weights(\n", - " cluster_z,\n", - " cosmo,\n", " sigma_c=sigma_c_eff,\n", " use_shape_noise=False,\n", - " is_deltasigma=True,\n", ")" ] }, @@ -300,7 +281,7 @@ "metadata": {}, "outputs": [], "source": [ - "w_ls_photoz = cl1.compute_galaxy_weights(\n", + "w_ls_photoz = cluster.compute_galaxy_weights(\n", " use_pdz=True, weight_name=\"w_ls_photoz\", cosmo=cosmo, is_deltasigma=True, add=True\n", ")" ] @@ -330,7 +311,7 @@ "metadata": {}, "outputs": [], "source": [ - "w_ls_shape = cl2.compute_galaxy_weights(\n", + "w_ls_shape = cluster.compute_galaxy_weights(\n", " use_pdz=False,\n", " use_shape_noise=True,\n", " shape_component1=\"e1\",\n", @@ -370,7 +351,7 @@ "metadata": {}, "outputs": [], "source": [ - "w_ls_photoz_shape = cl3.compute_galaxy_weights(\n", + "w_ls_photoz_shape = cluster.compute_galaxy_weights(\n", " use_pdz=True,\n", " use_shape_noise=True,\n", " shape_component1=\"e1\",\n", @@ -400,7 +381,7 @@ "metadata": {}, "outputs": [], "source": [ - "cl0.galcat.colnames" + "cluster.galcat.colnames" ] }, { @@ -410,7 +391,7 @@ "tags": [] }, "source": [ - "### $\\Sigma_c$ metadata\n", + "### $\\Sigma_{\\rm crit}$ metadata\n", "\n", "As seen above, the weights are computed either using the standard definition of $\\Sigma_{\\rm crit}^{\\rm std}$, using point estimate redshift, or the effective definition based on the inverse $\\Sigma_c^{\\rm eff}$ averaged over the redshift PDF $p(z)$:\n", "\n", @@ -428,8 +409,22 @@ "metadata": {}, "outputs": [], "source": [ - "print(f\"For cluster 0: {cl0.galcat.meta['sigmac_type']}\")\n", - "print(f\"For cluster 1: {cl1.galcat.meta['sigmac_type']}\")" + "print(\n", + " \"For cluster w_ls_point column :\",\n", + " cluster.galcat.meta['w_ls_point_sigmac_type'],\n", + ")\n", + "print(\n", + " \"For cluster w_ls_photoz column :\",\n", + " cluster.galcat.meta['w_ls_photoz_sigmac_type'],\n", + ")\n", + "print(\n", + " \"For cluster w_ls_shape column :\",\n", + " cluster.galcat.meta['w_ls_shape_sigmac_type'],\n", + ")\n", + "print(\n", + " \"For cluster w_ls_photoz_shape column :\",\n", + " cluster.galcat.meta['w_ls_photoz_shape_sigmac_type'],\n", + ")" ] }, { @@ -460,30 +455,30 @@ "\n", "ax[0].scatter(\n", " z_gal,\n", - " 1e3 * cl0.galcat[\"w_ls_point\"] / np.sum(cl0.galcat[\"w_ls_point\"]),\n", + " 1e3 * cluster.galcat[\"w_ls_point\"] / cluster.galcat[\"w_ls_point\"].sum(),\n", " c=\"r\",\n", " label=\"point estimate z\",\n", " s=5,\n", ")\n", "ax[0].scatter(\n", " z_gal,\n", - " 1e3 * cl1.galcat[\"w_ls_photoz\"] / np.sum(cl1.galcat[\"w_ls_photoz\"]),\n", + " 1e3 * cluster.galcat[\"w_ls_photoz\"] / cluster.galcat[\"w_ls_photoz\"].sum(),\n", " c=\"orange\",\n", " label=\"photoz pdf\",\n", " marker=\"+\",\n", " s=5,\n", ")\n", - "ax[0].scatter(z_gal, 1e3 * w_ls_true / np.sum(w_ls_true), c=\"g\", label=\"true z\", marker=\"x\", s=5)\n", + "ax[0].scatter(z_gal, 1e3 * w_ls_true / w_ls_true.sum(), c=\"g\", label=\"true z\", marker=\"x\", s=5)\n", "ax[1].scatter(\n", " z_gal,\n", - " 1e3 * cl2.galcat[\"w_ls_shape\"] / np.sum(cl2.galcat[\"w_ls_shape\"]),\n", + " 1e3 * cluster.galcat[\"w_ls_shape\"] / cluster.galcat[\"w_ls_shape\"].sum(),\n", " c=\"blue\",\n", " label=r\"shape_error, point z\",\n", " s=5,\n", ")\n", "ax[1].scatter(\n", " z_gal,\n", - " 1e3 * cl3.galcat[\"w_ls_photoz_shape\"] / np.sum(cl3.galcat[\"w_ls_photoz_shape\"]),\n", + " 1e3 * cluster.galcat[\"w_ls_photoz_shape\"] / cluster.galcat[\"w_ls_photoz_shape\"].sum(),\n", " c=\"cyan\",\n", " label=\"shape_error + photoz pdf\",\n", " s=5,\n", @@ -555,7 +550,7 @@ " field_size=10.0,\n", " ngals=3000,\n", ")\n", - "cl0_new = clmm.GalaxyCluster(\"mock_cluster\", 0, 0, cluster_z, noisy_data_z_2)" + "cluster_new = clmm.GalaxyCluster(\"mock_cluster\", 0, 0, cluster_z, noisy_data_z_2)" ] }, { @@ -575,7 +570,7 @@ "metadata": {}, "outputs": [], "source": [ - "p_background_photoz_1 = cl0.compute_background_probability(\n", + "p_background_photoz_1 = cluster.compute_background_probability(\n", " use_pdz=True, p_background_name=\"p_background_photoz_1\", add=True\n", ")" ] @@ -587,7 +582,7 @@ "metadata": {}, "outputs": [], "source": [ - "p_background_photoz_2 = cl0_new.compute_background_probability(\n", + "p_background_photoz_2 = cluster_new.compute_background_probability(\n", " use_pdz=True, p_background_name=\"p_background_photoz_2\", add=True\n", ")" ] @@ -604,7 +599,7 @@ "\n", "plt.tick_params(axis=\"both\", which=\"major\", labelsize=10)\n", "plt.scatter(\n", - " cl0_new.galcat[\"ztrue\"],\n", + " cluster_new.galcat[\"ztrue\"],\n", " p_background_photoz_2,\n", " c=\"darkorange\",\n", " label=r\"$\\sigma_z = 0.02$\",\n", @@ -613,7 +608,7 @@ " alpha=0.5,\n", ")\n", "plt.scatter(\n", - " cl0.galcat[\"ztrue\"],\n", + " cluster.galcat[\"ztrue\"],\n", " p_background_photoz_1,\n", " c=\"blue\",\n", " label=r\"$\\sigma_z = 0.05$\",\n", @@ -629,12 +624,12 @@ "\n", "plt.xlabel(\"true source redshift\", fontsize=15)\n", "plt.ylabel(r\"$P(z_s > z_l)$\", fontsize=15)\n", - "plt.legend(frameon=True, fontsize=15)\n", + "plt.legend(frameon=True, fontsize=15, loc=4)\n", "\n", "\n", "ax2 = fig.add_axes([0.155, 0.65, 0.17, 0.18])\n", "ax2.scatter(\n", - " cl0_new.galcat[\"z\"],\n", + " cluster_new.galcat[\"z\"],\n", " p_background_photoz_2,\n", " c=\"darkorange\",\n", " label=r\"$\\sigma_z = 0.02$\",\n", @@ -644,7 +639,7 @@ " lw=0.1,\n", ")\n", "ax2.scatter(\n", - " cl0.galcat[\"z\"],\n", + " cluster.galcat[\"z\"],\n", " p_background_photoz_1,\n", " c=\"blue\",\n", " label=r\"$\\sigma_z = 0.05$\",\n", From 2ee9fc4ded59d1cd189975fdb8669f4a06174973 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 13:56:21 +0200 Subject: [PATCH 24/34] fix for type(sigma_c)=list --- clmm/dataops/__init__.py | 7 ++++--- examples/demo_compute_deltasigma_weights.ipynb | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index f25c18e1b..a4edca95a 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -152,8 +152,9 @@ def compute_tangential_and_cross_components( cross_comp = _compute_cross_shear(shear1_, shear2_, phi) if sigma_c is not None: - tangential_comp *= sigma_c - cross_comp *= sigma_c + _sigma_c_arr = np.array(sigma_c) + tangential_comp *= _sigma_c_arr + cross_comp *= _sigma_c_arr return angsep, tangential_comp, cross_comp @@ -287,7 +288,7 @@ def compute_galaxy_weights( # computing w_ls_geo w_ls_geo = 1.0 if sigma_c is not None: - w_ls_geo /= sigma_c**2 + w_ls_geo /= np.array(sigma_c) ** 2 # computing w_ls_shape err_e2 = 0 diff --git a/examples/demo_compute_deltasigma_weights.ipynb b/examples/demo_compute_deltasigma_weights.ipynb index fb5a62fa9..4d5b51110 100644 --- a/examples/demo_compute_deltasigma_weights.ipynb +++ b/examples/demo_compute_deltasigma_weights.ipynb @@ -411,19 +411,19 @@ "source": [ "print(\n", " \"For cluster w_ls_point column :\",\n", - " cluster.galcat.meta['w_ls_point_sigmac_type'],\n", + " cluster.galcat.meta[\"w_ls_point_sigmac_type\"],\n", ")\n", "print(\n", " \"For cluster w_ls_photoz column :\",\n", - " cluster.galcat.meta['w_ls_photoz_sigmac_type'],\n", + " cluster.galcat.meta[\"w_ls_photoz_sigmac_type\"],\n", ")\n", "print(\n", " \"For cluster w_ls_shape column :\",\n", - " cluster.galcat.meta['w_ls_shape_sigmac_type'],\n", + " cluster.galcat.meta[\"w_ls_shape_sigmac_type\"],\n", ")\n", "print(\n", " \"For cluster w_ls_photoz_shape column :\",\n", - " cluster.galcat.meta['w_ls_photoz_shape_sigmac_type'],\n", + " cluster.galcat.meta[\"w_ls_photoz_shape_sigmac_type\"],\n", ")" ] }, From 87da6bef4e6298066b1b6d11cbc9623570363e60 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Fri, 26 May 2023 13:58:36 +0200 Subject: [PATCH 25/34] pylint clmm/dataops/__init__.py --- clmm/dataops/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index a4edca95a..4e374eaf4 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -69,8 +69,8 @@ def compute_tangential_and_cross_components( g_t =& -\left( g_1\cos\left(2\phi\right)+g_2\sin\left(2\phi\right)\right)\\ g_x =& g_1 \sin\left(2\phi\right)-g_2\cos\left(2\phi\right) - Finally, if the critical surface density (:math:`\Sigma_\text{crit}`) is provided, an estimate of the - excess surface density :math:`\widehat{\Delta\Sigma}` is obtained from + Finally, if the critical surface density (:math:`\Sigma_\text{crit}`) is provided, an estimate + of the excess surface density :math:`\widehat{\Delta\Sigma}` is obtained from .. math:: \widehat{\Delta\Sigma_{t,x}} = g_{t,x} \times \Sigma_\text{crit}(z_l, z_{\text{src}}) @@ -167,8 +167,8 @@ def compute_background_probability( .. math:: P(z_s > z_l) = \int_{z_l}^{+\infty} dz_s \; p_{\text{photoz}}(z_s), - when the photometric probability density functions (:math:`p_{\text{photoz}}(z_s)`) are provided. - In the case of true redshifts, it returns 1 if :math:`z_s > z_l` else returns 0. + when the photometric probability density functions (:math:`p_{\text{photoz}}(z_s)`) are + provided. In the case of true redshifts, it returns 1 if :math:`z_s > z_l` else returns 0. Parameters From ff8c474ccb093c98f241496eefece958906e1923 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Wed, 12 Jul 2023 16:20:33 +0200 Subject: [PATCH 26/34] fix docstring --- clmm/galaxycluster.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index 06a9176f1..764a72a35 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -217,15 +217,14 @@ def compute_tangential_and_cross_components( r"""Adds a tangential- and cross- components for shear or ellipticity to self Calls `clmm.dataops.compute_tangential_and_cross_components` with the following arguments: - ra_lens: cluster Ra - dec_lens: cluster Dec + ra_lens: `cluster` Ra + dec_lens: `cluster` Dec ra_source: `galcat` Ra dec_source: `galcat` Dec shear1: `galcat` shape_component1 shear2: `galcat` shape_component2 geometry: `input` geometry is_deltasigma: `input` is_deltasigma - sigma_c: `galcat` sigma_c | None Parameters ---------- From 426b799b498cfdd6df79ecd8234ae89439c14b22 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 13 Jul 2023 15:31:19 +0200 Subject: [PATCH 27/34] add is_deltasigma back to dataops.compute_tangential_and_cross_components and dataops.compute_galaxy_weights --- clmm/dataops/__init__.py | 17 +++++++++++++---- clmm/galaxycluster.py | 2 ++ clmm/utils/__init__.py | 1 + clmm/utils/validation.py | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 4e374eaf4..82b61b20e 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -13,6 +13,7 @@ validate_argument, _validate_ra, _validate_dec, + _validate_is_deltasigma_sigma_c, ) from ..redshift import ( _integ_pzfuncs, @@ -29,6 +30,7 @@ def compute_tangential_and_cross_components( shear1, shear2, geometry="curve", + is_deltasigma=False, sigma_c=None, validate_input=True, ): @@ -96,10 +98,12 @@ def compute_tangential_and_cross_components( geometry: str, optional Sky geometry to compute angular separation. Options are curve (uses astropy) or flat. + is_deltasigma: bool + If `True`, the tangential and cross components returned are multiplied by Sigma_crit. + It requires `sigma_c` argument. Results in units of :math:`M_\odot\ Mpc^{-2}` sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. - If equals to None, shear components are returned, else :math:`\Delta \Sigma` components - are returned. + Used only when is_deltasigma=True. validate_input: bool Validade each input argument @@ -129,6 +133,7 @@ def compute_tangential_and_cross_components( names=("Ra", "Dec", "Shear1", "Shear2"), prefix="Tangential- and Cross- shape components sources", ) + _validate_is_deltasigma_sigma_c(locals()) elif np.iterable(ra_source): ra_source_, dec_source_, shear1_, shear2_ = ( np.array(col) for col in [ra_source, dec_source, shear1, shear2] @@ -200,6 +205,7 @@ def compute_background_probability( def compute_galaxy_weights( + is_deltasigma=False, sigma_c=None, use_shape_noise=False, shape_component1=None, @@ -241,10 +247,12 @@ def compute_galaxy_weights( Parameters ---------- + is_deltasigma: bool + If `True`, the tangential and cross components returned are multiplied by Sigma_crit. + It requires `sigma_c` argument. Results in units of :math:`M_\odot\ Mpc^{-2}` sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. - If equals to None, weights are computed for shear, else weights are computed for - :math:`\Delta \Sigma`. + Used only when is_deltasigma=True. use_shape_noise: bool If `True` shape noise is included in the weight computation. It then requires `shape_componenet{1,2}` to be provided. Default: False. @@ -284,6 +292,7 @@ def compute_galaxy_weights( names=("shape_component1", "shape_component2"), prefix="Shape components sources", ) + _validate_is_deltasigma_sigma_c(locals()) # computing w_ls_geo w_ls_geo = 1.0 diff --git a/clmm/galaxycluster.py b/clmm/galaxycluster.py index 764a72a35..b4db5446c 100644 --- a/clmm/galaxycluster.py +++ b/clmm/galaxycluster.py @@ -276,6 +276,7 @@ def compute_tangential_and_cross_components( # compute shears angsep, tangential_comp, cross_comp = compute_tangential_and_cross_components( + is_deltasigma=is_deltasigma, ra_lens=self.ra, dec_lens=self.dec, geometry=geometry, @@ -395,6 +396,7 @@ def compute_galaxy_weights( # computes weights w_ls = compute_galaxy_weights( + is_deltasigma=is_deltasigma, use_shape_noise=use_shape_noise, use_shape_error=use_shape_error, validate_input=self.validate_input, diff --git a/clmm/utils/__init__.py b/clmm/utils/__init__.py index 9f8d1197c..cf15420ee 100644 --- a/clmm/utils/__init__.py +++ b/clmm/utils/__init__.py @@ -38,6 +38,7 @@ validate_argument, _validate_ra, _validate_dec, + _validate_is_deltasigma_sigma_c, ) from .units import ( diff --git a/clmm/utils/validation.py b/clmm/utils/validation.py index 29d4dffac..f08e2ad86 100644 --- a/clmm/utils/validation.py +++ b/clmm/utils/validation.py @@ -207,3 +207,18 @@ def _validate_dec(loc, dec_name, is_array): """ v_type = "float_array" if is_array else (float, str) validate_argument(loc, dec_name, v_type, argmin=-90, eqmin=True, argmax=90, eqmax=True) + + +def _validate_is_deltasigma_sigma_c(loc): + """ "Validate the compatibility between is_deltasigma and sigma_c arguments. + + + Parameters + ---------- + loc: dict + Dictionary with all input arguments. Should be locals(). + """ + if loc["is_deltasigma"] and loc["sigma_c"] is None: + raise TypeError("sigma_c (=None) must be provided when is_deltasigma=True") + if not loc["is_deltasigma"] and loc["sigma_c"] is not None: + raise TypeError(f"sigma_c (={loc['sigma_c']}) be provided when is_deltasigma=False") From 5b71380a420e4d36eefcee9a9799d3df94d41844 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 13 Jul 2023 15:32:18 +0200 Subject: [PATCH 28/34] update tests --- tests/test_dataops.py | 46 ++++++++++++++++++++++++++++++++----- tests/test_galaxycluster.py | 4 +--- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/tests/test_dataops.py b/tests/test_dataops.py index 95de095b1..f60ac795b 100644 --- a/tests/test_dataops.py +++ b/tests/test_dataops.py @@ -447,6 +447,32 @@ def test_compute_tangential_and_cross_components(modeling_data): # check values for DeltaSigma sigma_c = cosmo.eval_sigma_crit(z_lens, gals["z"]) + # check validation between is_deltasigma and sigma_c + assert_raises( + TypeError, + da.compute_tangential_and_cross_components, + ra_lens=ra_lens, + dec_lens=dec_lens, + ra_source=gals["ra"], + dec_source=gals["dec"], + shear1=gals["e1"], + shear2=gals["e2"], + is_deltasigma=False, + sigma_c=sigma_c, + ) + assert_raises( + TypeError, + da.compute_tangential_and_cross_components, + ra_lens=ra_lens, + dec_lens=dec_lens, + ra_source=gals["ra"], + dec_source=gals["dec"], + shear1=gals["e1"], + shear2=gals["e2"], + is_deltasigma=True, + sigma_c=None, + ) + # test values for geometry, expected in geo_tests: angsep_DS, tDS, xDS = da.compute_tangential_and_cross_components( ra_lens=ra_lens, @@ -455,6 +481,7 @@ def test_compute_tangential_and_cross_components(modeling_data): dec_source=gals["dec"], shear1=gals["e1"], shear2=gals["e2"], + is_deltasigma=True, sigma_c=sigma_c, geometry=geometry, ) @@ -561,7 +588,8 @@ def test_compute_galaxy_weights(): # true redshift + deltasigma sigma_c = cosmo.eval_sigma_crit(z_lens, z_src) weights = da.compute_galaxy_weights( - sigma_c, + is_deltasigma=True, + sigma_c=sigma_c, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, @@ -584,7 +612,8 @@ def test_compute_galaxy_weights(): pzpdf=pzpdf, ) weights = da.compute_galaxy_weights( - sigma_c_eff, + is_deltasigma=True, + sigma_c=sigma_c_eff, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, @@ -602,7 +631,8 @@ def test_compute_galaxy_weights(): pzbins = pzbin pzpdf = [multivariate_normal.pdf(pzbin, mean=z, cov=0.3) for z in z_src] weights = da.compute_galaxy_weights( - sigma_c_eff, + is_deltasigma=True, + sigma_c=sigma_c_eff, use_shape_noise=False, shape_component1=shape_component1, shape_component2=shape_component2, @@ -617,7 +647,8 @@ def test_compute_galaxy_weights(): # test with noise weights = da.compute_galaxy_weights( - sigma_c_eff, + is_deltasigma=True, + sigma_c=sigma_c_eff, use_shape_noise=True, shape_component1=shape_component1, shape_component2=shape_component2, @@ -632,6 +663,7 @@ def test_compute_galaxy_weights(): # test with is_deltasigma=False and geometric weights only weights = da.compute_galaxy_weights( + is_deltasigma=False, sigma_c=None, use_shape_noise=False, shape_component1=shape_component1, @@ -649,7 +681,8 @@ def test_compute_galaxy_weights(): assert_raises( ValueError, da.compute_galaxy_weights, - sigma_c_eff, + is_deltasigma=True, + sigma_c=sigma_c_eff, use_shape_noise=True, shape_component1=None, shape_component2=None, @@ -663,7 +696,8 @@ def test_compute_galaxy_weights(): assert_raises( ValueError, da.compute_galaxy_weights, - sigma_c_eff, + is_deltasigma=True, + sigma_c=sigma_c_eff, use_shape_noise=False, use_shape_error=True, shape_component1_err=None, diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index 61ac6fba5..35c865598 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -190,9 +190,7 @@ def test_integrity_of_probfuncs(): ra=161.3, dec=34.0, z=0.3, - galcat=GCData( - [ra_source, dec_source, z_srcs, id_source], names=("ra", "dec", "z", "id") - ), + galcat=GCData([ra_source, dec_source, z_srcs, id_source], names=("ra", "dec", "z", "id")), ) # true redshift cluster.compute_background_probability(use_pdz=False, p_background_name="p_bkg_true") From 36d28585c8789a963582fb24b4206fe01284b390 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 13 Jul 2023 15:32:26 +0200 Subject: [PATCH 29/34] update fmt --- tests/test_galaxycluster.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_galaxycluster.py b/tests/test_galaxycluster.py index 35c865598..04d73c6dc 100644 --- a/tests/test_galaxycluster.py +++ b/tests/test_galaxycluster.py @@ -292,9 +292,7 @@ def test_pzpdf_random_draw(): cluster.galcat.pzpdf_info.pop("zbins") cluster.galcat.remove_column("pzbins") - cluster.galcat["pzpdf"] = [ - multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_src - ] + cluster.galcat["pzpdf"] = [multivariate_normal.pdf(pzbins, mean=z, cov=0.3) for z in z_src] assert_raises(TypeError, cluster.draw_gal_z_from_pdz) # add pzbins back to galcat From 37df96ed5e4f2f6250d4e1d276778cc6f1246a81 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 13 Jul 2023 16:52:03 +0200 Subject: [PATCH 30/34] change args of _validate_is_deltasigma_sigma_c --- clmm/dataops/__init__.py | 8 ++++---- clmm/utils/validation.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 82b61b20e..00865b0d1 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -133,7 +133,7 @@ def compute_tangential_and_cross_components( names=("Ra", "Dec", "Shear1", "Shear2"), prefix="Tangential- and Cross- shape components sources", ) - _validate_is_deltasigma_sigma_c(locals()) + _validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c) elif np.iterable(ra_source): ra_source_, dec_source_, shear1_, shear2_ = ( np.array(col) for col in [ra_source, dec_source, shear1, shear2] @@ -248,8 +248,8 @@ def compute_galaxy_weights( Parameters ---------- is_deltasigma: bool - If `True`, the tangential and cross components returned are multiplied by Sigma_crit. - It requires `sigma_c` argument. Results in units of :math:`M_\odot\ Mpc^{-2}` + If `False`, weights are computed for shear, else weights are computed for + :math:`\Delta \Sigma`. sigma_c : None, array_like Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. Used only when is_deltasigma=True. @@ -292,7 +292,7 @@ def compute_galaxy_weights( names=("shape_component1", "shape_component2"), prefix="Shape components sources", ) - _validate_is_deltasigma_sigma_c(locals()) + _validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c) # computing w_ls_geo w_ls_geo = 1.0 diff --git a/clmm/utils/validation.py b/clmm/utils/validation.py index f08e2ad86..f4a322002 100644 --- a/clmm/utils/validation.py +++ b/clmm/utils/validation.py @@ -209,16 +209,18 @@ def _validate_dec(loc, dec_name, is_array): validate_argument(loc, dec_name, v_type, argmin=-90, eqmin=True, argmax=90, eqmax=True) -def _validate_is_deltasigma_sigma_c(loc): - """ "Validate the compatibility between is_deltasigma and sigma_c arguments. +def _validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c): + r""" "Validate the compatibility between is_deltasigma and sigma_c arguments. Parameters ---------- - loc: dict - Dictionary with all input arguments. Should be locals(). + is_deltasigma: bool + If `False`, values are computed for shear, else they are computed for :math:`\Delta \Sigma`. + sigma_c : None, array_like + Critical (effective) surface density in units of :math:`M_\odot\ Mpc^{-2}`. """ - if loc["is_deltasigma"] and loc["sigma_c"] is None: + if is_deltasigma and sigma_c is None: raise TypeError("sigma_c (=None) must be provided when is_deltasigma=True") - if not loc["is_deltasigma"] and loc["sigma_c"] is not None: - raise TypeError(f"sigma_c (={loc['sigma_c']}) be provided when is_deltasigma=False") + if not is_deltasigma and sigma_c is not None: + raise TypeError(f"sigma_c (={sigma_c}) be provided when is_deltasigma=False") From 33a7f9436d2c391854ad1f8d2076db54fc7eb197 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Thu, 13 Jul 2023 18:36:56 +0200 Subject: [PATCH 31/34] fix arg order --- clmm/dataops/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clmm/dataops/__init__.py b/clmm/dataops/__init__.py index 00865b0d1..33adb2dd9 100644 --- a/clmm/dataops/__init__.py +++ b/clmm/dataops/__init__.py @@ -205,14 +205,14 @@ def compute_background_probability( def compute_galaxy_weights( - is_deltasigma=False, - sigma_c=None, use_shape_noise=False, shape_component1=None, shape_component2=None, use_shape_error=False, shape_component1_err=None, shape_component2_err=None, + is_deltasigma=False, + sigma_c=None, validate_input=True, ): r"""Computes the individual lens-source pair weights From d631f4ec452e38da98393d1a141448403160fd0b Mon Sep 17 00:00:00 2001 From: m-aguena Date: Tue, 29 Aug 2023 11:33:21 +0200 Subject: [PATCH 32/34] fix err msg --- clmm/utils/validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clmm/utils/validation.py b/clmm/utils/validation.py index f4a322002..ed020d183 100644 --- a/clmm/utils/validation.py +++ b/clmm/utils/validation.py @@ -223,4 +223,4 @@ def _validate_is_deltasigma_sigma_c(is_deltasigma, sigma_c): if is_deltasigma and sigma_c is None: raise TypeError("sigma_c (=None) must be provided when is_deltasigma=True") if not is_deltasigma and sigma_c is not None: - raise TypeError(f"sigma_c (={sigma_c}) be provided when is_deltasigma=False") + raise TypeError(f"sigma_c (={sigma_c}) must be None when is_deltasigma=False") From 22d90d2e62f6ffb2658fe033f1df36cd80d5e579 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Tue, 29 Aug 2023 11:33:41 +0200 Subject: [PATCH 33/34] fix notebook --- examples/demo_compute_deltasigma_weights.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/demo_compute_deltasigma_weights.ipynb b/examples/demo_compute_deltasigma_weights.ipynb index 4d5b51110..d261446b4 100644 --- a/examples/demo_compute_deltasigma_weights.ipynb +++ b/examples/demo_compute_deltasigma_weights.ipynb @@ -175,6 +175,7 @@ "source": [ "w_ls_true = compute_galaxy_weights(\n", " sigma_c=sigma_c,\n", + " is_deltasigma=True,\n", " use_shape_noise=False,\n", ")" ] @@ -260,6 +261,7 @@ "source": [ "w_ls_photoz = compute_galaxy_weights(\n", " sigma_c=sigma_c_eff,\n", + " is_deltasigma=True,\n", " use_shape_noise=False,\n", ")" ] From 783efe949129f4721703b1c7b4807e0f472e4ff5 Mon Sep 17 00:00:00 2001 From: m-aguena Date: Mon, 16 Oct 2023 06:36:00 -0700 Subject: [PATCH 34/34] Update version to 1.10.0 --- clmm/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clmm/__init__.py b/clmm/__init__.py index 4071ee026..9689bbd54 100644 --- a/clmm/__init__.py +++ b/clmm/__init__.py @@ -26,4 +26,4 @@ ) from . import support -__version__ = "1.9.0" +__version__ = "1.10.0"