-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamine_hera_data.pro
More file actions
317 lines (261 loc) · 7.57 KB
/
examine_hera_data.pro
File metadata and controls
317 lines (261 loc) · 7.57 KB
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
pro examine_hera_data, file $
, flagged=flagged $
, use_windows=use_windows $
, sm=sm $
, median=use_med $
, pos = pos $
, rad = rad $
, fts = fts
;+
; NAME:
;
; examine_hera_data
;
; PURPOSE:
;
; An sort-of-interactive tool to browse through a HERA spectra data
; structure. Intended to be used to identify and flag pathological pixels,
; scans, etc. and to get an idea of whether an increase in baseline order is
; needed.
;
; CATEGORY:
;
; Data reduction tool.
;
; CALLING SEQUENCE:
;
; examine_hera_data, "some_hera_data.fits", sm=[25], /blank
;
; INPUTS:
;
;
;
; OPTIONAL INPUTS:
;
;
;
; KEYWORD PARAMETERS:
;
;
;
; OUTPUTS:
;
;
;
; OPTIONAL OUTPUTS:
;
;
;
; COMMON BLOCKS:
;
;
;
; SIDE EFFECTS:
;
;
;
; RESTRICTIONS:
;
;
;
; PROCEDURE:
;
;
;
; EXAMPLE:
;
;
;
; MODIFICATION HISTORY:
;
;-
@define_hera_pixels.pro
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; SOME SMART DEFAULTS
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
if n_elements(sm) eq 0 then sm = 25
if n_elements(use_windows) eq 0 then use_windows = 1
if n_elements(flagged) eq 0 then flagged = 0
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; READ THE DATA AND EXTRACT THE PART WE ARE INTERESTED IN
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; ... DATA FILE
t = mrdfits(file,1,hdr)
; ... VELOCITY AXIS
nchan = n_elements(t[0].spectrum)
vaxis = t[0].v0 + findgen(nchan)*t[0].deltav
; ... KEEP ONLY FLAGGED/UNFLAGGED, REFERENCE-SUBTRACTED, ON-SORUCE DATA
if keyword_set(flagged) eq 0 then begin
ind = where(t.flagged eq 0 and t.on eq 1 and $
t.ref_subtracted eq 1, ct)
endif else begin
ind = where(t.flagged eq 1 and t.on eq 1 and $
t.ref_subtracted eq 1, ct)
endelse
; ... CRASH IF EMPTY
if ct eq 0 then return
t = t[ind]
; ... FOCUS ON A SPECIFIC POSITION
if n_elements(pos) gt 0 then begin
dist = sphdist(t.ra_deg, t.dec_deg, pos[0], pos[1], /deg)
if n_elements(rad) eq 0 then $
rad = 15.
ind = where(dist lt rad*1.0/3600., ct)
if ct eq 0 then return
t = t[ind]
endif
; REDUCE PIXEL LIST TO PIXELS WITH DATA
keep_pix = bytarr(npix)+1
for i = 0, npix-1 do begin
if total(t.telescop eq pixel_list[i]) eq 0 then $
keep_pix[i] = 0
endfor
pixel_list = pixel_list[where(keep_pix)]
npix = n_elements(pixel_list)
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; READ THE SPECTRAL FITTING WINDOWS INTO A MASK
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
blank_mask = (t.spectrum eq t.spectrum)*0B
if keyword_set(use_windows) then begin
; EXTRACT THE WINDOWS AS AN ARRAY OF LO-HI x NSPEC
win_arr = extract_windows(t)
win_sz = size(win_arr)
; BLANK THE DATA INSIDE THE WINDOWS
vaxis_arr = vaxis # (fltarr(ct)+1.)
for m = 0, win_sz[1]-1, 2 do begin
win_arr_lo = (fltarr(nchan) + 1.) # win_arr[m,*]
win_arr_hi = (fltarr(nchan) + 1.) # win_arr[m+1,*]
blank = where(vaxis_arr ge win_arr_lo and $
vaxis_arr le win_arr_hi, blank_ct)
if blank_ct gt 0 then blank_mask[blank] = 1B
endfor
endif
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; BROWSE DATA
; %&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&
; A NEW WINDOW
window, xsize = 1000, ysize=1000
; CURRENT STATUS OF BROWSING
all_at_once = 1B
start_index = 0L
index_increment = 1000
pixel = 0
blank = use_windows
; INITIALIZE USER INPUT
inp = ""
refresh = 1
; INPUT LOOP
while strupcase(inp) ne "Q" do begin
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; GET INPUT FROM THE MOUSE
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if strupcase(inp) eq "M" then begin
cursor, x, y
print, "Channel ", x, " Spectrum ", y
endif
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; SWAP TO/FROM AN ALL-AT-ONCE VIEW
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if strupcase(inp) eq "A" then begin
if all_at_once eq 1 then begin
all_at_once = 0
start_index = 0
refresh = 1
endif else begin
all_at_once = 1
start_index = 0
refresh = 1
endelse
endif
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; INCREMENT OR DECREMENT THE SCROLL
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if inp eq "+" then begin
if start_index lt (data_ct - index_increment - 1) then begin
start_index = (start_index + index_increment) < $
(data_ct - index_increment - 1)
refresh = 1
endif
endif
if inp eq "-" then begin
if start_index gt 0 then begin
start_index = (start_index - index_increment) > 0
refresh = 1
endif
endif
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; INCREMENT OR DECREMENT PIXEL BEING VIEWED
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if strupcase(inp) eq "P" then begin
if pixel gt 0 then begin
pixel -= 1
start_index = 0
refresh = 1
endif
endif
if strupcase(inp) eq "N" then begin
if pixel lt npix-1 then begin
pixel += 1
start_index = 0
refresh = 1
endif
endif
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; REFRESH DSPLAY IF NECESSARY
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if keyword_set(refresh) then begin
; ... GET DATA FOR RELEVANT PIXEL
data_ind = where(t.telescop eq pixel_list[pixel], data_ct)
im = t[data_ind].spectrum
; ... BLANK THE DATA IF NEEDED
if keyword_set(blank) then begin
blank_ind = where(blank_mask[*,data_ind], blank_ct)
if blank_ct gt 0 then $
im[blank_ind] = !values.f_nan
endif
; ... BUILD TRIVIAL AXES
sz = size(im)
xaxis = findgen(sz[1])
yaxis = findgen(sz[2])
; ... EXTRACT A SUB-IMAGE IF THAT'S WHAT WE'RE DOING
if all_at_once eq 0 then begin
y_lo = start_index
y_hi = (start_index + index_increment) < (data_ct-1)
im = im[*,y_lo:y_hi]
yaxis = yaxis[y_lo:y_hi]
endif
; ... GET THE INTEGRATED SPECTRUM
int_spec = total(im,2,/nan)
if keyword_set(use_med) then int_spec = median(im,dim=2)
erase
; ... DISPLAY
!p.multi=[1,2,2]
loadct, 5, /silent
disp, im, xaxis, yaxis $
, min=-0.5, max=0.5 $
, title=pixel_list[pixel]+' '+file
!p.multi=[3,2,2]
loadct, 5, /silent
plot, int_spec
!p.multi=[0,2,1]
loadct, 5, /silent
disp, im gt 0, xaxis, yaxis $
, min=0, max=1 $
, title=pixel_list[pixel]+' '+file $
, /noerase
refresh = 0
endif
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; GET USER INPUT
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
print, "Options:"
print, "(A) - Toggle all spectra / subset of spectra"
print, "(C) - Click mouse for info on target spectrum"
print, "(N) - Next pixel"
print, "(P) - Previous pixel"
print, "(+) - Scroll up in subset mode"
print, "(-) - Scroll down in subset mode"
print, "(Q) - Quit"
inp = get_kbrd(1)
endwhile
end