Cosmological summary statistics from galaxy catalogues and lensing data
Project description
sum_stat
Python package for measuring cosmological summary statistics from galaxy catalogues and lensing data, built on JAX for differentiable, JIT-compilable estimators.
Features
| Module | Estimators |
|---|---|
| Two-point correlation functions | w_theta, xi_r, wp, xi_multipoles |
| Power spectra | cl_angular, pk3d, pk_multipoles |
| Galaxy–galaxy lensing | delta_sigma, delta_sigma_nfw_jax, delta_sigma_from_xi_jax |
| Luminosity / stellar-mass functions | luminosity_function_vmax, stellar_mass_function_vmax, luminosity_function_swml, cumulative_luminosity_function_cminus, fit_schechter_sty |
| Independence tests | efron_petrosian_tau (Efron & Petrosian 1992), rauzy_completeness (Rauzy 2001) |
| Redshift distributions | nz_histogram, nz_kde |
| Covariance | jackknife_covariance, bootstrap_covariance |
| I/O | SummaryStatWriter, SummaryStatReader (HDF5) |
| Catalogues | GalaxyCatalogue, ShapeCatalogue, PhotoZCalibTable |
| Cosmology | JAX-differentiable comoving distance, volume, Σ_crit |
Installation
mamba env create -f environment.yml
mamba activate sum_stat
pip install -e .
Quick start
import numpy as np
import sum_stat as ss
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0=67.36, Om0=0.3111)
# --- Catalogues ----------------------------------------------------------
cat = ss.GalaxyCatalogue(ra=ra, dec=dec, redshift=z, weight=w, mag_limit=22.5)
rand = ss.GalaxyCatalogue(ra=ra_r, dec=dec_r, redshift=z_r)
# --- Two-point correlation functions -------------------------------------
import numpy as np
theta_bins = np.logspace(-2, 1, 20) # degrees
theta, w, vw = ss.w_theta(cat, rand, theta_bins)
r_bins = np.logspace(-1, 2, 20) # Mpc/h
r, xi, vxi = ss.xi_r(cat, rand, r_bins, cosmo)
r, wp_val, vwp = ss.wp(cat, rand, r_bins, pi_max=60.0, cosmo=cosmo)
s_bins = np.logspace(-1, 2, 20)
s, xi_dict = ss.xi_multipoles(cat, rand, s_bins, ells=(0, 2, 4), cosmo=cosmo)
# xi_dict[0], xi_dict[2], xi_dict[4] → monopole, quadrupole, hexadecapole
# --- Power spectra -------------------------------------------------------
ell_bins = np.geomspace(10, 3000, 30)
ell, cl, vcl = ss.cl_angular(cat, rand, ell_bins)
k_bins = np.logspace(-2, 0, 30)
k, pk, vpk = ss.pk3d(cat, rand, k_bins, cosmo=cosmo)
# --- Galaxy–galaxy lensing -----------------------------------------------
import dsigma.helpers as dh
from astropy.table import Table
# Build a dsigma-formatted source table (see dsigma docs for survey details)
table_s = dh.dsigma_table(Table({
"ra": ra_s, "dec": dec_s, "z": z_s,
"e_1": e1, "e_2": e2, "w": w_s, "m": m, "e_rms": e_rms,
"R_11": R11, "R_22": R22, "R_12": R12, "R_21": R21,
}), "source")
rp_bins = np.logspace(-1, 1.5, 15) # Mpc
corrections = {"scalar_shear_response_correction": True,
"shear_responsivity_correction": True}
rp, ds, cov = ss.delta_sigma(cat, table_s, rp_bins, cosmo,
corrections=corrections)
# --- Luminosity / stellar-mass functions ---------------------------------
from sum_stat.lf_smf.swml import luminosity_function_swml
from sum_stat.lf_smf.cminus import cumulative_luminosity_function_cminus
from sum_stat.lf_smf.independence import efron_petrosian_tau, rauzy_completeness
M_bins = np.linspace(-24, -18, 20)
area_sr = 0.3
# 1/Vmax estimator (Schmidt 1968)
M, phi, phi_err = ss.luminosity_function_vmax(cat, 0.1, 0.5, 22.5, M_bins, area_sr, cosmo)
# SWML estimator (Efstathiou, Ellis & Peterson 1988)
M, phi_sw, phi_sw_err = luminosity_function_swml(cat, 0.1, 0.5, 22.5, M_bins, area_sr, cosmo)
# C⁻ non-parametric cumulative estimator (Lynden-Bell 1971)
M_sorted, Phi, Phi_err = cumulative_luminosity_function_cminus(cat, 0.1, 0.5, 22.5, area_sr, cosmo)
# STY parametric Schechter fit
result = ss.fit_schechter_sty(cat, 0.1, 0.5, 22.5, M_bins, area_sr, cosmo)
logM_bins = np.linspace(9, 12, 20)
logM, smf, smf_err = ss.stellar_mass_function_vmax(cat, 0.1, 0.5, logM_bins, area_sr, cosmo)
# Efron–Petrosian independence test (τ ~ N(0,1) under H₀)
ep = efron_petrosian_tau(cat.abs_mag, cat.redshift, 22.5, cosmo)
# Rauzy completeness tests
rz = rauzy_completeness(cat.abs_mag, cat.redshift, 22.5, cosmo)
# --- Covariance ----------------------------------------------------------
cov_jk = ss.jackknife_covariance(estimator_func, cat, n_patches=20)
cov_bt = ss.bootstrap_covariance(estimator_func, cat, n_bootstrap=200)
# --- I/O (HDF5) ----------------------------------------------------------
writer = ss.SummaryStatWriter("results.h5")
writer.write_twopcf("angular_2pcf/sample_A",
theta, w, cov_jk, theta_bins,
estimator="landy-szalay", cosmo=cosmo, meta={})
reader = ss.SummaryStatReader("results.h5")
data = reader.read_twopcf("angular_2pcf/sample_A")
JAX cosmology utilities
All functions in sum_stat.cosmology are JIT-compiled and differentiable with respect to cosmological parameters:
from sum_stat.cosmology import comoving_distance_jax, critical_surface_density_jax
import jax
chi = comoving_distance_jax(z=0.5, h=0.6736, omega_m=0.3111) # [Mpc]
dchi = jax.grad(comoving_distance_jax)(0.5, 0.6736, 0.3111) # d chi / d z
sigma_crit = critical_surface_density_jax(z_l=0.3, z_s=0.8,
h=0.6736, omega_m=0.3111) # [M_sun/pc^2]
Development
# tests
pytest tests/
# formatting / linting
black sum_stat/
ruff check sum_stat/
# documentation
cd docs && make html
Citation
If you use sum_stat in your research, please cite it as:
@software{comparat2026sumstat,
author = {Comparat, Johan},
title = {{sum\_stat}: Cosmological summary statistics from galaxy catalogues and lensing data},
year = {2026},
version = {0.1.0},
url = {https://github.com/JohanComparat/sum_stat},
license = {MIT},
}
A CITATION.cff file is also provided for automated citation tools (GitHub "Cite this repository" button).
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for development setup, coding conventions, and how to submit a pull request.
License
MIT — see LICENSE.
Package structure
sum_stat/
├── sum_stat/
│ ├── catalogue.py # GalaxyCatalogue, ShapeCatalogue, PhotoZCalibTable
│ ├── cosmology.py # JAX-differentiable distances and Σ_crit
│ ├── covariance/ # jackknife_covariance, bootstrap_covariance
│ ├── io/ # SummaryStatWriter, SummaryStatReader
│ ├── lensing/ # delta_sigma, NFW model
│ ├── lf_smf/ # 1/Vmax, SWML, C⁻, STY fit, EP τ, Rauzy
│ ├── nz/ # nz_histogram, nz_kde
│ ├── powspec/ # cl_angular, pk3d, pk_multipoles
│ └── twopcf/ # w_theta, xi_r, wp, xi_multipoles
├── tests/
├── docs/
├── environment.yml
└── pyproject.toml
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sum_stat-0.1.0.tar.gz.
File metadata
- Download URL: sum_stat-0.1.0.tar.gz
- Upload date:
- Size: 87.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b01616de53709c7e820366fd18abd7c36c2c38e6d4d0f353b6793e7e325e1d82
|
|
| MD5 |
e2b251391519cfd07e0919781f766e37
|
|
| BLAKE2b-256 |
8356d2248d37b8e8a72bde63331dc4f223e9a5e132794d00360b4e23d833bfe2
|
File details
Details for the file sum_stat-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sum_stat-0.1.0-py3-none-any.whl
- Upload date:
- Size: 73.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e50d5b75e275fb3f1024dade089513130a338961df10aff7da7f1907493c500b
|
|
| MD5 |
2c0d6ed1d0d56241c31d260a0ec31eb8
|
|
| BLAKE2b-256 |
7c1994eb3e852cfb31fec9013842fd31381493e61289a013dd23056fd26ac732
|