Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/524/weights in beta #532

Merged
merged 45 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6589f93
Merged into main
eduardojsbarroso Jul 21, 2022
b36ed4b
Added weights option
eduardojsbarroso Jul 21, 2022
6af1a3e
Merge remote-tracking branch 'origin' into issue/524/weights_in_beta
eduardojsbarroso Mar 1, 2023
2fd4ad8
Fixed old code to match new features
eduardojsbarroso Mar 1, 2023
23a0c58
Deleting Unwanted commited files
eduardojsbarroso Mar 1, 2023
8605658
Implemented Weights option
eduardojsbarroso Mar 2, 2023
5766cfa
Implemented resquested changes
eduardojsbarroso Mar 20, 2023
37a3e76
Finished implementation of functions
eduardojsbarroso May 5, 2023
724faec
Merge branch 'main' into issue/524/weights_in_beta
eduardojsbarroso May 5, 2023
b990d0e
Fixed failling tests
eduardojsbarroso May 9, 2023
6335ed9
rm compute_beta from theory.parent
m-aguena May 9, 2023
744a8ae
revert beta functions
m-aguena May 9, 2023
88765f3
improve compute_beta
m-aguena May 9, 2023
ac4d959
fix merge conflicts
m-aguena May 16, 2023
d1aa463
update changes
m-aguena May 16, 2023
37d41fb
rm unused instances of integ_kwargs
m-aguena May 16, 2023
76a567a
update tests
m-aguena May 16, 2023
9c1ea82
pylint beta_lens.py
m-aguena May 16, 2023
c0b0f7a
restore examples/demo_boost_factors.ipynb
m-aguena May 16, 2023
e43bb6e
update tests
m-aguena May 17, 2023
f2585e4
rm unnecessary checks
m-aguena May 17, 2023
a030408
move all validation of theory cases to _validate_z_src
m-aguena May 17, 2023
e07a226
create _validate_approx_z_src_info func
m-aguena May 17, 2023
4ee5ef8
fix merge conflicts
m-aguena May 26, 2023
0a88ad2
Updating notebook
eduardojsbarroso Jun 26, 2023
34dd89f
Finished updating notebook
eduardojsbarroso Jun 26, 2023
01a0e90
Added description in notebook
eduardojsbarroso Jun 27, 2023
835fdcc
make compute_beta more efficient and fix shape_weights=None in comput…
m-aguena Jul 12, 2023
ef11681
improve compute_beta_s*_mean_from_weights
m-aguena Jul 12, 2023
d04f6e3
add _eval_da, _eval_da_z1z2, _get_z_from_a, _get_a_from_z to cosm
m-aguena Jul 12, 2023
00d6e02
reorder funcs in cosmo parent
m-aguena Jul 12, 2023
4fc845e
update tests
m-aguena Jul 12, 2023
a500d61
add compute_beta_s_mean_from_weights to demo_theory_functionality_dif…
m-aguena Jul 12, 2023
6faa95e
reorder funcs in cosmo parent
m-aguena Jul 12, 2023
2416457
add fix for pylint duplicate-code error bug
m-aguena Jul 12, 2023
82ca497
add pylint skip
m-aguena Jul 12, 2023
2dd7b83
fix linebreaks
m-aguena Jul 12, 2023
5e14ff2
fix merge conflicts
m-aguena Oct 18, 2023
1cc32c2
fix new use in examples/mass_fitting/Example3_Fit_Halo_Mass_to_Shear_…
m-aguena Nov 10, 2023
1b29e0b
fix new use in examples/demo_theory_functionality.ipynb
m-aguena Nov 16, 2023
5e8af97
fix new use in examples/demo_theory_functionality_oo.ipynb
m-aguena Nov 16, 2023
0b41b60
Merge branch 'main' into issue/524/weights_in_beta
m-aguena Feb 21, 2024
9169407
Merge branch 'main' into issue/524/weights_in_beta
m-aguena Feb 23, 2024
024139c
Update version to 1.12.0
m-aguena Mar 28, 2024
b044dd7
add fix to skip pylint for astropy.units (fails in astropy 6)
m-aguena Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Analysing the code with pylint
run: |
pip install pylint
pylint clmm
pylint clmm --ignored-classes=astropy.units
- name: Run the unit tests
run: |
pip install pytest pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion clmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
)
from . import support

