PrePostCov is a Python package to compute analytical covariances between multipoles of the pre-reconstruction galaxy power spectrum and the post-reconstruction two-point correlation function.
Install from PyPI:
pip install prepostcovOr install locally for development (from the root directory):
pip install -e .The main novelty presented in this repo is an analytic calculation of the cross-covariance between covariances_pk_xi.py. Running this requires only very basic dependencies like numpy and scipy.
For the basic cross-covariance calculation, see the worked example in preprost_covariance.ipynb. In brief:
# After installation, you can import the main classes and functions as
from prepostcov import PkXiCovariance, LegendreMultipoleExtractor
# Initialize the covariance builder
cov_builder = PkXiCovariance(k=k_array, r=r_array, V=survey_volume,
poles_Pk=[0, 2], poles_Xi=[0, 2])
# Provide the fiducial P_cross(k, mu) (see paper for details)
cov_builder.set_Pcross_from_callable(P_cross_of_mu, ells=[0, 2, 4])
# Compute the Pk-Xi block of the covariance matrix
cov_PkXi = cov_builder.compute_covariance() # shape (n_poles_Pk, n_poles_Xi, nk, nr)Additionally, we include code to calculate the remaining blocks of the covariance matrix involving
Overall steps are:
- Compute P(k),Xi(s) from catalogs
- Compute P(k) window matrices
- Obtain fiducial spectra for covariances (Can skip steps 1-3 if you already have fiducial spectra)
- Compute gaussian, t0, and ssc pieces of P(k) covariance
- Compute Xi(s) covariance
- Compute PkxXi covariance and combine everyting
These are all subroutines in the full_covariance() class in Covariances_full.py. The front end script is do_everything.py to which you add arguments related to the desired task:
-
Measure P(k):
srun -n 64 python do_everything.py --task measure_pk \ --tracer LRG --zrange 0.4 0.6 --zeff 0.51 --DR 2 --version v2 \ --region GCcomb --outpath ./data/pk_measured/Pk_LRG_z0.4-0.6_DR2_GCcomb -
Compute window:
srun -n 64 python do_everything.py --task compute_window \ --pk_poles_path ./data/pk_measured/Pk_LRG_z0.4-0.6_DR2_GCcomb.npy \ --tracer LRG --zrange 0.4 0.6 --zeff 0.51 --DR 2 --version v2 \ --region GCcomb --outpath ./data/pk_window/wmat_LRG_z0.4-0.6_DR2_GCcomb
If you use this code in your research, please cite:
Maus, Baleato Lizancos, White, de Mattia & Chen (2026)
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License (CC BY-NC 4.0). You are free to use, share, and adapt this code for non-commercial purposes with appropriate attribution.