-
Notifications
You must be signed in to change notification settings - Fork 0
/
chipreg.py
169 lines (104 loc) · 4.08 KB
/
chipreg.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
# PURPOSE: combinr point source regions with field of view regions,
# PURPOSE: to create a region with the right observed area
import centradec
import pycrates as cr
import numpy as nn
import os
import pdb
def make(clu, ob, r1mpc, ctsIN0, ctsIN1, ctsIN2, ctsIN3, ctsIN5, ctsIN6, ctsIN7, ctsOUT0, ctsOUT1, ctsOUT2, ctsOUT3, ctsOUT5, ctsOUT6, ctsOUT7) :
(rac, decc) = centradec.getrd('mfe_'+clu)
instr = 'circle('+rac+','+decc+','+str(r1mpc/10)+'")'
outstr= 'annulus('+rac+','+decc+','+str(r1mpc/10)+'",'+str(r1mpc)+'")'
bgstr = 'circle('+rac+','+decc+','+str(r1mpc)+'")'
regfits = cr.read_file('mfe_'+clu+'/reg/chipsreg'+ob+'.fits')
rx = cr.copy_colvals(regfits, 'x')
ry = cr.copy_colvals(regfits, 'y')
rccd = cr.copy_colvals(regfits, 'ccd_id')
# POINT SOURCES WITH A MINUS SIGN FOR EXCLUSION
filept = open('mfe_'+clu+'/reg/pt0mfe_wcs.reg','r')
linept=filept.readline()
linept=filept.readline()
exclpt=''
while linept != '' and linept != '\n' :
exclpt = exclpt + ' -' + linept
linept=filept.readline()
filept.close()
#HI-BG corner region
hibgbool=False
if os.path.exists('mfe_'+clu+'/reg/hibgcorner'+ob+'.reg') :
hibgbool=True
filecorner=open('mfe_'+clu+'/reg/hibgcorner'+ob+'.reg', 'r')
hibgreg=filecorner.readline()
filecorner.close()
# combine ptsrcs and hi bg corner
fileexc = open('mfe_'+clu+'/reg/exclpt'+ob+'.reg', 'w')
fileexc.write(exclpt)
if hibgbool : fileexc.write(hibgreg)
fileexc.close()
acisiccds='0123'
# OBSERVATIONS WITH CHIPS 0,1,2,3 -- IN region
if ctsIN0+ctsIN1+ctsIN2+ctsIN3 >= 40 :
file1= open( 'mfe_'+clu+'/reg/in2_'+ob+'_ccdi.reg', 'w')
for ii in range(len(rccd)) :
if str(rccd[ii]) in acisiccds :
sstr = '+polygon('
for jj in range(rx.shape[1]) :
if nn.isfinite(rx[ii,jj]) :
if jj==0 : sstr = sstr + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
else : sstr = sstr + ',' + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
sstr = sstr + ')'
file1.write( sstr + ' * ' + instr )
if hibgbool : file1.write( exclpt + ' -' + hibgreg)
else : file1.write( exclpt )
file1.close()
# OBSERVATIONS WITH CHIPS 0,1,2,3 -- OUT/BG regions
if ctsOUT0+ctsOUT1+ctsOUT2+ctsOUT3 >= 500 :
file2= open( 'mfe_'+clu+'/reg/out2_'+ob+'_ccdi.reg', 'w')
file3= open( 'mfe_'+clu+'/reg/bg2_'+ob+'_ccdi.reg', 'w')
for ii in range(len(rccd)) :
if str(rccd[ii]) in acisiccds :
sstr = '+polygon('
for jj in range(rx.shape[1]) :
if nn.isfinite(rx[ii,jj]) :
if jj==0 : sstr = sstr + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
else : sstr = sstr + ',' + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
sstr = sstr + ')'
file2.write( sstr + ' * ' + outstr )
if hibgbool : file2.write( exclpt + ' -' + hibgreg)
else : file2.write( exclpt )
file3.write( sstr + ' * ' + bgstr )
if hibgbool : file2.write( exclpt + ' -' + hibgreg)
else : file2.write( exclpt )
file2.close()
file3.close()
# OBSERVATIONS WITH CHIPS 5, 6 AND 7
chipv=[5,6,7] # ---> must be integer!!
regionname=['in2', 'out2', 'bg2']
regionstr=[instr, outstr, bgstr]
mincounts=[ 40, 500, 500 ]
cts = nn.zeros( (len(regionname),len(chipv)) )
cts[0,0]= ctsIN5
cts[1,0]= ctsOUT5
if ctsIN5 >= 40 or ctsOUT5 >= 500 : cts[2,0]= 500+1
cts[0,1]= ctsIN6
cts[1,1]= ctsOUT6
if ctsIN6 >= 40 or ctsOUT6 >= 500 : cts[2,1]= 500+1
cts[0,2]= ctsIN7
cts[1,2]= ctsOUT7
if ctsIN7 >= 40 or ctsOUT7 >= 500 : cts[2,2]= 500+1
for ichip in range(len( chipv )) :
chip=chipv[ichip]
for ireg in range(len(regionname)) :
if cts[ireg, ichip] >= mincounts[ireg] :
for ii in range(len(rccd)) :
if rccd[ii] == chip :
file1 = open( 'mfe_'+clu+'/reg/'+regionname[ireg]+'_'+ob+'_ccd'+str(chip)+'.reg', 'w')
sstr='+polygon('
for jj in range(rx.shape[1]) :
if nn.isfinite(rx[ii,jj]) :
if jj == 0 : sstr = sstr + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
else : sstr = sstr + ',' + str(rx[ii,jj]) + ',' + str(ry[ii,jj])
sstr = sstr + ')'
file1.write( sstr + ' * ' + regionstr[ireg] )
file1.write( exclpt )
file1.close()