__version__ = "1.11.1"
__version__ = "1.12.0"
20 changes: 10 additions & 10 deletions clmm/cosmology/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@ def _get_param(self, key):
return value

def _get_Omega_m(self, z):
a = self.get_a_from_z(z)
a = self._get_a_from_z(z)
return ccl.omega_x(self.be_cosmo, a, "matter")

def _get_E2(self, z):
a = self.get_a_from_z(z)
a = self._get_a_from_z(z)
return (ccl.h_over_h0(self.be_cosmo, a)) ** 2

def _get_E2Omega_m(self, z):
a = self.get_a_from_z(z)
a = self._get_a_from_z(z)
return ccl.omega_x(self.be_cosmo, a, "matter") * (ccl.h_over_h0(self.be_cosmo, a)) ** 2

def _get_rho_m(self, z):
# total matter density in physical units [Msun/Mpc3]
a = self.get_a_from_z(z)
a = self._get_a_from_z(z)
return ccl.rho_x(self.be_cosmo, a, "matter", is_comoving=False)

def _get_rho_c(self, z):
a = self.get_a_from_z(z)
a = self._get_a_from_z(z)
return ccl.rho_x(self.be_cosmo, a, "critical", is_comoving=False)

def _eval_da_z1z2_core(self, z1, z2):
a1 = np.atleast_1d(self.get_a_from_z(z1))
a2 = np.atleast_1d(self.get_a_from_z(z2))
a1 = np.atleast_1d(self._get_a_from_z(z1))
a2 = np.atleast_1d(self._get_a_from_z(z2))
if len(a1) == 1 and len(a2) != 1:
a1 = np.full_like(a2, a1)
elif len(a2) == 1 and len(a1) != 1:
Expand All @@ -110,10 +110,10 @@ def _eval_da_z1z2_core(self, z1, z2):
return res

def _eval_sigma_crit_core(self, z_len, z_src):
a_len = self.get_a_from_z(z_len)
a_src = self.get_a_from_z(z_src)
a_len = self._get_a_from_z(z_len)
a_src = self._get_a_from_z(z_src)

return self.be_cosmo.sigma_critical(a_lens=a_len, a_source=a_src) * self.cor_factor

