-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheorio.py
executable file
·151 lines (130 loc) · 4.68 KB
/
eorio.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
###Imports
import matplotlib.pyplot as plt
import math
import sys
import string
import eorpy
import eormodel
import numpy as np
em = eormodel.modelData()
print 'loading eorio'
def plotSensitivity(eor,fignum=1,color=None,label='auto',linewidth=2):
"""plot sensitivity"""
if label == 'auto':
label = '%s z=%.0f' % (eor.config,eor.z)
print 'EORIO.PY: Note that to get both bins and lines, you need to run with plotBins first'
little_h = eor.h
edgeLeft = eorpy.edgeLeft
ctr = eorpy.ctr
edgeRight = eorpy.edgeRight
plt.figure(fignum)
panels=False
if panels:
if eor.z < 4.5:
plt.subplot(121)
else:
plt.subplot(122)
xdat=np.array(eor.kbin[ctr])*little_h
ydat=np.array(eor.d)
if eor.plotVersion == 'errbar':
em.plotModelData(eor,[xdat,ydat],fignum,color,linewidth)
else:
if eor.plotModel:
em.plotModelData(eor,None,fignum,color,linewidth)
if eor.plotSteps:
xdat,ydat=stepWise(eor,little_h)
if eor.plotBins:
errx,erry=errorBars(eor,little_h)
## if eor.z < 4.5:
## plt.subplot(121,xscale='log',yscale='log')
## else:
## plt.subplot(122,xscale='log',yscale='log')
if color==None:
plt.errorbar(xdat,ydat,yerr=None,xerr=errx,fmt='_')
else:
color = 'b'
plt.errorbar(xdat,ydat,yerr=None,xerr=errx,fmt='_')#,ecolor=color)
if eor.plotLines:
if color==None:
plt.loglog(xdat,ydat,ls=eor.ltype,label=label,linewidth=linewidth)
else:
plt.loglog(xdat,ydat,color=color,ls=eor.ltype,label=label,linewidth=linewidth)
else:
plt.loglog(xdat,ydat,'+')
#if eor.plotModel:
# em.plotModelData(eor,None,fignum,color,linewidth)
plt.xlabel(r'$k$ [h$\cdot$Mpc$^{-1}$]')
#plt.ylabel(r'$\Delta^2_{CO}$ or $\Delta^2_N$ [$\mu$K$^2$]')
plt.ylabel(r'$\Delta^2_{CO}$ [$\mu$K$^2$]')
if eor.showLegend:
plt.legend(loc='upper left') #lower right')
if eor.plotMMQ: # compute approx
bmmq = eor.computeMMQboost()
dmmq = eor.computeDValues(eor.kbin[ctr],bmmq)
dmmq = eor.computeTracks(dmmq)
plt.figure(fignum)
if eor.plotLines:
plt.loglog(eor.kbin[ctr],dmmq)
else:
plt.loglog(eor.kbin[ctr],dmmq,'x')
def plotBoost(eor,fignum=2):
plt.figure(fignum)
plt.title('Boost [k vs boost]')
plt.loglog(eor.kbin[eorpy.ctr],eor.boost)
if eor.plotMMQ: # compute approx
bmmq = eor.computeMMQboost()
plt.figure(fignum)
if eor.plotLines:
plt.loglog(eor.kbin[eorpy.ctr],bmmq)
else:
plt.loglog(eor.kbin[eorpy.ctr],bmmq,'x')
def stepWise(eor,h):
stepK=[]
stepD=[]
for i in range(eor.nbin-1):
stepK.append(h*eor.kbin[eorpy.edgeLeft][i])
stepK.append(h*eor.kbin[eorpy.edgeRight][i])
stepK.append(h*eor.kbin[eorpy.edgeLeft][i+1])
stepD.append(eor.d[i])
stepD.append(eor.d[i])
stepD.append(eor.d[i+1])
return stepK,stepD
def errorBars(eor,h):
errx = []
erry = []
for i in range(eor.nbin):
errx.append(h*(eor.kbin[eorpy.edgeRight][i] - eor.kbin[eorpy.edgeLeft][i])/2.0)
erry.append(0.0)
return errx, erry
def writeData(eor,x,y,fileName='data.out'):
"""writes all x,y data to file"""
fp = open(fileName,"w")
for i,v in enumerate(x):
s = str(v)+'\t'+str(y[i])+'\n'
fp.write(s)
fp.close()
return i
def drawBins(eor,thetaStep=1,fignum=100,plotBins=True,writeBins=False,span=360.0,color='k'):
"""Generates the circles corresponding to the kedge bins: bins[ [x,y] ]
thetaStep in degrees"""
bins = []
ntheta = int(math.ceil(span/thetaStep)) + 1
for k in eor.kbin[eorpy.edgeLeft]:
x = []
y = []
for i in range(ntheta):
x.append(k*math.cos(i*thetaStep*math.pi/180.0))
y.append(k*math.sin(i*thetaStep*math.pi/180.0))
d = [x,y]
bins.append(d)
print "plot(eor.bins[nedge][0],eor.bins[nedge][1])"
if writeBins:
for i in range(len(eor.kbin[eorpy.edgeLeft])):
filename = 'circ'+str(i)+'.dat'
print "Writing "+filename
eor.writeData(bins[i][0],bins[i][1],filename)
if plotBins:
plt.figure(fignum)
for i in range(len(eor.kbin[eorpy.edgeLeft])):
plt.plot(bins[i][0],bins[i][1],color)
return ntheta