-
Notifications
You must be signed in to change notification settings - Fork 2
/
rebin_euclid.py
executable file
·64 lines (53 loc) · 1.66 KB
/
rebin_euclid.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
57
58
59
60
61
62
63
64
#!/usr/bin/python
"""
Re-bin Euclid n(z)
"""
import numpy as np
import pylab as P
import scipy.integrate
import radiofisher as rf
# Precompute cosmo fns.
cosmo_fns = rf.background_evolution_splines(rf.experiments.cosmo)
HH, rr, DD, ff = cosmo_fns
expt = rf.experiments_galaxy.EuclidRef
def vol(zmin, zmax):
"""
Calculate volume of redshift bin.
"""
C = 3e5
_z = np.linspace(zmin, zmax, 1000)
vol = C * scipy.integrate.simps(rr(_z)**2. / HH(_z), _z)
vol *= 4. * np.pi
return vol
# Load Euclid n(z) and b(z)
e = rf.experiments_galaxy.load_expt(expt)
nz = expt['nz']
zmin = expt['zmin']
zmax = expt['zmax']
zc = 0.5*(zmax + zmin)
# Get volume for each bin
v = np.array( [vol(zmin[i], zmax[i]) for i in range(zmin.size)] )
# Rebin in dz=0.3 bins
i = np.arange(zmin.size)
j = i // 3 # 3 small bins per big bin
print j
# Calculate new n(z) bins by volume-weighted averaging
new_nz = [ np.sum( nz[np.where(j==jj)] * v[np.where(j==jj)] )
/ np.sum( v[np.where(j==jj)] )
for jj in range(np.max(j)+1) ]
new_nz = np.array(new_nz)
# Calculate new z bin edges
new_zmin = np.array([ np.min(zmin[np.where(j==jj)]) for jj in range(np.max(j)+1) ])
new_zmax = np.array([ np.max(zmax[np.where(j==jj)]) for jj in range(np.max(j)+1) ])
new_zc = 0.5 * (new_zmin + new_zmax)
for i in range(nz.size):
print i, zmin[i], zmax[i], nz[i]
print "-"*50
for i in range(new_nz.size):
print i, new_zmin[i], new_zmax[i], new_nz[i]
# Plot
P.subplot(111)
P.errorbar(zc, nz, xerr=0.5*(zmax-zmin), color='r', lw=1.5, marker='.', ls='none')
P.errorbar(new_zc, new_nz, xerr=0.5*(new_zmax-new_zmin), color='b', lw=1.5, marker='.', ls='none')
P.yscale('log')
P.show()