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=Falseanddo_primordial_bispectrum=True. The primordial bispectrum is normalized tof_NL=1.Full and sparse bispectrum outputs can be too large to return directly to Python, so set
full_output_fileand/orSlice_Base_Lto write them from the Fortran calculation. Slice outputs write rows for fixedL1=Slice_Base_LandL3-L2values fromdeltas.The Fisher matrix calculation is optional and requires building CAMB from source with
FISHER=Yand LAPACK linked. On a normal binary or source build without this flag, requestingDoFisher=TrueraisesCAMBValueErrorrather 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
- 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 withFISHER=Y. Usehas_fisherandhas_optimal_fisherto 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.CAMBparamsinstance, without going through.inifiles. The defaultBispectrumParamscalculates the CMB lensing bispectrum, soparams.DoLensingmust be true. For requested large outputs, pass anoutput_rootprefix and setbispectrum_params.full_output_fileorbispectrum_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=Yand LAPACK available, for examplecd fortran && make python FISHER=Yfor gfortran builds using the default-lblas -llapacklink flags.- Parameters:
params –
model.CAMBparamsinstance, or a dict passed tocamb.set_params()bispectrum_params – optional
BispectrumParamsinstance or dictoutput_root – filename prefix for requested large file outputs
- Returns: