# CosmoloPy: Cosmology Routines for Python

by on September 17, 2009

This is a guest post by Roban Hultman Kramer, who is currently an astronomy grad student at Columbia University and will be starting as a Zwicky Fellow at ETH Zurich in January.

CosmoloPy is a package of basic cosmology routines for Python, designed for use with NumPy and SciPy. Features currently include: calculation of cosmological distance measures, perturbation-theory-based calculation of the matter power spectrum and halo collapse fraction (courtesy of Eisenstein & Hu’s transfer function code), and integration of simple reionization models and the resulting electron scattering optical depth due to reionization. I hope it will prove useful to the increasing number of astronomers turning to Python. Read on to find out more.

Using CosmoloPy is as simple as setting up a dictionary of cosmological parameters (some WMAP5 parameters are provided for convenience in cosmolopy.parameters) and passing it to the functions you want to use. For instance, we could quickly calculate the comoving distance to redshift 6 like this:
 >>> import cosmolopy.distance as cd >>> cosmo = {'omega_M_0' : 0.3, ... 'omega_lambda_0' : 0.7, ... 'h' : 0.72} >>> d_co, err = cd.comoving_distance(z=6., **cosmo) >>> print "Comoving distance to z=6 is %.1f Mpc" % (d_co) Comoving distance to z=6 is 8017.8 Mpc 

A few more lines of code, and you can produce a plot like the one shown above.
CosmoloPy is released under the MIT software license, which allows it to be freely used and modified. So please download it, use it, and request or add features you’d like to see included (and point out bugs we need to fix). Anyone can access the git repository, so please edit the code and send in useful changes and additions. All questions about use or development can be posted to the developer discussion group.