forked from deapplegate/wtgpipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanja_plots.py
234 lines (139 loc) · 6.54 KB
/
anja_plots.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
###################
# Plots asked for by Anja for her Mar 2012 ESO proposal
###################
import publication_plots as pp
import cPickle
from dappleutils import readtxtfile
import pylab, numpy as np
import nfwutils, compare_masses as cm
import maxlike_secure_bentstep3_voigt_driver as driver
###################
def precisionZ(data = None):
#mass precision as a function of redshift
if data is None:
data = {}
if 'fracerrs' not in data:
items = [tuple(x) for x in readtxtfile('worklist')]
allmasses = cm.readDougMasses('/u/ki/dapple/subaru/doug/publication/baseline_2012-05-17')
redshifts = cm.readClusterRedshifts()
clusters = [x[0] for x in items]
properz = np.array([redshifts[x] for x in clusters])
masses, errs = cm.constructMassArray(allmasses, items)
fracerrs = errs / masses
aveerrs = np.mean(fracerrs, axis=0)
data['aveerrs'] = aveerrs
data['properz'] = properz
ccitems = [tuple(x) for x in readtxtfile('referenceset')]
ccmasses = cm.readAnjaMasses()
clusters = [x[0] for x in ccitems]
ccproperz = np.array([redshifts[x] for x in clusters])
data['ccproperz'] = ccproperz
masses, errs = cm.constructMassArray(ccmasses, ccitems)
fracerrs = errs/masses
ccaveerrs = np.mean(fracerrs, axis=0)
data['ccaveerrs'] = ccaveerrs
else:
aveerrs = data['aveaerrs']
properz = data['properz']
ccaveerrs = data['ccaveerrs']
ccproperz = data['ccproperz']
fig = pylab.figure()
ax = fig.add_axes([0.12, 0.12, 0.95-0.12, 0.95-0.12])
ax.plot(ccproperz, ccaveerrs, 'bo', label = 'Color-Cut', mfc = 'None', mew = 1.0, mec='b')
ax.plot(properz, aveerrs, 'rD', label = 'P($z$)')
ax.set_xlabel('Cluster Redshift')
ax.set_ylabel('Fractional Statistical Uncertainty M(r$<$1.5Mpc)')
ax.set_xlim([0.14, 0.72])
ax.legend(loc='upper left', numpoints = 1)
fig.savefig('publication/aveerr_redshift.eps')
return fig, data
##########################
def galdensity(data = None):
if data is None:
data = {}
if 'ngals' not in data:
ngals = cPickle.load(open('galaxy_counts_pzmethod.pkl', 'rb'))
data['ngals'] = ngals
items = [tuple(x) for x in readtxtfile('worklist')]
clusters = [x[0] for x in items]
redshifts = cm.readClusterRedshifts()
properz = np.array([redshifts[x] for x in clusters])
data['properz'] = properz
Dl = np.array([nfwutils.angulardist(z) for z in properz])
data['Dl'] = Dl
inner_rad = np.arctan2(0.75, Dl) * (180./np.pi) * 60
outer_rad = np.arctan2(3., Dl) * (180 / np.pi) * 60
area = np.pi*(outer_rad**2 - inner_rad**2)
data['area'] = area
propercounts = np.array([ngals[x] for x in items])
density = propercounts / area
data['density'] = density
else:
properz = data['properz']
density = data['density']
fig = pylab.figure()
ax = fig.add_axes([0.12, 0.12, 0.95 - 0.12, 0.95 - 0.12])
ax.plot(properz, density, 'bo')
ax.set_xlabel('Cluster Redshift')
ax.set_ylabel('Input Galaxy Density')
return fig, data
######################################
def lostgals(data = None):
if data is None:
data = {}
items = readtxtfile('worklist')
del items[-1]
clusters = [x[0] for x in items]
if 'properz' not in data:
redshifts = cm.readClusterRedshifts()
properz = np.array([redshifts[x] for x in clusters])
data['properz'] = properz
else:
properz = data['properz']
if 'properbase' not in data:
basecuts = {}
for cluster, filter, image in items:
controller = driver.makeController()
options, args = controller.modelbuilder.createOptions()
options, args = controller.filehandler.createOptions(options = options, args = args,
workdir = '/u/ki/dapple/ki06/catalog_backup_2012-02-08',
incatalog = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.lensingbase.cat' % (cluster, filter, image),
cluster = cluster, filter = filter, image = image,
redseqcat = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.redsequence.cat' % (cluster, filter, image), shapecut = True)
controller.load(options, args)
basecuts[cluster] = controller.ngalaxies
data['basecuts'] = basecuts
properbase = np.array([basecuts[x[0]] for x in items])
data['properbase'] = properbase
else:
properbase = data['properbase']
if 'properloose' not in data:
loosecuts = {}
for cluster, filter, image in items:
controller = driver.makeController()
options, args = controller.modelbuilder.createOptions(deltaz95high = 9999, zbhigh = 9999)
options, args = controller.filehandler.createOptions(options = options, args = args,
workdir = '/u/ki/dapple/ki06/catalog_backup_2012-02-08',
incatalog = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.lensingbase.cat' % (cluster, filter, image),
cluster = cluster, filter = filter, image = image,
redseqcat = '/u/ki/dapple/ki06/catalog_backup_2012-02-08/%s.%s.%s.redsequence.cat' % (cluster, filter, image), shapecut = True)
controller.load(options, args)
loosecuts[cluster] = controller.ngalaxies
data['loosecuts'] = loosecuts
properloose = np.array([loosecuts[x[0]] for x in items])
data['properloose'] = properloose
else:
properloose = data['properloose']
if 'ratio' not in data:
ratio = 1 - (properbase.astype('float64') / properloose)
data['ratio'] = ratio
else:
ratio = data['ratio']
fig = pylab.figure()
ax = fig.add_axes([0.12, 0.12, 0.95 - 0.12, 0.95 - 0.12])
ax.plot(properz, ratio, 'bo')
ax.set_xlim([0.16, 0.72])
ax.set_xlabel('Cluster Redshift')
ax.set_ylabel('Fraction of Catalog Discarded')
return fig, data
######################################