def _eval_linear_matter_powerspectrum(self, k_vals, redshift):
return ccl.linear_matter_power(self.be_cosmo, k_vals, self.get_a_from_z(redshift))
return ccl.linear_matter_power(self.be_cosmo, k_vals, self._get_a_from_z(redshift))
174 changes: 87 additions & 87 deletions clmm/cosmology/parent_class.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""@file parent_class.py
CLMMCosmology abstract class
"""
# CLMM Cosmology object abstract superclass
import numpy as np
Expand Down Expand Up @@ -41,11 +42,91 @@ def __setitem__(self, key, val):
else:
raise TypeError(f"key input must be str, not {type(key)}")

# 1. Functions to be implemented by children classes

def _init_from_cosmo(self, be_cosmo):
raise NotImplementedError

def _init_from_params(self, **kwargs):
raise NotImplementedError

def _set_param(self, key, value):
raise NotImplementedError

def _get_param(self, key):
raise NotImplementedError

def _get_Omega_m(self, z):
raise NotImplementedError

def _get_E2(self, z):
raise NotImplementedError

def _get_E2Omega_m(self, z):
raise NotImplementedError

def _get_rho_c(self, z):
raise NotImplementedError

def _eval_da_z1z2_core(self, z1, z2):
raise NotImplementedError

def _eval_sigma_crit_core(self, z_len, z_src):
raise NotImplementedError

def _eval_linear_matter_powerspectrum(self, k_vals, redshift):
raise NotImplementedError

# 2. Functions that can be used by all subclasses

def _get_rho_m(self, z):
rhocrit_cd2018 = (3.0e16 * const.PC_TO_METER.value) / (
8.0 * np.pi * const.GNEWT.value * const.SOLAR_MASS.value
)
return rhocrit_cd2018 * (z + 1) ** 3 * self["Omega_m0"] * self["h"] ** 2

def _eval_da_z1z2(self, z1, z2):
warning_msg = "\nSome values of z2 are lower than z1." + "\nda = np.nan for those."
return compute_for_good_redshifts(
self._eval_da_z1z2_core, z1, z2, np.nan, warning_message=warning_msg
)

def _eval_da(self, z):
return self._eval_da_z1z2(0.0, z)

def _get_a_from_z(self, z):
z = np.array(z)
return 1.0 / (1.0 + z)

def _get_z_from_a(self, a):
a = np.array(a)
return (1.0 / a) - 1.0

def _eval_sigma_crit(self, z_len, z_src):
warning_msg = (
"\nSome source redshifts are lower than the cluster redshift."
+ "\nSigma_crit = np.inf for those galaxies."
)
return compute_for_good_redshifts(
self._eval_sigma_crit_core,
z_len,
z_src,
np.inf,
z1_arg_name="z_len",
z2_arg_name="z_src",
warning_message=warning_msg,
)

# 3. Wrapper functions for input validation

def get_desc(self):
"""
To be filled in child classes
Returns the Cosmology description.
"""
raise NotImplementedError
return (
f"{type(self).__name__}(H0={self['H0']}, Omega_dm0={self['Omega_dm0']}, "
f"Omega_b0={self['Omega_b0']}, Omega_k0={self['Omega_k0']})"
)

def init_from_params(self, H0=67.66, Omega_b0=0.049, Omega_dm0=0.262, Omega_k0=0.0):
"""Set the cosmology from parameters
Expand All @@ -68,33 +149,6 @@ def init_from_params(self, H0=67.66, Omega_b0=0.049, Omega_dm0=0.262, Omega_k0=0
validate_argument(locals(), "Omega_k0", float, argmin=0, eqmin=True)
self._init_from_params(H0=H0, Omega_b0=Omega_b0, Omega_dm0=Omega_dm0, Omega_k0=Omega_k0)

def _init_from_params(self, **kwargs):
"""
To be filled in child classes
"""
raise NotImplementedError

def _set_param(self, key, value):
"""
To be filled in child classes
"""
raise NotImplementedError

def _get_param(self, key):
"""
To be filled in child classes
"""
raise NotImplementedError

def get_desc(self):
"""
Returns the Cosmology description.
"""
return (
f"{type(self).__name__}(H0={self['H0']}, Omega_dm0={self['Omega_dm0']}, "
f"Omega_b0={self['Omega_b0']}, Omega_k0={self['Omega_k0']})"
)

def set_be_cosmo(self, be_cosmo=None, H0=67.66, Omega_b0=0.049, Omega_dm0=0.262, Omega_k0=0.0):
"""Set the cosmology

Expand Down Expand Up @@ -134,9 +188,6 @@ def get_Omega_m(self, z):
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self._get_Omega_m(z=z)

def _get_Omega_m(self, z):
raise NotImplementedError

def get_E2(self, z):
r"""Gets the value of the hubble parameter (normalized at 0)

Expand All @@ -159,9 +210,6 @@ def get_E2(self, z):
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self._get_E2(z=z)

def _get_E2(self, z):
raise NotImplementedError

def get_E2Omega_m(self, z):
r"""Gets the value of the dimensionless matter density times the Hubble parameter squared
(normalized at 0)
Expand All @@ -187,9 +235,6 @@ def get_E2Omega_m(self, z):
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self._get_E2Omega_m(z=z)

def _get_E2Omega_m(self, z):
raise NotImplementedError

def get_rho_m(self, z):
r"""Gets physical matter density at a given redshift.

Expand All @@ -207,12 +252,6 @@ def get_rho_m(self, z):
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self._get_rho_m(z=z)

def _get_rho_m(self, z):
rhocrit_cd2018 = (3.0e16 * const.PC_TO_METER.value) / (
8.0 * np.pi * const.GNEWT.value * const.SOLAR_MASS.value
)
return rhocrit_cd2018 * (z + 1) ** 3 * self["Omega_m0"] * self["h"] ** 2

def get_rho_c(self, z):
r"""Gets physical critical density at a given redshift.

Expand All @@ -230,9 +269,6 @@ def get_rho_c(self, z):
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self._get_rho_c(z=z)

def _get_rho_c(self, z):
raise NotImplementedError

def eval_da_z1z2(self, z1, z2):
r"""Computes the angular diameter distance between z1 and z2

Expand Down Expand Up @@ -260,15 +296,6 @@ def eval_da_z1z2(self, z1, z2):
validate_argument(locals(), "z2", "float_array", argmin=0, eqmin=True)
return self._eval_da_z1z2(z1=z1, z2=z2)

def _eval_da_z1z2(self, z1, z2):
warning_msg = "\nSome values of z2 are lower than z1." + "\nda = np.nan for those."
return compute_for_good_redshifts(
self._eval_da_z1z2_core, z1, z2, np.nan, warning_message=warning_msg
)

def _eval_da_z1z2_core(self, z1, z2):
raise NotImplementedError

def eval_da(self, z):
r"""Computes the angular diameter distance between 0.0 and z

Expand All @@ -284,14 +311,10 @@ def eval_da(self, z):
-------
float, numpy.ndarray
Angular diameter distance in units :math:`M\!pc`

Notes
-----
Describe the vectorization.
"""
if self.validate_input:
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
return self.eval_da_z1z2(0.0, z)
return self._eval_da(z)

def eval_da_a1a2(self, a1, a2=1.0):
r"""This is a function to calculate the angular diameter distance
Expand Down Expand Up @@ -340,7 +363,7 @@ def eval_da_a1a2(self, a1, a2=1.0):
)
z1 = self.get_z_from_a(a2)
z2 = self.get_z_from_a(a1)
return self.eval_da_z1z2(z1, z2)
return self._eval_da_z1z2(z1, z2)

def get_a_from_z(self, z):
"""Convert redshift to scale factor
Expand All @@ -357,8 +380,7 @@ def get_a_from_z(self, z):
"""
if self.validate_input:
validate_argument(locals(), "z", "float_array", argmin=0, eqmin=True)
z = np.array(z)
return 1.0 / (1.0 + z)
return self._get_a_from_z(z)

def get_z_from_a(self, a):
"""Convert scale factor to redshift
Expand All @@ -377,8 +399,7 @@ def get_z_from_a(self, a):
validate_argument(
locals(), "a", "float_array", argmin=0, eqmin=True, argmax=1, eqmax=True
)
a = np.array(a)
return (1.0 / a) - 1.0
return self._get_z_from_a(a)

def rad2mpc(self, dist1, redshift):
r"""Convert between radians and Mpc using the small angle approximation
Expand Down Expand Up @@ -446,24 +467,6 @@ def eval_sigma_crit(self, z_len, z_src):
validate_argument(locals(), "z_src", "float_array", argmin=0, eqmin=True)
return self._eval_sigma_crit(z_len=z_len, z_src=z_src)

def _eval_sigma_crit(self, z_len, z_src):
warning_msg = (
"\nSome source redshifts are lower than the cluster redshift."
+ "\nSigma_crit = np.inf for those galaxies."
)
return compute_for_good_redshifts(
self._eval_sigma_crit_core,
z_len,
z_src,
np.inf,
z1_arg_name="z_len",
z2_arg_name="z_src",
warning_message=warning_msg,
)

def _eval_sigma_crit_core(self, z_len, z_src):
raise NotImplementedError

def eval_linear_matter_powerspectrum(self, k_vals, redshift):
r"""Computes the linear matter power spectrum

Expand All @@ -483,6 +486,3 @@ def eval_linear_matter_powerspectrum(self, k_vals, redshift):
validate_argument(locals(), "k_vals", "float_array", argmin=0)
validate_argument(locals(), "redshift", float, argmin=0, eqmin=True)
return self._eval_linear_matter_powerspectrum(k_vals, redshift)

def _eval_linear_matter_powerspectrum(self, k_vals, redshift):
raise NotImplementedError
Loading
Loading