Skip to content

Commit

Permalink
Merge branch 'main' into issue/401/use_qp
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aguena committed Aug 9, 2024
2 parents db8d13d + e95f0e0 commit f89abcd
Show file tree
Hide file tree
Showing 46 changed files with 2,361 additions and 1,165 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/build_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,47 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v2
- name: Install prereq using conda
- uses: conda-incubator/setup-miniconda@v3
- name: Install prereq and NumCosmo using conda
run: |
echo "$CONDA/bin" >> $GITHUB_PATH
conda install -c conda-forge gobject-introspection pygobject
conda install -c conda-forge gobject-introspection pygobject numcosmo cmake swig setuptools_scm sphinx sphinx_rtd_theme nbconvert pandoc ipython
- name: Install prereq using pip
run: |
pip install -r requirements.txt
- name: Install the package
run: |
pip install .
- name: Install NumCosmo from conda-forge
run: |
conda install -c conda-forge numcosmo
# temporarily moved up due to libarchive issue - see PR 620
# - name: Install NumCosmo from conda-forge
# run: |
# conda install -c conda-forge numcosmo
- name: Install cluster_toolkit from source
run: |
git clone https://github.com/tmcclintock/cluster_toolkit.git
cd cluster_toolkit
pip install .
- name: Install CCL from source
run: |
conda install -c conda-forge cmake swig --override-channels
# temporarily moved up due to libarchive issue - see PR 620
#conda install -c conda-forge cmake swig setuptools_scm
git clone https://github.com/LSSTDESC/CCL
cd CCL
git checkout v3.0.0
pip install .
pip install --no-use-pep517 .
- 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
pytest tests/ --ignore=cluster_toolkit/tests --cov=clmm/
env:
DISPLAY: test
- name: Install Sphinx prereq
run: |
conda install -c conda-forge sphinx sphinx_rtd_theme nbconvert pandoc ipython ipython_genutils
# temporarily moved up due to libarchive issue - see PR 620
# - name: Install Sphinx prereq
# run: |
# conda install -c conda-forge sphinx sphinx_rtd_theme nbconvert pandoc ipython ipython_genutils
- name: Run the docs
run: |
make -C docs/ html
Expand Down
10 changes: 5 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
## Basic procedure <a name="basic_install"></a>

