python binding of CLASS for large-scale structure calculations
Project description
classylss
A python binding of the CMB Boltzmann code CLASS, designed for large-scale structure calculations.
The package mainly uses CLASS in order to compute linear power spectra, but the python binding also supports computing nonlinear power spectra and the Cls spectra.
Some of the package features:
underyling calculations done in C++, with SWIG used to produce the Python interface
a parameter interface with the astropy.cosmology module
linear correlation function calculations using FFTLog
power spectra and correlation functions in the Zel’dovich approximation
Dependencies
The required external Python dependencies are:
astropy
numpy
requests
The latest version of CLASS will automatically be downloaded and compiled, and is thus, not an external dependency for the user.
Installation
The package can be cloned from github as
git clone https://github.com/nickhand/classylss.git
cd classylss
The classylss package can be installed using
export CFLAGS='-std=c++11 -fopenmp'; pip install .
If CLASS is not built succesfully, the installation will crash. In this case, the user can edit the default configuration variables in depends/class.cfg, which are used when building the CLASS library.
This procedure has been tested on Mac and Linux machines.
To verify that the installation has succeeded, run:
import classylss
Examples
To compute power spectra for the Planck 2015 cosmology:
from astropy.cosmology import Planck15
from classylss import power
import numpy
# desired wavenumbers (in h/Mpc)
k = numpy.logspace(-3, 0, 500)
# desired redshift
z = 0
# linear power spectrum in [Mpc/h]^3
Plin = power.linear(k, z, verbose=True, cosmo=Planck15)
# nonlinear power spectrum in [Mpc/h]^3
Pnl = power.nonlinear(k, z, verbose=True, cosmo=Planck15)
# Zeldovich power spectrum in [Mpc/h]^3
Pzel = power.zeldovich(k, z, verbose=True, cosmo=Planck15)
and similarly, correlation functions can be computed:
from classylss import correlation
# desired separation (in Mpc/h)
r = numpy.logspace(0, numpy.log10(150), 500)
# desired redshift
z = 0
# linear 2PCF
cf_lin = correlation.linear(r, z, verbose=True, cosmo=Planck15)
# nonlinear 2PCF
cf_nl = correlation.nonlinear(r, z, verbose=True, cosmo=Planck15)
# Zeldovich power spectrum in [Mpc/h]^3
cf_zel = correlation.zeldovich(r, z, smoothing=1.0, verbose=True, cosmo=Planck15)
All of the above functions accept a class_kwargs keyword, which allows the user to pass any valid CLASS parameter to the CLASS code. The class_kwargs parameter is a dictionary that will be passed to the ClassEngine instance, which is responsible for running CLASS.
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.