PolyBin3D is a Python code that estimates the binned power spectrum and bispectrum for 3D fields such as the distributions of matter and galaxies, using the algorithms of Philcox 2020, Philcox 2021, Ivanov et al. 2023 and Philcox & Flöss 2024. It is a sister code to PolyBin, which computes the polyspectra of data on the two-sphere and is a modern reimplementation of the former Spectra-Without-Windows code.
For each statistic, two estimators are available: the standard (ideal) estimators, which do not take into account the mask, and window-deconvolved estimators. In the second case, we require computation of a Fisher matrix; this depends on binning and the mask, but does not need to be recomputed for each new simulation.
The code supports GPU acceleration using JAX, which can be enabled using the backend
argument in the base
class, as demonstrated below.
PolyBin contains the following modules:
pspec
: Binned power spectrabspec
: Binned bispectra
The basic usage of the power spectrum class is the following:
# Import code
import PolyBin3D as pb
import numpy as np
# Load base class
base = pb.PolyBin3D(boxsize, # dimensions of box
gridsize, # dimensions of Fourier-space grid,
boxcenter=[0,0,0], # center of simulation box
pixel_window='tsc', # pixel window function
backend='fftw', # backend for performing FFTs ('fftw' or 'mkl' for cpu, 'jax' for gpu)
nthreads=4, # number of CPUs to parallelize across (not used for jax code)
sightline='global') # redshift-space axis
# Load power spectrum class
pspec = pb.PSpec(base,
k_bins, # k-bin edges
lmax=lmax, # Legendre multipoles
mask=mask, # real-space mask
applySinv=None, # filter to apply to data
)
# Compute Fisher matrix and shot-noise using Monte Carlo simulations (should usually be parallelized)
fish, shot_num = pspec.compute_fisher(10, verb=True)
# Compute windowed power spectra
Pk_ideal = pspec.Pk_ideal(data)
# Compute unwindowed power spectra, using the Fisher matrix we just computed
Pk_unwindowed = pspec.Pk_unwindowed(data, fish=fish, shot_num=shot_num, subtract_shotnoise=False)
Bispectra can be computed similarly:
# Load bispectrum class
bspec = pb.BSpec(base,
k_bins, # k-bin edges
lmax=lmax, # Legendre multipoles
mask=mask, # real-space mask
applySinv=None, # filter to apply to data
)
# Compute Fisher matrix using Monte Carlo simulations (should usually be parallelized)
fish = bspec.compute_fisher(10, verb=True)
# Compute windowed bispectra
Bk_ideal = bspec.Bk_ideal(data)
# Compute unwindowed bispectra using the Fisher matrix we just computed
Bk_unwindowed = bspec.Bk_unwindowed(data, fish=fish, include_linear_term=False)
Further details are described in the tutorials, which describe
- Tutorial 1: introduction to PolyBin3D, and computing the power spectrum from simulations
- Tutorial 2: validation of the window-deconvolved power spectrum estimators
- Tutorial 3: application of the power spectrum estimators to the BOSS DR12 dataset
- Tutorial 4: introduction to computing bispectra
- Tutorial 5: validation of the window-deconvolved bispectrum estimators
- Oliver Philcox (Columbia / Simons Foundation)
- Thomas Flöss (University of Groningen)
- Python 2/3
numpy
,scipy
fftw
ormkl_fft
[for FFTs on the CPU] orJAX
[for GPU computations]nbodykit
[not required, but useful for testing]
pip install "PolyBin3D @ git+https://github.com/oliverphilcox/PolyBin3D"
To install with fftw
or mkl_fft
or jax
as the backend, use:
pip install "PolyBin3D[fftw] @ git+https://github.com/oliverphilcox/PolyBin3D"
Replace
fftw
withmkl_fft
orjax
as appropriate.You can also install nbodykit as an optional dependency by adding
[nbodykit]
to the dependencies
git clone https://github.com/oliverphilcox/PolyBin3D.git
pip install .
To install in editable mode, use:
pip install -e .
To recompile the cython files (only in editable mode), use:
python setup.py build_ext --inplace
python setup.py clean --all # to remove temp build files
The optional dependencies can be installed by adding the relevant extras to the pip install command, e.g.
pip install .[fftw, nbodykit]
.
Code references:
- Philcox, O. H. E. & Flöss, T.: "PolyBin3D: A Suite of Optimal and Efficient Power Spectrum and Bispectrum Estimators for Large-Scale Structure", (2024) (arXiv)
- Philcox, O. H. E., "Cosmology Without Window Functions: Quadratic Estimators for the Galaxy Power Spectrum", (2020) (arXiv)
- Philcox, O. H. E., "Cosmology Without Window Functions: Cubic Estimators for the Galaxy Bispectrum", (2021) (arXiv)
- Ivanov, M. M., Philcox, O. H. E., et al. "Cosmology with the Galaxy Bispectrum Multipoles: Optimal Estimation and Application to BOSS Data" (2023) (arXiv)
Some works using data from PolyBin3D (or its predecessor)
- Philcox & Ivanov (2021, arXiv): Combined constraints on LambdaCDM from the BOSS power spectrum and bispectrum.
- Cabass et al. (2022, arXiv): Constraints on single-field inflation from the BOSS power spectrum and bispectrum.
- Cabass et al. (2022, arXiv): Constraints on multi-field inflation from the BOSS power spectrum and bispectrum.
- Nunes et al. (2022, arXiv): Constraints on dark-sector interactions from the BOSS galaxy power spectrum.
- Rogers et al. (2023, arXiv): Ultra-light axions and the S8 tension: joint constraints from the cosmic microwave background and galaxy clustering.
- Ivanov et al. (2023, arXiv): Cosmology with the Galaxy Bispectrum Multipoles: Optimal Estimation and Application to BOSS Data.
- Moretti et al. (2023, arXiv): Constraints on the growth index and neutrino mass from the BOSS power spectrum.
- He et al. (2023, arXiv): Self-Interacting Neutrinos in Light of Large-Scale Structure Data.
- Camarena et al. (2023, arXiv): The two-mode puzzle: Confronting self-interacting neutrinos with the full shape of the galaxy power spectrum
- Chudaykin, Ivanov, Philcox (2025, arXiv): Reanalyzing DESI DR1: 1. LCDM Constraints from the Power Spectrum & Bispectrum