Bispectrum

The bispectrum wrapper runs the existing Fortran calculation from Python, using normal CAMBparams objects rather than writing temporary .ini files. It can calculate CMB lensing and local primordial bispectra, write large slice or full bispectrum tables directly to files, and return the small in-memory Fisher summary when requested.

The module is not imported by default with import camb. Import it explicitly when needed:

import camb
from camb import bispectrum

pars = camb.set_params(lmax=600, lens_potential_accuracy=1)
bpars = bispectrum.BispectrumParams(Slice_Base_L=10, deltas=[0, 2])
result = bispectrum.get_bispectrum(pars, bpars, output_root="run1_")

print(bpars.expected_output_files("run1_"))
print(result.has_fisher)

The default BispectrumParams calculates the CMB lensing bispectrum, so the CAMB parameters must have lensing enabled. To calculate the local primordial bispectrum normalized to f_NL=1 instead, use BispectrumParams(do_lensing_bispectrum=False, do_primordial_bispectrum=True).

Fisher Matrices

Fisher matrix output is disabled in normal builds to avoid requiring LAPACK. To use BispectrumParams(DoFisher=True), build the Fortran library from source with FISHER=Y and LAPACK/BLAS linked. For the default gfortran makefile this is, for example:

cd fortran
make python FISHER=Y

The gfortran makefile uses -lblas -llapack by default for Fisher builds. Intel ifort builds use MKL when FISHER=Y is set.

class camb.bispectrum.BispectrumParams(**kwargs)[source]

Settings for calculating local primordial and CMB lensing bispectra.

The default settings calculate the CMB lensing bispectrum using temperature and polarization fields. To calculate the local primordial bispectrum instead, set do_lensing_bispectrum=False and do_primordial_bispectrum=True. The primordial bispectrum is normalized to f_NL=1.

Full and sparse bispectrum outputs can be too large to return directly to Python, so set full_output_file and/or Slice_Base_L to write them from the Fortran calculation. Slice outputs write rows for fixed L1=Slice_Base_L and L3-L2 values from deltas.

The Fisher matrix calculation is optional and requires building CAMB from source with FISHER=Y and LAPACK linked. On a normal binary or source build without this flag, requesting DoFisher=True raises CAMBValueError rather than aborting the Python process.

Variables:
  • do_lensing_bispectrum – (boolean) Calculate the CMB lensing bispectrum

  • do_primordial_bispectrum – (boolean) Calculate the local primordial bispectrum, normalized to f_NL=1

  • nfields – (integer) 1 for T only, 2 for T and E

  • Slice_Base_L – (integer) Base L for slice output; zero disables slice output

  • ndelta – (integer) Number of L3-L2 offsets for slice output

  • deltas – (integer array) L3-L2 offsets for slice output

  • do_parity_odd – (boolean) Calculate parity-odd lensing slices

  • DoFisher – (boolean) Calculate Fisher matrix outputs; requires a FISHER build

  • export_alpha_beta – (boolean) Export primordial radial alpha/beta functions

  • FisherNoise – (float64) Temperature white noise level in micro-Kelvin^2 radians

  • FisherNoisePol – (float64) Polarization white noise level in micro-Kelvin^2 radians

  • FisherNoiseFwhmArcmin – (float64) Gaussian beam FWHM in arcmin for Fisher noise

  • SparseFullOutput – (boolean) Write only sampled/sparse full-bispectrum rows

expected_output_files(output_root='') list[Path][source]

Return the normal slice/full-output filenames requested by these settings.

This helper mirrors the public large-output options and does not attempt to predict internal Fortran diagnostic file-tag variants.

class camb.bispectrum.BispectrumResult[source]

Small in-memory summary returned by get_bispectrum().

Large bispectrum tables are written directly to files requested by BispectrumParams. This object contains Fisher matrices and corresponding one-sigma errors when the Fisher calculation was requested and the library was built with FISHER=Y. Use has_fisher and has_optimal_fisher to check which arrays were filled.

Variables:
  • nbispectra – (integer)

  • nfields – (integer)

  • has_fisher – (boolean)

  • has_optimal_fisher – (boolean)

  • has_lensing_variance – (boolean)

  • Fisher – (float64 array)

  • OptimalFisher – (float64 array)

  • Sigma – (float64 array)

  • OptimalSigma – (float64 array)

  • LensingFisherWithVariance – (float64)

camb.bispectrum.get_bispectrum(params, bispectrum_params=None, output_root='', _debug_params=False) BispectrumResult[source]

Calculate local primordial and/or CMB lensing bispectrum outputs.

The wrapper runs the Fortran bispectrum calculation using a normal model.CAMBparams instance, without going through .ini files. The default BispectrumParams calculates the CMB lensing bispectrum, so params.DoLensing must be true. For requested large outputs, pass an output_root prefix and set bispectrum_params.full_output_file or bispectrum_params.Slice_Base_L.

For example:

from camb import bispectrum

pars = camb.set_params(lmax=600, lens_potential_accuracy=1)
bpars = bispectrum.BispectrumParams(Slice_Base_L=10, deltas=[0, 2])
result = bispectrum.get_bispectrum(pars, bpars, output_root="run1_")
print(bpars.expected_output_files("run1_"))

Fisher outputs require a source build with the make variable FISHER=Y and LAPACK available, for example cd fortran && make python FISHER=Y for gfortran builds using the default -lblas -llapack link flags.

Parameters:
Returns:

BispectrumResult