-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacknife.py
369 lines (214 loc) · 7.72 KB
/
jacknife.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#################################
import numpy as np
import matplotlib.pyplot as plt
import healpy as hp
import math as m
## JACKNIFE RESAMPLING ##
'''
- generate random catalog
- decide on: number of pieces to divide & number of cfs calculated on each piece
- run through list of (ra, dec) getting values that are within range of each piece
- calculate CF for each sub area of (ra, dec)
- do this for all pieces, keeping a sum of each CF bin
- by the end of running through lists and calculating cfs you have a list of summed up cfs
- divide the summed up values by the number of pieces to get the MEAN
'''
#--- inputs
Nrd = 1000
#1/8 of the sky
ramin = 0
ramax = 90
decmin = 0
decmax = 90
nside = 1024
raRAND_deg = np.random.uniform(ramin,ramax,Nrd)
decRAND_deg = np.random.uniform(decmin,decmax,Nrd)
phi = np.deg2rad(raRAND_deg)
theta = np.deg2rad(decRAND_deg)
i=0
list_pixels = [] #will contain pixel Identity Numbers for the points from the catalog using the healpy format
while i<len(theta): #points are grouped together into pixels of given nside resolution, to check all pixels that actually contain a point
pixelID = hp.ang2pix(nside,theta[i],phi[i]) #points in form of pixels
is_this_pix_not_new = pixelID in list_pixels #true if piexelID is in list of runned pixels
if is_this_pix_not_new == False: #if this pix is new, it appends it to the list
list_pixels.append(pixelID)
i+=1
k=0
while k<len(list_pixels): #running through list of Ids
area_ra = []#these will contain ra and dec of each Jackknife area
area_dec = []
i=0
while i<len(theta):
pixelID = hp.ang2pix(nside,theta[i],phi[i]) #getting the ids of each pixel again
if pixelID == list_pixels[k]: #if that Id is the same as one of the areas
area_ra.append(phi[i])
area_dec.append(theta[i])
i+=1
#f = open("jackArea{0}.txt".format(i), "w+")
#np.savetxt('jackArea{0}.txt'.format(k),np.array([area_ra,area_dec]).transpose(),fmt='%e',delimiter='\t')
#f.close()
#numpy savetxt
plt.scatter(area_ra,area_dec)
k+=1
#COV matrix
wmean = sum(output)/len(output)
i = 0
j = 0
norm = (N - 1 / N)
Dif =[]
while i < m.sqrt(N):
while j < sqrt(N):
Dif.append((ouput[i] - wmean)*(output[j] - wmean))
j+=1
i+=1
COV = np.matrix('1 2; 3 4')
##
plt.xlabel("RA[deg]")
plt.ylabel("DEC[deg]")
plt.title("Random catalog divided into Jackknife areas NSIDE = 1024")
plt.show()
#---------------------------------------------------------------------------------
nside = 256
data_filename= "/home/anderson/CUTE/MICE/shell_0.dat" # columns RA DEC ZPHOT
RA = np.loadtxt(data_filename, usecols=(0,))
DEC = np.loadtxt(data_filename, usecols=(1,))
phi= np.deg2rad(RA)
theta= np.deg2rad(DEC)
i=0
list_pixels = []
while i<len(theta):
pixelID = hp.ang2pix(nside,theta[i],phi[i], lonlat=True)
is_this_pix_not_new = pixelID in list_pixels
if is_this_pix_not_new == False:
list_pixels.append(pixelID)
i+=1
k=0
while k<len(list_pixels):
area_ra = []
area_dec = []
i=0
while i<len(theta):
pixelID = hp.ang2pix(nside,theta[i],phi[i], lonlat=True)
if pixelID == list_pixels[k]:
area_ra.append(phi[i])
area_dec.append(theta[i])
i+=1
#f = open("jackArea{0}.txt".format(i), "w+")
numpy.savetxt('jackArea{0}.txt'.format(i),np.array([area_ra,area_dec]).transpose(),fmt='%e',delimiter='\t')
f.close()
k+=1
#---------------------------------------------------------------------------------
#cycol = cycle('bgrcmky')
# colors: one of {'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}; 8 types
#----generating random points-------------------------------------------------------
degtorad = m.pi/180.
ramin_rad = ramin*degtorad
ramax_rad = ramax*degtorad
decmin_rad = decmin*degtorad
decmax_rad = decmax*degtorad
#rasim_rad = np.random.uniform(ramin_rad,ramax_rad,Nrd)
#decsim_rad = np.random.uniform(decmin_rad,decmax_rad,Nrd)
rasim_rad = (ramax_rad-ramin_rad)*np.array(np.random.uniform(0,1,Nrd))+ramin_rad;
decsim_rad = np.arcsin( np.array(np.random.uniform(0,1,Nrd))*(np.sin(decmax_rad)-np.sin(decmin_rad))+np.sin(decmin_rad) );
cosdec = np.cos((m.pi/2. - decsim_rad))
phi = rasim_rad
theta = decsim_rad
mapa = hp.ang2pix(nside, theta, phi, lonlat=True)
hp.mollview(mapa, title="nside=512")
#procuro por quais coordenadas então no mesmo pixel (fazendo uso dos pixels para separar)
i=0
list_pixels = []
while i<len(theta):
pixelID = hp.ang2pix(nside,theta[i],phi[i], lonlat=True)
is_this_pix_not_new = pixelID in list_pixels
if is_this_pix_not_new == False:
list_pixels.append(pixelID)
i+=1
areas.append(pixelID)
if hp.ang2pix(nside,theta[i],phi[i]) ==
i+=1
areas = [][]
while k < len(areas):
plt.scatter(copy_ra, copy_dec)
plt.xlabel("RA[rad]")
plt.ylabel("DEC[rad]")
plt.title("Random catalog divided into Jackknife areas - NSIDE = 1024")
plt.show()
#----getting vertices
lenght_ra = ramax_rad/n_pieces
lenght_dec = decmax_rad/n_pieces
vertice1 = {(decmax_rad - lenght_dec), ramin_rad}
vertice2 = {decmax_rad, ramin_rad}
vertice3 = {decmax_rad, lenght_ra}
vertice4 = {(decmax_rad - lenght_dec), lenght_ra}
#----getting the map NESTED
map_rnd = hp.ang2pix(nside, theta, phi)
hp.mollview(map_rnd, norm='hist')
plt.show()
#----find coordinates that should be UNSEEN NESTED
copy_ra = rasim_rad #this will store the full catalog with the marked coordinates
copy_dec = decsim_rad
sub_ra = []
sub_dec = []
ids2cover = []
k = 0
i = 0
where_to_remove = 0
dinamic_Nrd = Nrd
while k < n_pieces:
while i < Nrd:
if (decmax_rad - lenght_dec) < decsim_rad[i] and rasim_rad[i] < lenght_ra:
sub_ra.append(rasim_rad[i])
sub_dec.append(decsim_rad[i])
copy_ra = np.delete(copy_ra, where_to_remove)#remove
copy_dec = np.delete(copy_dec, where_to_remove)
where_to_remove -=1
where_to_remove+=1
i+=1
#---- covering each sub_section and calculating CF n_pieces times
k+=1
n_bins = 30 #30 cfs for each sub_area
CFsum = [0]*n_bins #certifying all [] are empty
plt.scatter(copy_ra, copy_dec)
plt.scatter(sub_ra,sub_dec)
plt.xlabel("RA")
plt.ylabel("DEC")
plt.grid(color = 'k', linestyle = '--', linewidth = 0.1)
plt.title("Random catalog divided into 9 Jackknife areas (area highlighted)")
plt.show()
plt.scatter(rasim_rad, decsim_rad)
plt.xlabel("RA [rad]")
plt.ylabel("DEC [rad]")
plt.title("Random points plot RA x DEC")
plt.show()
plt.scatter(rasim_rad, cosdec)
plt.xlabel("RA [rad]")
plt.ylabel("cos(pi/2 - DEC) [rad]")
plt.title("Random points plot RA x cos(pi/2 - DEC)")
plt.show()
mask_ra = rasim_rad < lenght_ra
mask_dec = decsim_rad > (decmax_rad - lenght_dec)
plt.scatter(rasim_rad[mask_ra], cosdec[mask_dec])
plt.xlabel("RA [rad]")
plt.ylabel("cos(pi/2 - DEC) [rad]")
plt.title("Random points plot RA x cos(pi/2 - DEC)")
plt.show()
### save values in a file1
### run cfs with sub_ra , sub_dec
### store found values in file2
# CF_values is an array containing the values CF medians over 10 areas
## vertices-----------------------------araquivo--------------------------mapa com cores
###-----------------------------------------------------------------------------------------------------------------------------for all areas
'''
- transform RA DEC --> theta phi [radians]
- ang2pix with chosen nside -->npix
- nside2pixarea(nside[, degrees])Gives pixel area given nside in square radians or square degrees. --> A_tot of catalog
- A_Tot/n_pieces = A_of_pieces
- find point of maximun RA or DEC (pixels?) --> starting point, a border, pixel1
- get_all_neighbours(nside, theta[, phi, ...]) Return the 8 nearest pixels --> staring at pixel1 --> keep spreading
- each pixel counted adds to a sum_of_subArea -- > once subArea = A_of_pieces you stop spreading and calculate CF for this area
problem: will it cover the whole area no matter the shape? the spread could get pluged
resolução
areas nao precisam ser iguais
'''
##