Here we provide a quick guide for a basic instalation, this will install all the packages in your current environment.
To create a specific conda environment for CLMM, we recommend you to check the begining of section
To create a specific conda environment for CLMM, we recommend you to check the begining of section
[Access to the proper environment on cori.nersc.gov](#access_to_the_proper_environment_on_cori).

### Theory backend installation
First, choose and install a theory backend for CLMM.
This can be CCL (versions between 2.7.1.dev10+gf81b59a4 and 3),
NumCosmo (v0.15 or later),
NumCosmo (v0.19 or later),
or cluster_toolkit and they are installable as follows.

To install CCL as the theory/cosmology backend, run
Expand Down Expand Up @@ -60,7 +60,7 @@ Now, you can install CLMM and its dependencies as
pip install pytest sphinx sphinx_rtd_theme
pip install jupyter # need to have jupyter notebook tied to this environment, you can then see the environment in jupyter.nersc.gov
git clone https://github.com/LSSTDESC/CLMM.git # If you'd like to contribute but don't have edit permissions to the CLMM repo, see below how to fork the repo instead.
cd CLMM
cd CLMM
python setup.py install # build from source
```

Expand All @@ -72,9 +72,9 @@ If you have access to NERSC, this will likely be the easiest to make sure you ha
module load python # Also loads anaconda
conda create --name clmmenv # Create an anaconda environment for clmm
source activate clmmenv # switch to your newly created environment
conda install pip # need pip to install everything else necessary for clmm
conda install pip # need pip to install everything else necessary for clmm
conda install ipython # need to have the ipython tied to this environment
conda install -c conda-forge firefox # Need a browser to view jupyter notebooks
conda install -c conda-forge firefox # Need a browser to view jupyter notebooks
```

Note, for regular contributions and use, we recommend adding `module load python` to your `~/.bashrc` so you have anaconda installed every time you log in. You will subseqeuntly also want to be in the correct environment whenever working with `clmm`, which means running `source activate clmmenv` at the start of each session.
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# CLMM
[![Build and Check](https://github.com/LSSTDESC/CLMM/workflows/Build%20and%20Check/badge.svg)](https://github.com/LSSTDESC/CLMM/actions?query=workflow%3A%22Build+and+Check%22)
[![Coverage Status](https://coveralls.io/repos/github/LSSTDESC/CLMM/badge.svg?branch=main)](https://coveralls.io/github/LSSTDESC/CLMM?branch=main)
Expand All @@ -23,8 +22,8 @@ link to this repository: https://github.com/LSSTDESC/CLMM. Please follow the gui
CLMM requires Python version 3.8 or later. CLMM has the following dependencies:

- [NumPy](https://www.numpy.org/) (v1.17 or later)
- [SciPy](https://scipy.org/) (v1.3 or later)
- [Astropy](https://www.astropy.org/) (v4.0 or later for units and cosmology dependence)
- [SciPy](https://scipy.org/) (v1.6 or later)
- [Astropy](https://www.astropy.org/) (v4.0 or later for units and cosmology dependence)
(Please avoid Astropy v5.0 since there is bug breaking CCL backend. It has been fixed in Astropy v5.0.1.)
- [Matplotlib](https://matplotlib.org/) (for plotting and going through tutorials)

Expand All @@ -36,7 +35,7 @@ For the theoretical predictions of the signal, CLMM relies on existing libraries

- [cluster-toolkit](https://cluster-toolkit.readthedocs.io/en/latest/)
- [CCL](https://ccl.readthedocs.io/en/latest/) (versions between 2.7.1.dev10+gf81b59a4 and 3)
- [NumCosmo](https://numcosmo.github.io/) (v0.15 or later)
- [NumCosmo](https://numcosmo.github.io/) (v0.19 or later)


(See the [INSTALL documentation](INSTALL.md) for more detailed installation instructions.)
Expand Down Expand Up @@ -91,8 +90,8 @@ non-DESC project concept and progress to be presented to the working group,
so working group members can help co-identify tools and/or ongoing development
that might mutually benefit your non-DESC project and ongoing DESC projects.

**External Projects by Non-DESC members**: If you are not from the DESC
community, you are also welcome to contact CLMM Topical Team leads to introduce
**External Projects by Non-DESC members**: If you are not from the DESC
community, you are also welcome to contact CLMM Topical Team leads to introduce
your project and share feedback.


Expand All @@ -110,6 +109,7 @@ the `CCL` publication be cited. See details
The `Cluster Toolkit` documentation can be found
[here](https://cluster-toolkit.readthedocs.io/en/latest/#).

The data for the notebook test_coordinate.ipynb is available at https://www.dropbox.com/scl/fo/dwsccslr5iwb7lnkf8jvx/AJkjgFeemUEHpHaZaHHqpAg?rlkey=efbtsr15mdrs3y6xsm7l48o0r&st=xb58ap0g&dl=0

# Contributing to CLMM <a name="contributing"></a>

Expand All @@ -123,7 +123,7 @@ issue](https://github.com/LSSTDESC/CLMM/issues).

The current leads of the LSST DESC CLMM Topical Team are Michel Aguena
(m-aguena, [email protected]) and Marina Ricci (mricci,
marina.ricci@lmu.de)
marina.ricci@apc.in2p3.fr)


# Acknowledgements <a name="acknowledgements"></a>
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.10.0"
__version__ = "1.13.0"
19 changes: 14 additions & 5 deletions clmm/clusterensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .gcdata import GCData
from .dataops import make_stacked_radial_profile
from .utils import DiffArray


class ClusterEnsemble:
Expand All @@ -27,7 +28,7 @@ class ClusterEnsemble:
* "tan_sc" : tangential component computed with sample covariance
* "cross_sc" : cross component computed with sample covariance
* "tan_jk" : tangential component computed with bootstrap
* "tan_bs" : tangential component computed with bootstrap
* "cross_bs" : cross component computed with bootstrap
* "tan_jk" : tangential component computed with jackknife
* "cross_jk" : cross component computed with jackknife
Expand All @@ -46,7 +47,7 @@ def __init__(self, unique_id, gc_list=None, **kwargs):
else:
raise TypeError(f"unique_id incorrect type: {type(unique_id)}")
self.unique_id = unique_id
self.data = GCData(meta={"bin_units": None})
self.data = GCData(meta={"bin_units": None, "radius_min": None, "radius_max": None})
if gc_list is not None:
self._add_values(gc_list, **kwargs)
self.stacked_data = None
Expand Down Expand Up @@ -198,6 +199,9 @@ def add_individual_radial_profile(
"""
cl_bin_units = profile_table.meta.get("bin_units", None)
self.data.update_info_ext_valid("bin_units", self.data, cl_bin_units, overwrite=False)
for col in ("radius_min", "radius_max"):
value = DiffArray(profile_table[col])
self.data.update_info_ext_valid(col, self.data, value, overwrite=False)

cl_cosmo = profile_table.meta.get("cosmo", None)
self.data.update_info_ext_valid("cosmo", self.data, cl_cosmo, overwrite=False)
Expand Down Expand Up @@ -248,9 +252,14 @@ def make_stacked_radial_profile(self, tan_component="gt", cross_component="gx",
[self.data[tan_component], self.data[cross_component]],
)
self.stacked_data = GCData(
[radius, *components],
meta=self.data.meta,
names=("radius", tan_component, cross_component),
[
self.data.meta["radius_min"].value,
self.data.meta["radius_max"].value,
radius,
*components,
],
meta={k: v for k, v in self.data.meta.items() if k not in ("radius_min", "radius_max")},
names=("radius_min", "radius_max", "radius", tan_component, cross_component),
)

def compute_sample_covariance(self, tan_component="gt", cross_component="gx"):
Expand Down
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))
8 changes: 7 additions & 1 deletion clmm/cosmology/numcosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class NumCosmoCosmology(CLMMCosmology):

def __init__(self, dist=None, dist_zmax=15.0, **kwargs):
self.dist = None
self.smd = None

super().__init__(**kwargs)

Expand All @@ -54,6 +55,7 @@ def __init__(self, dist=None, dist_zmax=15.0, **kwargs):
self.smd = Nc.WLSurfaceMassDensity.new(self.dist)
self.smd.prepare_if_needed(self.be_cosmo)


def _init_from_cosmo(self, be_cosmo):
assert isinstance(be_cosmo, Nc.HICosmo)
assert isinstance(be_cosmo, Nc.HICosmoDECpl)
Expand All @@ -63,7 +65,7 @@ def _init_from_cosmo(self, be_cosmo):

def _init_from_params(self, H0, Omega_b0, Omega_dm0, Omega_k0):
# pylint: disable=arguments-differ
self.be_cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDECpl{'massnu-length':<1>}")
self.be_cosmo = Nc.HICosmoDECpl(massnu_length=1)
self.be_cosmo.omega_x2omega_k()
self.be_cosmo.param_set_by_name("w0", -1.0)
self.be_cosmo.param_set_by_name("w1", 0.0)
Expand Down Expand Up @@ -136,6 +138,10 @@ def _update_vec_funcs(self):
self._eval_sigma_crit_core = np.vectorize(
lambda z_len, z_src: (self.smd.sigma_critical(self.be_cosmo, z_src, z_len, z_len))
)
if self.dist is not None:
self.dist.prepare_if_needed(self.be_cosmo)
if self.smd is not None:
self.smd.prepare_if_needed(self.be_cosmo)

def _get_rho_c(self, z):
return (
Expand Down
Loading

0 comments on commit f89abcd

Please sign in to comment.