CAMB (Code for Anisotropies in the Microwave Background), a cosmology code for calculating CMB, lensing, galaxy count, dark-age 21cm power spectra, matter power spectra and transfer functions. There are also general utility function for cosmological calculations such as the background expansion, distances, etc. The main code is Python with numerical calculations implemented efficiently in Python-wrapped modern Fortran.
See the CAMB python example notebook for an introductory set of examples of how to use the CAMB package. This is usually the fastest way to learn how to use it and quickly see some of the capabilities.
For a standard non-editable installation use:
pip install camb [--user]
The –user is optional and only required if you don’t have write permission to your main python installation. If you want to work on the code from GitHub, you can also just install in place without copying anything using:
git clone --recursive https://github.com/cmbant/CAMB.git
pip install -e ./CAMB [--user]
You will need ifort or gfortran 6 or higher installed (and on your path) to compile; see Fortran compilers for compiler installation details if needed. A compiled library for Windows is also provided, and is used if no gfortran installation is found on Windows machines. If you have gfortran installed, “python setup.py make” will build the Fortran library on all systems (including Windows without directly using a Makefile), and can be used to update a source installation after changes or pulling an updated version.
Anaconda users can also install from conda-forge, best making a new clean environment using:
conda create -n camb -c conda-forge python=3.9 camb
with no need for a Fortran compiler (unless you want to use custom sources/symbolic compilation features). Check that conda installs the latest version, if not try installing in a new clean conda environment as above.
After installation the camb python module can be loaded from your scripts using “import camb”.
You can also run CAMB from the command line reading parameters from a .ini file, e.g.:
Main high-level modules:
- Basic functions
- Input parameter model
- Calculation results
- Symbolic manipulation