-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalib_301.cl
executable file
·238 lines (190 loc) · 6.08 KB
/
calib_301.cl
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
#
# Ver 2.0, 13nov05
#
# Changes: 1) proceduro to U filter now
# 2) swap.tol parameter defined by calib_301 now
#
procedure calib_301
string pre = "s" {prompt="Preffix of dark images"}
string suf = "1" {prompt="Suffix of flat images (excluding the last 0 character)"}
bool trim = yes {prompt="Trim the images?"}
bool texpcor = yes {prompt="Check the *real* integration time?"}
real tol = 2. {prompt="Exptime error tolerance (%)"}
bool headcor = no {prompt="Reset exptime values in headers?"}
string trimsec = "301s" {prompt="Trim data section"}
string texpdarks = "" {prompt="Real dark exptimes (format xx.x; *00.0* to use header value)"}
string texpflats = "uu.u bb.b vv.v rr.r ii.i" {prompt="Real flat exptimes (*00.0* to use header value)"}
struct *flist1
struct *flist2
# ABOUT texpdarks and texpflats parameters:
# Example: if there are n = 5 dark images, "texpdarks" format allways must be "t1 t2 t3 t4 t5" (since headcor=yes),
# even if the values of four last darks are correct in respectives images. Thereby, texpdarks must be explicitly "t1 00.0 00.0 00.0 00.0".
# The values must correspond to exptimes of the directories in alphabetical order
begin
string temp1, temp2, item
string image, lixo, trimseci, directory, darkpath, filter[5]
real texp, darktime
int i
filter[1]="u"
filter[2]="b"
filter[3]="v"
filter[4]="r"
filter[5]="i"
#Pre-defined trim sections
trimseci = trimsec
if(trimsec == "301b") {
trimseci = "[15:385,10:270]"
}
if(trimsec == "301s") {
trimseci = "[15:200,1:170]"
}
if(trimsec == "301m") {
trimseci = "[15:160,1:130]"
}
if(trimsec == "301a") {
trimseci = "[15:250,1:170]"
}
if(trimsec == "301n") {
trimseci = "[15:140,1:120]"
}
#Clean the routines parameters
unlearn flatcombine
unlearn darkcombine
unlearn ccdproc
flatcombine.delete = yes
flatcombine.ccdtype = ""
darkcombine.delete = yes
darkcombine.ccdtype = ""
ccdproc.ccdtype = ""
ccdproc.fixpix = no
ccdproc.overscan = no
ccdproc.trim = trim
ccdproc.flatcor = no
ccdproc.darkcor = no
ccdproc.zerocor = no
ccdproc.trimsec = trimseci
swap.tol = tol
# Procedure to combine darks
if(access("dark")) {
chdir("dark")
temp1 = mktemp("../dark_list")
imdel(images=pre//"*.fits", verify=no, >& "dev$null")
files(pre//"*"//"0", > temp1)
flist1 = temp1
i = 1
#Loop on the dark directories
while(fscanf(flist1, "%3c %c", directory, lixo) != EOF) {
chdir(directory//"0")
imdel(images="*.fits", verify=no, >& "dev$null")
# Obtaining exptime of images
texp = 0.
if(headcor) {
item = substr(texpdarks,1+(i-1)*5,5+(i-1)*5)
lixo = fscan(item,texp)
# print(texpdarks)
# print(texp)
}
# Case headcor=no or current parameter from texpdarks equals zero
if(texp == 0) {
temp2 = mktemp("../templist")
files(pre//"*", > temp2)
flist2 = temp2
lixo = fscan(flist2, image)
delete(temp2, ver-, >& "dev$null")
swap(image, tcheck=no)
temp2 = mktemp("tempexp")
hselect(images=image//".fits", fields="EXPTIME", expr=yes, > temp2)
flist2 = temp2
lixo = fscan(flist2, texp)
delete(temp2, ver-, >& "dev$null")
imdel(images=image//".fits", verify=no, >& "dev$null")
}
print(directory//": Exptime "//texp//"s")
print(directory//": Extracting dark imagens with swap...")
if(texpcor)
swap(directory//"*", exptime=texp, tcheck=yes)
else
swap(directory//"*", tcheck=no)
print(directory//": Combining dark images with darkcombine...")
darkcombine("*.fits", output="../"//directory//"avg.fits")
hedit(images="../"//directory//"avg.fits", fields="DARKTIME", value=texp, verify=no, add=yes)
print("")
chdir("..")
i = i + 1
}
delete(temp1, ver-, >& "dev$null")
chdir("..")
}
# Procedure to combine flats
if(access("flat")) {
chdir("flat")
imdel(images="f*"//suf//"avg.fits", verify=no, >& "dev$null")
#Loop on the flat directories
for(i = 1; i < 6; i=i+1) {
directory = "f"//filter[i]//suf
if(! access(directory//"0"))
next
chdir(directory//"0")
imdel(images="*.fits", verify=no, >& "dev$null")
ccdproc.darkcor = no
# Obtaining exptimes of images
texp = 0
if(headcor) {
item = substr(texpflats,1+(i-1)*5,5+(i-1)*5)
lixo = fscan(item,texp)
}
# Case headcor=no or current parameter from texpflats equals zero
if(texp == 0) {
temp2 = mktemp("../templist")
files(directory//"*", > temp2)
flist2 = temp2
lixo = fscan(flist2, image)
delete(temp2, ver-, >& "dev$null")
swap(image, tcheck=no)
temp2 = mktemp("tempexp")
hselect(images=image//".fits", fields="EXPTIME", expr=yes, > temp2)
flist2 = temp2
lixo = fscan(flist2, texp)
delete(temp2, ver-, >& "dev$null")
imdel(images=image//".fits", verify=no, >& "dev$null")
}
print(directory//": Exptime "//texp//"s")
print(directory//": Extracting flat imagens with swap...")
if(texpcor)
swap(directory//"*", exptime=texp, tcheck=yes)
else
swap(directory//"*", tcheck=no)
if(access("../../dark")) {
temp2 = mktemp("../dark_base")
files("../../dark/"//pre//"*.fits", > temp2)
flist2 = temp2
# Loop on the dark images to find what to substract of corrent flat
# cat(temp2)
while(fscan(flist2, darkpath) != EOF){
temp1 = mktemp("darktemp")
hselect(images=darkpath, fields="DARKTIME", expr=yes, > temp1)
flist1 = temp1
lixo = fscan(flist1, darktime)
delete(temp1, ver-, >& "dev$null")
if(texp == darktime) {
ccdproc.darkcor = yes
ccdproc.dark = darkpath
break
}
}
}
# Only enables the dark correction if was found the correct dark image in loop above
if(ccdproc.darkcor)
print(directory//": Combining flat images with flatcombine, using dark "//darkpath//"...")
else
print(directory//": Combining flat images with flatcombine, WITHOUT dark subtraction...")
flatcombine("*.fits", output="../"//directory//"avg.fits")
delete(temp2, ver-, >& "dev$null")
print("")
chdir("..")
}
chdir("..")
}
flist1 = ""
flist2 = ""
end