-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cosmo.py
56 lines (43 loc) · 1.65 KB
/
Cosmo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
Copied from Julian Bautista
'''
import numpy as N
class Cosmo:
def __init__(self, OmegaM=0.31, h=0.676):
print 'Initializing cosmology with OmegaM = %.2f'%OmegaM
c = 299792458. #m/s
OmegaL = 1.-OmegaM
ztab = N.linspace(0., 4., 10000)
E_z = N.sqrt(OmegaL + OmegaM*(1+ztab)**3)
rtab = N.zeros(ztab.size)
for i in range(1, ztab.size):
rtab[i] = rtab[i-1] + c*1e-3 * (1/E_z[i-1]+1/E_z[i])/2. * (ztab[i]-ztab[i-1]) / 100.
self.h = h
self.c = c
self.OmegaM = OmegaM
self.OmegaL = OmegaL
self.ztab = ztab
self.rtab = rtab
#-- comoving distance in Mpc/h
def get_comoving_distance(self, z):
return N.interp(z, self.ztab, self.rtab)
def get_redshift(self, r):
return N.interp(r, self.rtab, self.ztab)
#-- comoving spherical volume between zmin and zman in (Mpc/h)**3
def shell_vol(self, zmin, zmax):
rmin = self.get_comoving_distance(zmin)
rmax = self.get_comoving_distance(zmax)
return 4*N.pi/3.*(rmax**3-rmin**3)
def get_box_size(self, ra, dec, zmin=0.5, zmax=1.0):
dmin = get_comoving_distance(zmin)
dmax = get_comoving_distance(zmax)
theta = (-dec+90)*N.pi/180.
phi = (ra)*N.pi/180
xmin = dmin * N.sin(theta)*N.cos(phi)
ymin = dmin * N.sin(theta)*N.sin(phi)
zmin = dmin * N.cos(theta)
xmax = dmax * N.sin(theta)*N.cos(phi)
ymax = dmax * N.sin(theta)*N.sin(phi)
zmax = dmax * N.cos(theta)
for pair in [[xmin, xmax], [ymin, ymax], [zmin, zmax]]:
print abs(N.array(pair).min() - N.array(pair).max())