-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseparate.pro
210 lines (170 loc) · 6.82 KB
/
separate.pro
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
; This procedure separates the acquisitions into sub-folders, depending on the frequency band and the
; calibrator/skydip/target nature of the scan.
;
; The usable RF bands are hard-coded.
; The original version of this procedure considers the following bands and frequency boundaries (MHz):
;
; pbounds=[300,1000]
; lbounds=[1000,2000]
; sbounds=[2000,4000]
; cbounds=[4000,8000]
; xbounds=[8000,10000]
; kbounds=[18000,26500]
;
; If observing with more than one sub-band in the K-band RF range, specify /multiK as in
;
; IDL> separa, /multiK (in this case, kbounds=[18000,20000,23000,26500])
;
; Default flux density calibrators are considered to be 3C48, 3C123, 3C286, 3C295, NGC7027.
; When wanting to specify a custom list of calibrators, provide an external text file
; containing as columns the source names and flux densities (the same to be used when running "runcalib"),
; and then use
;
; IDL> separa, /extlist
;
; Latest update: July 6th, 2020
pro separate, multiK=multiK, extlist=extlist
print, ' '
sp=path_sep()
pin=dialog_pickfile(/DIRECTORY, title='Select main folder, containing the YYYYMMDD data folders')
print, 'Selected folder is ', pin
if not keyword_set(multiK) then Kband='single' else Kband='multi'
homecals=['3C48','3C123','3C286','3C295','NGC7027'] ; default flux density calibrators
if keyword_set(extlist) then begin
myextlist=dialog_pickfile(TITLE='Please pick EXTERNAL LIST of calibrators')
readcol, myextlist, extcalname, extcalflux, format='(A,D)', /SILENT
calname=strupcase(extcalname)
endif else begin
myextlist=' '
calname=strupcase(homecals)
endelse
; In this module the frequency bands are defined
; Users might want to add/edit some
; ***********************************************
pbounds=[300,1000]
lbounds=[1000,2000]
sbounds=[2000,4000]
cbounds=[4000,8000]
xbounds=[8000,10000]
; NOTICE: in case of editing, edit the boundaries implementation as well! Search for string "edit here" in this code.
if Kband eq 'single' then begin
bands=['P','L','S','C','X','K']
kbounds=[18000,26500]
endif else begin
bands=['P','L','S','C','X','K-low','K-mid','K-hi']
kbounds=[18000,20000,23000,26500] ; definition of sub-bands boundaries for K-band
endelse
; ***********************************************
bandnum=n_elements(bands)
mybounds=make_array(1,bandnum,/integer)
; Checking whether the folder for DAT files (produced by the CalibrationTool) exists.
; If not, it is created.
ans0=file_test(pin+'DATS',/DIRECTORY)
if ans0 eq 0 then begin
print, 'Creating subfolder for .dat files...'
file_mkdir, pin+'DATS'
endif
print, 'Creating subfolders for band-separated files...'
for b=0, bandnum-1 do begin
; Checking whether the band-dependant and type-dependant folders alreasy exist.
; If not, they are created.
ans1=file_test(pin+bands[b],/DIRECTORY)
if ans1 eq 0 then begin
file_mkdir, pin+bands[b]
endif
ans2=file_test(pin+bands[b]+sp+'CALIBRATORS',/DIRECTORY)
ans3=file_test(pin+bands[b]+sp+'TARGETS',/DIRECTORY)
ans4=file_test(pin+bands[b]+sp+'SKYDIPS',/DIRECTORY)
if ans2 eq 0 then begin
; print, 'Creating folder for '+bands[b]+'-band CALIBRATORS files'
file_mkdir, pin+bands[b]+sp+'CALIBRATORS'
endif
if ans3 eq 0 then begin
; print, 'Creating folder for '+bands[b]+'-band TARGETS files'
file_mkdir, pin+bands[b]+sp+'TARGETS'
endif
if ans4 eq 0 then begin
; print, 'Creating folder for '+bands[b]+'-band SKYDIP files'
file_mkdir, pin+bands[b]+sp+'SKYDIPS'
endif
endfor
list = FILE_SEARCH(pin+'20*', COUNT=number, /TEST_DIRECTORY)
for i=0,number-1 do begin ; loop over 'number' days
; print, list[i]
datlist = file_search(list[i]+sp+'*.dat', COUNT=datnum)
if datnum ne 0 then begin
for j=0,datnum-1 do begin
file_move, datlist[j], pin+'DATS'+sp, /OVERWRITE
endfor
endif
sublist = FILE_SEARCH(list[i]+sp+'20*', /TEST_DIRECTORY, COUNT=subnum)
for j=0,subnum-1 do begin ; loop over 'subnum' scans
subsublist = FILE_SEARCH(sublist[j]+sp+'*.fits', COUNT=subsubnum)
; obtaining info from the first subscan (i.e. the first FITS in the folder)
RFinfo=mrdfits(subsublist[0],2,/silent)
sky_bandwidth=RFinfo[0].bandWidth
sky_freq=RFinfo[0].frequency+sky_bandwidth/2.0
mainh=mrdfits(subsublist[0],0,head0,/silent)
findh0key, head0, '*SOURCE*', keylab, target, infolab, tarflag
; elaborating the target name string
target=strcompress(target, /remove_all)
cleantarget=strsplit(target,"'",/extract)
target=cleantarget[0]
; directing the file to the proper location
type='TARGETS'+sp ; default choice
checkcal=where(strupcase(target) eq calname, isitcal)
if isitcal ne 0 then begin
type = 'CALIBRATORS'+sp ; overriding the default choice: the source is a calibrator
if subsubnum eq 2 then begin ; to handle cases when SKYDIPS have been mis-named
data=mrdfits(subsublist[0],4,/SILENT)
span=abs(data[0].el-data[-1].el)
if span gt 45.0/180.0*!dpi then type = 'SKYDIPS'+sp
endif
endif
if (strmatch(sublist[j],'*sky*',/FOLD_CASE)) then type = 'SKYDIPS'+sp ; overriding the default choice: the file is a SKYDIP
; actually moving the folders
if (i eq 0) and (j eq 0) then print, 'Moving files...'
for b=0, bandnum-1 do begin
case bands[b] of
; edit here in case you need to add more bands
'P': mybounds=pbounds
'L': mybounds=lbounds
'S': mybounds=sbounds
'C': mybounds=cbounds
'X': mybounds=xbounds
'K': mybounds=kbounds
'K-low': mybounds=[kbounds[0],kbounds[1]]
'K-mid': mybounds=[kbounds[1],kbounds[2]]
'K-hi': mybounds=[kbounds[2],kbounds[3]]
endcase
intervals=n_elements(mybounds)-1
for int=0, intervals-1 do begin
if (sky_freq ge mybounds[int] and sky_freq lt mybounds[int+1]) then begin
outband = pin+bands[b]+sp
file_move, sublist[j], outband+type, /OVERWRITE
break
endif
endfor
endfor
endfor ; ending cycle on scans
endfor; ending cycle on days
; removing empty/unused folders (the non-empty ones will be by default spared!)
print, 'Removing empty subfolders...'
for b=0, bandnum-1 do begin
file_delete, pin+bands[b]+sp+'CALIBRATORS',/quiet
file_delete, pin+bands[b]+sp+'TARGETS',/quiet
file_delete, pin+bands[b]+sp+'SKYDIPS',/quiet
file_delete, pin+bands[b]+sp,/quiet
endfor
file_delete, pin+'DATS',/quiet
tobedel=file_search(pin+'20*', /TEST_DIRECTORY, count=delnum)
for dn=0, delnum-1 do begin
file_delete, tobedel[dn],/quiet
endfor
print, ' '
print, '**********'
print, ' DONE '
print, '**********'
print, ' '
return
end