Skip to content

Commit

Permalink
API Change: no numerical errors returned by distance funcs. swig not …
Browse files Browse the repository at this point in the history
…required.

I've never found the numerical errors returned by the numerical
integration routines used in the distance.py functions to be useful or
accurate, so I'm no longer returning them. This should streamline
usage of these function considerably.

I also changed setup.py and included the swig-generated power_wrap.c
and power.py so that swig is no longer required to compile the
package.

	modified:   .gitignore
	modified:   LISCENSE
	modified:   README
	new file:   cosmolopy/EH/README
	deleted:    cosmolopy/EH/install_EH.bash
	deleted:    cosmolopy/EH/installation.txt
	new file:   cosmolopy/EH/power.py
	new file:   cosmolopy/EH/power_wrap.c
	modified:   cosmolopy/constants.py
	modified:   cosmolopy/distance.py
	modified:   cosmolopy/reionization.py
	deleted:    setup.cfg
	modified:   setup.py
	modified:   tests/test_age.py
	modified:   tests/test_distances.py
	modified:   tests/test_plot_Hogg.py
	modified:   tests/test_wmap.py
	modified:   www/index.html
	new file:   pypi_notes.txt
  • Loading branch information
roban committed Nov 25, 2010
1 parent 150f3cf commit 7124b1d
Show file tree
Hide file tree
Showing 19 changed files with 4,092 additions and 143 deletions.
6 changes: 2 additions & 4 deletions .gitignore
@@ -1,10 +1,8 @@
*~ *~
.coverage .coverage
*.pyc *.pyc
cosmolopy/EH/power.o cosmolopy/EH/*.o
cosmolopy/EH/power.py* cosmolopy/EH/*.so
cosmolopy/EH/_power.so
cosmolopy/EH/power_wrap.*
CosmoloPy.egg-info/ CosmoloPy.egg-info/
build/ build/
dist/ dist/
2 changes: 1 addition & 1 deletion LISCENSE
@@ -1,6 +1,6 @@
The MIT License The MIT License


Copyright (c) 2009 Roban Hultman Kramer and contributors Copyright (c) 2009-2010 Roban Hultman Kramer and contributors
http://roban.github.com/CosmoloPy/ http://roban.github.com/CosmoloPy/


Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
41 changes: 36 additions & 5 deletions README
@@ -1,3 +1,4 @@
=========
CosmoloPy CosmoloPy
========= =========


Expand All @@ -15,23 +16,53 @@ Calculate the comoving distance to redshift 6.


>>> import cosmolopy.distance as cd >>> import cosmolopy.distance as cd
>>> cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72} >>> cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72}
>>> d_co, err = cd.comoving_distance(6., **cosmo) >>> d_co = cd.comoving_distance(6., **cosmo)
>>> print "Comoving distance to z=6 is %.1f Mpc" % (d_co) >>> print "Comoving distance to z=6 is %.1f Mpc" % (d_co)
Comoving distance to z=6 is 8017.8 Mpc Comoving distance to z=6 is 8017.8 Mpc




Prerequisites Prerequisites
------------ =============

Python Python
NumPy NumPy
SciPy SciPy


For tests: For tests:
nose nose
matplotlib matplotlib


For power spectrum calculation (needed for most of perturbation module): For power spectrum calculation (needed for most of perturbation module):
python-dev python-dev
swig


Installation of Prerequisites under Ubuntu
------------------------------------------

> sudo apt-get install python-numpy python-scipy python-matplotlib
> sudo apt-get install python-dev

Installation from PYPI
======================

You can easily install the pacakge directly from the Python Package
Index with easy_install or pip.

Run either:

> sudo easy_install cosmolopy

Or:

> sudo pip install cosmolopy

Installation from Source
========================

If you've downloaded the source, install it by running

> sudo pyton setup.py install

Testing
=======


> python setup.py nosetests
35 changes: 35 additions & 0 deletions cosmolopy/EH/README
@@ -0,0 +1,35 @@
Original c code
===============

power.c is redistributed under the MIT License with the permission of
Wayne Hu

htt://background.uchicago.edu/~whu/transfer/transferpage.html

and is described in Eisenstein, D. J., & Hu, W. "Power Spectra for
Cold Dark Matter and Its Variants," 1999, ApJ, 511, 5
[astro-ph/9710252]. Please cite this paper to acknowledge use of power
spectrum calculations.

See LISCENSE file.

Python Interface
================

I use swig to generate the python interface to `power.c`.

`power_wrap.c` and `power.py` are created from `power.i` and `power.c`
by runing:

> swig -python power.i

I used to let distutils run swig, but that stopped working for some
reason. The code was:

power_module = Extension('cosmolopy.EH._power',
sources=[os.path.join(eh_dir, 'power.i'), os.path.join(eh_dir,
'power.c')])

I still let distutils do the compiling to create `_power.so`. This has
the advantage of not requiring the user to install swig.

6 changes: 0 additions & 6 deletions cosmolopy/EH/install_EH.bash

This file was deleted.

29 changes: 0 additions & 29 deletions cosmolopy/EH/installation.txt

This file was deleted.

83 changes: 83 additions & 0 deletions cosmolopy/EH/power.py
@@ -0,0 +1,83 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.40
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
# This file is compatible with both classic and new-style classes.

from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_power', [dirname(__file__)])
except ImportError:
import _power
return _power
if fp is not None:
try:
_mod = imp.load_module('_power', fp, pathname, description)
finally:
fp.close()
return _mod
_power = swig_import_helper()
del swig_import_helper
else:
import _power
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)

def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0



def TFmdm_set_cosm(*args):
return _power.TFmdm_set_cosm(*args)
TFmdm_set_cosm = _power.TFmdm_set_cosm

def TFmdm_onek_mpc(*args):
return _power.TFmdm_onek_mpc(*args)
TFmdm_onek_mpc = _power.TFmdm_onek_mpc

def TFmdm_onek_hmpc(*args):
return _power.TFmdm_onek_hmpc(*args)
TFmdm_onek_hmpc = _power.TFmdm_onek_hmpc

cvar = _power.cvar

0 comments on commit 7124b1d

Please sign in to comment.