CAMB-Python Interface

Use of Cobaya. camb, CLASS, cosmomc, compilers, etc.
Post Reply
Joe Zuntz
Posts: 9
Joined: October 22 2004
Affiliation: UCL

CAMB-Python Interface

Post by Joe Zuntz » September 08 2010

I thought I'd put this up, on the off-chance it's of use to someone.

I've written a code to generate bindings for CAMB so you can call its main functions directly from the Python programming language.

This makes it easy, for example, to quickly generate power spectra for many different parameters combinations, and then plot them nicely, all in the same script. It's also useful for interactively exploring parameter spaces.

It's simple to add new parameters to it, if you've modified something in CAMB.

Code and instructions available here.

Please send any bugs/requests to jaz (at) astro.ox.ac.uk

Joe

Lukas Hollenstein
Posts: 16
Joined: March 31 2009
Affiliation: IPhT CEA-Saclay
Contact:

CAMB-Python Interface

Post by Lukas Hollenstein » October 04 2010

Hi Joe,

Thanks a lot, this is very useful :)

I don't know if anybody else has a problem compiling the Python code on a Mac? The "f2py" command complained that the CAMB library ("libcamb.a") had a problem. I found that one first needs to add a table of contents to the library before running "f2py". This is done with the "ranlib" command. So I added a line

Code: Select all

system('make all && ranlib libcamb.a')
before calling "f2py" in the end of "generatePyCamb.py".


By the way, I finally put my new version of GetDist_py up: http://www.physi.ch/lukas/Code.html. This is a version of GetDist (CosmoMC May 2010) which generates Python/PyLab scrips aside or instead of the usual Matlab scripts.

Lukas

Steven Murray
Posts: 3
Joined: April 02 2013
Affiliation: ICRAR UWA

CAMB-Python Interface

Post by Steven Murray » April 04 2013

Hi thanks so very much for this!

I was just in the middle of making my own version of the same thing - then thought "hey just wait a minute, someone may have done this already!"

I'll check it out and let you know if it works for me. I'm using Mac OSX as well.

Steven Murray
Posts: 3
Joined: April 02 2013
Affiliation: ICRAR UWA

CAMB-Python Interface

Post by Steven Murray » April 04 2013

Hi again,

It all worked well! I am using March2013 version of camb and the only thing I had to change for it to work was to change the library link to -lcamb_recfast rather than just -lcamb (I guess the name has changed in the last while).

I am looking to use this code within another project of mine which is a flexible program to find the halo mass function. Wold it be okay if I copied your link to the code?

Joe Zuntz
Posts: 9
Joined: October 22 2004
Affiliation: UCL

CAMB-Python Interface

Post by Joe Zuntz » April 05 2013

Hi all,

There is an updated version of this code, available at:
https://github.com/joezuntz/pycamb

(special thanks to github user rainwoodman for packaging and similar improvements!)

Post Reply