-
Notifications
You must be signed in to change notification settings - Fork 12
adding the DESI BAO likelihood #50
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
939c030
adding the DESI BAO likelihood
martin-millon 91653d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7028923
adding tests + normalisation correction
martin-millon 58d81cb
Merge branch 'BAO-martin' of https://github.com/martin-millon/hierArc…
martin-millon 9cfbaae
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 90cfe79
coverage improvement
martin-millon 1687e83
Merge branch 'BAO-martin' of https://github.com/martin-millon/hierArc…
martin-millon 3eb8d7f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2798586
coverage improvement
martin-millon 72b128f
Merge branch 'BAO-martin' of https://github.com/martin-millon/hierArc…
martin-millon d4e15df
coverage improvement
martin-millon 0ad7029
completing coverage
martin-millon 03e0655
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # DESI DR2 data set | ||
|
|
||
| Source: https://github.com/CobayaSampler/bao_data/tree/master/desi_bao_dr2 | ||
|
|
||
| Reference Paper : https://arxiv.org/abs/2503.14738 |
13 changes: 13 additions & 0 deletions
13
hierarc/Data/BAO/desi_bao_dr2/desi_gaussian_bao_ALL_GCcomb_cov.txt
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,13 @@ | ||
| 5.78998687e-03 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 2.83473742e-02 -3.26062007e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 -3.26062007e-02 1.83928040e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 3.23752442e-02 -2.37445646e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 -2.37445646e-02 1.11469198e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 2.61732816e-02 -1.12938006e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.12938006e-02 4.04183878e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.05336516e-01 -2.90308418e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 -2.90308418e-02 5.04233092e-02 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 5.83020277e-01 -1.95215562e-01 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 -1.95215562e-01 2.68336193e-01 0.00000000e+00 0.00000000e+00 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 1.02136194e-02 -2.31395216e-02 | ||
| 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00 -2.31395216e-02 2.82685779e-01 | ||
14 changes: 14 additions & 0 deletions
14
hierarc/Data/BAO/desi_bao_dr2/desi_gaussian_bao_ALL_GCcomb_mean.txt
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,14 @@ | ||
| # [z] [value at z] [quantity] | ||
| 0.29500000 7.94167639 DV_over_rs | ||
| 0.51000000 13.58758434 DM_over_rs | ||
| 0.51000000 21.86294686 DH_over_rs | ||
| 0.70600000 17.35069094 DM_over_rs | ||
| 0.70600000 19.45534918 DH_over_rs | ||
| 0.93400000 21.57563956 DM_over_rs | ||
| 0.93400000 17.64149464 DH_over_rs | ||
| 1.32100000 27.60085612 DM_over_rs | ||
| 1.32100000 14.17602155 DH_over_rs | ||
| 1.48400000 30.51190063 DM_over_rs | ||
| 1.48400000 12.81699964 DH_over_rs | ||
| 2.33 8.631545674846294 DH_over_rs | ||
| 2.33 38.988973961958784 DM_over_rs |
Empty file.
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,45 @@ | ||
| import numpy as np | ||
| from hierarc.Likelihood.BAOLikelihood.bao_likelihood_custom import CustomBAOLikelihood | ||
|
|
||
|
|
||
| class BAOLikelihood(object): | ||
| """BAO likelihood.This class supports custom likelihoods as well as likelihoods from | ||
| the DESI BAO files.""" | ||
|
|
||
| def __init__(self, sample_name="DESI_DR2", **kwargs_bao_likelihood): | ||
| """ | ||
|
|
||
| :param sample_name: string, either 'CUSTOM' or a specific name supported by SneLikelihoodFromFile() class | ||
| :param kwargs_sne_likelihood: keyword arguments to initiate likelihood class | ||
| """ | ||
| if sample_name == "CUSTOM": | ||
| self._likelihood = CustomBAOLikelihood(**kwargs_bao_likelihood) | ||
| elif sample_name == "DESI_DR2": | ||
| from hierarc.Likelihood.BAOLikelihood.desi_dr2 import DESIDR2Data | ||
|
|
||
| data = DESIDR2Data() | ||
|
|
||
| self._likelihood = CustomBAOLikelihood( | ||
| z=data.z, | ||
| d=data.d, | ||
| distance_type=data.distance_type, | ||
| cov=data.cov, | ||
| ) | ||
|
|
||
| else: | ||
| raise ValueError("Unsupported sample name: {}".format(sample_name)) | ||
|
|
||
| def log_likelihood(self, cosmo, rd=None): | ||
| """ | ||
|
|
||
| :param cosmo: instance of a class to compute angular diameter distances on arrays | ||
|
|
||
| :return: log likelihood of the data given the specified cosmology | ||
| """ | ||
| # TODO compute here the default case if rd is not sampled. | ||
| if rd is None: | ||
| raise NotImplementedError( | ||
| "Computation of rd is not implemented yet. Please provide rd in the kwargs_cosmo and turn rd_sampling=True in the kwargs_model." | ||
| ) | ||
|
|
||
| return self._likelihood.log_likelihood_bao(cosmo, rd) |
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,79 @@ | ||
| import numpy as np | ||
| from astropy.constants import c | ||
| import astropy.units as u | ||
|
|
||
| _twopi = 2 * np.pi | ||
|
|
||
|
|
||
| class CustomBAOLikelihood(object): | ||
| """Class method for an arbitrary BAO measurements. | ||
|
|
||
| Distances measurements (scaled by rs) and the covariance matrix must be provided in | ||
| the constructor. The likelihood is assumed to be Gaussian. | ||
| """ | ||
|
|
||
| def __init__(self, z, d, distance_type, cov): | ||
| """ | ||
|
|
||
| :param z: array of redshifts of the BAO measurements | ||
| :param d: array of BAO measurements, scaled by rs | ||
| :param distance_type: string, either 'DV_over_rs' or 'DM_over_rs' or 'DH_over_rs' | ||
|
|
||
| """ | ||
| self.z = z | ||
| self.d = d | ||
| self.distance_type = distance_type | ||
| self.cov = cov | ||
| self._inv_cov = np.linalg.inv(cov) | ||
| self.num_d = len(d) | ||
| assert len(z) == len(d), "z and d must have the same length" | ||
|
|
||
| def log_likelihood_bao(self, cosmo, rd): | ||
| """ | ||
| :param cosmo: instance of a class to compute angular diameter distances on arrays | ||
| :param rd: comoving sound horizon at the drag epoch | ||
| :return: log likelihood of the data given the specified cosmology | ||
| """ | ||
| distance_theory = np.zeros(self.num_d) | ||
|
|
||
| for i in range(self.num_d): | ||
| if self.distance_type[i] == "DV_over_rs": | ||
| distance_theory[i] = self._compute_DV(cosmo, self.z[i]) | ||
| elif self.distance_type[i] == "DM_over_rs": | ||
| distance_theory[i] = self._compute_DM(cosmo, self.z[i]) | ||
| elif self.distance_type[i] == "DH_over_rs": | ||
| distance_theory[i] = self._compute_DH(cosmo, self.z[i]) | ||
| else: | ||
| raise ValueError( | ||
| "Unsupported distance type: {}".format(self.distance_type) | ||
| ) | ||
| # scale by the comoving sound horizon | ||
| distance_theory[i] /= rd | ||
|
|
||
| # Compute the log likelihood | ||
| diff = self.d - distance_theory | ||
| logL = -0.5 * np.dot(diff, np.dot(self._inv_cov, diff)) | ||
| sign_det, lndet = np.linalg.slogdet(self.cov) | ||
| logL -= 1 / 2.0 * (self.num_d * np.log(2 * np.pi) + lndet) # normalization term | ||
| return logL | ||
|
|
||
| def _compute_DV(self, cosmo, z): | ||
| """Compute the DV distance at redshift z. | ||
|
|
||
| (see Section III.A of https://arxiv.org/pdf/2503.14738) | ||
| """ | ||
|
|
||
| DV = (z * self._compute_DM(cosmo, z) ** 2 * self._compute_DH(cosmo, z)) ** ( | ||
| 1.0 / 3.0 | ||
| ) | ||
| return DV | ||
|
|
||
| def _compute_DM(self, cosmo, z): | ||
| """Compute the DM distance (transverse comoving distance) at redshift z.""" | ||
| return cosmo.comoving_transverse_distance(z).value | ||
|
|
||
| def _compute_DH(self, cosmo, z): | ||
| """Compute the DH (Hubble distance) distance at redshift z.""" | ||
| Hz = cosmo.H(z) # in km/s/Mpc | ||
| D_H = (c / Hz).to(u.Mpc) | ||
| return D_H.value |
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,36 @@ | ||
| import os | ||
| import pandas as pd | ||
| import numpy as np | ||
| import hierarc | ||
|
|
||
| _PATH_2_DATA = os.path.join(os.path.dirname(hierarc.__file__), "Data", "BAO") | ||
|
|
||
|
|
||
| class DESIDR2Data(object): | ||
| """ | ||
| This class collect the data from teh DESI DR2 analysis presented in DESI collaboration et al. 2025 (https://arxiv.org/abs/2503.14738) | ||
|
|
||
| The data covariances that are stored in hierArc are originally from `DESI DR2`_. | ||
| https://github.com/CobayaSampler/bao_data/tree/master/desi_bao_dr2 | ||
|
|
||
| If you make use of these products, please cite `DESI collaboration et al. 2025`_ | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| self._data_file = os.path.join( | ||
| _PATH_2_DATA, "desi_bao_dr2", "desi_gaussian_bao_ALL_GCcomb_mean.txt" | ||
| ) | ||
| self._cov_file = os.path.join( | ||
| _PATH_2_DATA, "desi_bao_dr2", "desi_gaussian_bao_ALL_GCcomb_cov.txt" | ||
| ) | ||
|
|
||
| data = pd.read_csv(self._data_file, sep=r"\s+") | ||
|
|
||
| self.origlen = len(data) | ||
| print(f"Importing {self.origlen} distances from DESI DR2 data.") | ||
|
|
||
| self.z = data.iloc[:, 0].to_numpy() | ||
| self.d = data.iloc[:, 1].to_numpy() | ||
| self.distance_type = data.iloc[:, 2].to_numpy() | ||
|
|
||
| self.cov = np.loadtxt(self._cov_file) |
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
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.