-
Notifications
You must be signed in to change notification settings - Fork 2
gh-268: including CMB lensing #422
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
42869e4
Initial CMB lensing implementation
raphkou 2fda9a7
Merge remote-tracking branch 'origin/main' into feature/cmb-lensing
raphkou a1b65d1
Renamed cmb_lensing.py to cmb.py
raphkou 5f3bd5b
Fixing style
raphkou f71764f
Adding z_star among required tests background attributes. Adding consβ¦
raphkou bf6dc32
minor
raphkou a998f5a
Merge remote-tracking branch 'origin/main' into feature/cmb-lensing
raphkou 2335a33
Adding CMB lensing unit tests
raphkou 5cfb4f5
Fixing style and improving cmb tests
raphkou b38a5c6
Merge remote-tracking branch 'origin/main' into feature/cmb-lensing
raphkou 7b52c1b
Forcing symmetry in cross-correlation calls
raphkou c5859f2
Merge branch 'main' of https://github.com/cloe-org/cloelib into featuβ¦
gcanasherrera c921952
Updating test_cmb.py to be compatible with numpy versions > 2
raphkou 6c8282b
Updating documentation
raphkou d1155c1
Merge remote-tracking branch 'origin/main' into feature/cmb-lensing
raphkou 481c5a8
Updating test_cmb.py
raphkou cf3f83a
Fixing style
raphkou f93a6b6
Further fixes to test_cmb.py
raphkou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| Module implementing CMB lensing. | ||
|
|
||
| This class is compatible with the Tracer protocol. | ||
| """ | ||
|
|
||
| # cloelib imports | ||
| from cloelib.auxiliary.units import SPEED_OF_LIGHT | ||
| from cloelib.cosmology.cosmology import Perturbations | ||
|
|
||
| # General imports | ||
| import jax.numpy as np # type: ignore | ||
|
|
||
|
|
||
| # UNITS | ||
| c_0 = SPEED_OF_LIGHT / 1000 # Convert to km/s | ||
|
|
||
|
|
||
| class CMBLensingTracer: | ||
| """Class for the kernel for CMB Lensing convergence.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| perturbations: Perturbations, | ||
| z: np.ndarray, | ||
| ): | ||
| r""" | ||
| Initialize the class instance. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| perturbations : object | ||
| An object from NonLinearPerturbations class | ||
| z : np.ndarray | ||
| A 1-dimensional array used to perform line-of-sight integration. | ||
| """ | ||
| if 0.0 in z: | ||
| raise ValueError( | ||
| "One of the z array elements is equal to zero, breaking Limber integration." | ||
| ) | ||
| self.perturbations = perturbations | ||
| self.background = self.perturbations.background | ||
| self.z = z | ||
| self.n_z_bins = 1 | ||
| # This is to add the necessary prefactor to shear | ||
| self.prefact_toggle = 0 | ||
|
|
||
| def get_window(self, z): | ||
| r"""Compute the Window. | ||
|
|
||
| Computes CMB lensing window function | ||
|
|
||
| .. math:: | ||
| W^{\kappa}(\ell, z, k) = | ||
| \frac{3}{2}\left ( \frac{H_0}{c}\right )^2 | ||
| \Omega_{{\rm m},0} (1 + z) | ||
| f_K\left[\tilde{r}(z)\right] | ||
| \frac{f_K\left[\tilde{r}(z_*) - \tilde{r}(z)\right]} | ||
| {f_K\left[\tilde{r}(z_*)\right]}\\ | ||
|
|
||
| Parameters | ||
| ---------- | ||
| z: float | ||
| Redshift at which window kernel is being evaluated | ||
|
|
||
| Returns | ||
| ------- | ||
| window: np.ndarray | ||
| """ | ||
| Omega_m0 = self.background.Omega_m(0.0) | ||
| factor = ( | ||
| 3 | ||
| / 2 | ||
|
arthurmloureiro marked this conversation as resolved.
|
||
| * (self.background.H0 / c_0) ** 2 | ||
| * Omega_m0 | ||
| * (1 + z) | ||
| * self.background.comoving_distance(z) | ||
| ) | ||
| rz = self.background.comoving_distance(z) | ||
| z_star = self.background.z_star | ||
| rz_star = self.background.comoving_distance(z_star) | ||
| efficiency = 1 - rz / rz_star | ||
| result = factor * efficiency | ||
| return np.expand_dims(result, 0) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| """ | ||
| Unit tests to verify cmb tracers run correctly. | ||
| """ | ||
|
|
||
| import pytest | ||
| import numpy as np | ||
|
|
||
| from cloelib.cosmology.camb_cosmology import ( | ||
| CAMBBackground, | ||
| CAMBNonLinearPerturbations, | ||
| ) | ||
| from cloelib.observables.cmb import CMBLensingTracer | ||
| from cloelib.observables.photo import ShearTracer, PositionsTracer | ||
| from cloelib.summary_statistics.angular_two_point import AngularTwoPoint | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def camb_cmb_setup(): | ||
| """Create CAMB perturbations and position/shear tracers.""" | ||
| # Create background (using same params as test_camb_cosmology.py) | ||
| H0 = 67.7 | ||
| h = H0 / 100.0 | ||
| omch2 = 0.12 | ||
| Omega_cdm0 = omch2 / h**2 | ||
| ombh2 = 0.022 | ||
| Omega_b0 = ombh2 / h**2 | ||
|
|
||
| background = CAMBBackground( | ||
| H0=H0, | ||
| Omega_b0=Omega_b0, | ||
| Omega_cdm0=Omega_cdm0, | ||
| Omega_k0=0.0, | ||
| As=2e-9, | ||
| ns=0.96, | ||
| mnu=0.06, | ||
| w0=-1.0, | ||
| wa=0.0, | ||
| gamma_MG=0.0, | ||
| N_mnu=1, | ||
| ) | ||
|
|
||
| z_auto = np.linspace(0.01, 1100.0, 100) | ||
| z_cross = np.linspace(0.2, 2.0, 40) | ||
| perturbations = CAMBNonLinearPerturbations(background, z_auto) | ||
| n_z_bins = 1 | ||
| dndz = np.ones((n_z_bins, len(z_cross))) | ||
| dndz /= np.trapz(dndz, z_cross, axis=1)[:, None] | ||
| return perturbations, z_auto, z_cross, dndz | ||
|
|
||
|
|
||
| def test_cmb_lensing_window_cl(camb_cmb_setup): | ||
| """ | ||
| Test that cmb lensing window function auto and cross power spectra can be computed without error. | ||
|
|
||
| It further verifies that: | ||
| 1. CMB lensing window function has the expected shape. | ||
| 2. CMB lensing power spectrum and cross-correlations have the expected shapes. | ||
| """ | ||
| perturbations, z_auto, z_cross, dndz = camb_cmb_setup | ||
|
|
||
| # Create nuisance parameters | ||
| nuisance_pos = {"b1_photo_bin1": 1.0, "dz_pos_1": 0.0, "magnification_bias_1": 0.0} | ||
| nuisance_shear = { | ||
| "AIA": 0.0, | ||
| "CIA": 0.0, | ||
| "EtaIA": 0.0, | ||
| "multiplicative_bias_1": 0.0, | ||
| "dz_shear_1": 0.0, | ||
| } | ||
|
|
||
| # Create CMB lensing tracers | ||
| cmblens_cross = CMBLensingTracer(perturbations=perturbations, z=z_cross) | ||
| cmblens_auto = CMBLensingTracer(perturbations=perturbations, z=z_auto) | ||
|
|
||
| window_cross = cmblens_cross.get_window(z_cross) | ||
| window_auto = cmblens_auto.get_window(z_auto) | ||
|
|
||
| # Check that the window functions have the expected shape | ||
| assert window_cross.shape == (1, len(z_cross)) | ||
| assert window_auto.shape == (1, len(z_auto)) | ||
|
|
||
| # Create position tracer | ||
| pos_tracer = PositionsTracer( | ||
| perturbations=perturbations, | ||
| dndz=dndz, | ||
| z=z_cross, | ||
| galaxy_bias_model="per_bin", | ||
| nuisance_params=nuisance_pos, | ||
| ) | ||
|
|
||
| # Create shear tracer | ||
| shear_tracer = ShearTracer( | ||
| perturbations=perturbations, | ||
| dndz=dndz, | ||
| z=z_cross, | ||
| nuisance_params=nuisance_shear, | ||
| ) | ||
|
|
||
| nl = 10 | ||
| ells = np.logspace(1.0, np.log10(100), nl) | ||
|
|
||
| twopoint_kpos = AngularTwoPoint(cmblens_cross, pos_tracer) | ||
| twopoint_kshe = AngularTwoPoint(cmblens_cross, shear_tracer) | ||
| twopoint_kk = AngularTwoPoint(cmblens_auto, cmblens_auto) | ||
|
|
||
| cells = { | ||
| **twopoint_kpos.get_Cl(ells, 0, perturbations.k), | ||
| **twopoint_kshe.get_Cl(ells, 0, perturbations.k), | ||
| **twopoint_kk.get_Cl(ells, 0, perturbations.k), | ||
| } | ||
|
|
||
| # Check that cells has the right number of elements and right keys | ||
| assert len(cells.keys()) == 3 | ||
| assert ("CMBL", "POS", 1, 1) in cells.keys() | ||
| assert ("CMBL", "SHE", 1, 1) in cells.keys() | ||
| assert ("CMBL", "CMBL", 1, 1) in cells.keys() | ||
| assert cells[("CMBL", "POS", 1, 1)].shape == (nl,) | ||
| assert cells[("CMBL", "SHE", 1, 1)].shape == (2, nl) | ||
| assert cells[("CMBL", "CMBL", 1, 1)].shape == (nl,) | ||
|
|
||
| # We also check everything works well if we reverse the order of the probes | ||
| twopoint_posk = AngularTwoPoint(pos_tracer, cmblens_cross) | ||
| twopoint_shek = AngularTwoPoint(shear_tracer, cmblens_cross) | ||
| cells_reverse = { | ||
| **twopoint_posk.get_Cl(ells, 0, perturbations.k), | ||
| **twopoint_shek.get_Cl(ells, 0, perturbations.k), | ||
| } | ||
|
|
||
| assert len(cells_reverse.keys()) == 2 | ||
| assert ("CMBL", "POS", 1, 1) in cells_reverse.keys() | ||
| assert ("CMBL", "SHE", 1, 1) in cells_reverse.keys() | ||
| assert cells_reverse[("CMBL", "POS", 1, 1)].shape == (nl,) | ||
| assert cells_reverse[("CMBL", "SHE", 1, 1)].shape == (2, nl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.