forked from akleroy/phangs_imaging_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_clean_masks.pro
306 lines (254 loc) · 7.46 KB
/
make_clean_masks.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
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
pro make_clean_masks $
, nopause=nopause $
, inspect=do_inspect $
, start = start_num $
, skip = skip $
, only = only
;+
;
; Create clean masks for use with imaging.
;
;-
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; DIRECTORIES AND SETUP
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
root_imaging_dir = '../'
; ... look up the version to based the masks on
if n_elements(version) eq 0 then $
version = '3'
if version eq '2' then begin
vstring = 'v2'
release_dir = root_imaging_dir+'release/'+vstring+'/'
endif else if version eq '3' then begin
vstring = 'v3'
release_dir = root_imaging_dir+'release/'+vstring+'/'
endif else begin
print, "Version not recognized. Returning."
return
endelse
if n_elements(start_num) eq 0 then $
start_num = 0
; ... look up the list of galaxies
readcol, 'ms_file_key.txt', comment='#', format='A,X,A' $
, ms_file_gal, ms_file_array, /silent
gals = ms_file_gal[sort(ms_file_gal)]
gals = gals[uniq(gals)]
n_gals = n_elements(gals)
; ... look up the cases with nonstandard directory names
readcol, 'dir_key.txt', comment='#', format='A,A' $
, dir_key_gal, dir_key_dir, /silent
dir_for_gal = gals
for ii = 0, n_elements(dir_key_gal)-1 do begin
ind = where(dir_key_gal[ii] eq gals, ct)
if ct eq 0 then continue
dir_for_gal[ind] = (dir_key_dir[ii])
endfor
; ... define arrays
array_list = ['7m', '12m', '12m+7m']
n_array = n_elements(array_list)
; ... define products
product_list = ['co21']
n_product = n_elements(product_list)
; ... lists of galaxies to skip or focus on
if n_elements(only) eq 0 then $
only = []
if n_elements(skip) eq 0 then $
skip = []
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; GALAXY-SPECIFIC TUNING
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; ... these galaxies have central bright sources
has_bright_center = $
['circinus' $
, 'ngc0253' $
, 'ngc1097' $
, 'ngc1300' $
, 'ngc1317' $
, 'ngc1365' $
, 'ngc1433' $
, 'ngc1512' $
, 'ngc1566' $
, 'ngc1637' $
, 'ngc1672' $
, 'ngc2566' $
, 'ngc2903' $
, 'ngc2997' $
, 'ngc3351' $
, 'ngc3507' $
, 'ngc3626' $
, 'ngc3627' $
, 'ngc4293' $
, 'ngc4303' $
, 'ngc4321' $
, 'ngc4457' $
, 'ngc4535' $
, 'ngc4536' $
, 'ngc4548' $
, 'ngc4569' $
, 'ngc4579' $
, 'ngc4826' $
, 'ngc4941' $
, 'ngc4951' $
, 'ngc5128' $
, 'ngc5248' $
, 'ngc5643' $
, 'ngc6300' $
, 'ngc7496' $
]
is_super_faint = $
['ngc0300' $
, 'ngc3489' $
, 'ngc3599' $
, 'ngc3489' $
, 'ngc4459' $
, 'ngc4476' $
, 'ngc4477' $
, 'ngc4596' $
, 'ngc7743' $
]
empty = $
['ngc3239' $
]
use_edge_chan = $
[ $
'ngc3489' $
, 'ngc3599' $
, 'ngc3489' $
, 'ngc4459' $
, 'ngc4476' $
, 'ngc4477' $
, 'ngc4596' $
, 'ngc7743' $
]
small_kernel = $
[ $
'ngc3599' $
, 'ngc4596' $
]
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; LOOP OVER GALAXIES
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
for ii = start_num, n_gals-1 do begin
dir_ind = where(dir_key_gal eq gals[ii], dir_ct)
is_multipart = dir_ct ge 1
if is_multipart then begin
this_gal = dir_key_dir[dir_ind]
endif else begin
this_gal = gals[ii]
endelse
if n_elements(skip) gt 0 then begin
if total(gals[ii] eq skip) gt 0 then begin
print, "Skipping "+gals[ii]
continue
endif
endif
if n_elements(only) gt 0 then begin
if (total(gals[ii] eq only) eq 0) and $
(total(this_gal eq only) eq 0) $
then begin
print, "Skipping "+gals[ii]
continue
endif
endif
print, ""
print, "Making clean mask for "+gals[ii]+' (Galaxy '+str(ii)+')'
print, ""
dir = release_dir+'process/'
print, dir, version, vstring
clean_mask_fname = '../clean_masks/'+this_gal+'_co21_clean_mask.fits'
;if n_elements(only) gt 0 then $
; if total(only eq gals[ii]) eq 0 then continue
cube_fname = dir+this_gal+'_7m+tp_co21_flat_round_k.fits'
if file_test(cube_fname) eq 0 then begin
cube_fname = dir+this_gal+'_7m_co21_flat_round_k.fits'
endif
if file_test(cube_fname) eq 0 then begin
cube_fname = dir+this_gal+'_12m_co21_flat_round_k.fits'
endif
if file_test(cube_fname) eq 0 then begin
print, ""
print, "WARNING!!!"
print, ""
print, "No cube found for "+this_gal
print, "... looking for "+cube_fname
print, "Continuing."
continue
endif
cube = readfits(cube_fname, cube_hdr)
kernel_lores = 33.0
chan_lores = 20
if total(this_gal[0] eq small_kernel) ge 1 then begin
kernel_lores = 20.0
chan_lores = 20
endif
conv_with_gauss $
, data=cube*1.0 $
, hdr=cube_hdr $
, target = [1,1,0.] * kernel_lores $
, out_data=lowres_cube $
, out_hdr=lowres_hdr $
, /perbeam
lowres_cube = smooth(lowres_cube, [1,1,chan_lores], /nan)
lowres_ppbeam = calc_pixperbeam(hdr=lowres_hdr)
rms_lowres_cube = mad(lowres_cube)
if total(this_gal[0] eq use_edge_chan) ge 1 then begin
nchan = (size(lowres_cube))[3]
n_edge = 50
rms_lowres_cube = $
0.5*(mad(lowres_cube[*,*,0:(n_edge-1)]) + $
mad(lowres_cube[*,*,(nchan-n_edge-1):*]))
endif
if total(this_gal[0] eq is_super_faint) ge 1 then begin
lo_thresh_lowres = 3
hi_thresh_lowres = 5
endif else begin
lo_thresh_lowres = 3
hi_thresh_lowres = 10
endelse
make_cprops_mask $
, indata=lowres_cube $
, inrms = rms_lowres_cube $
, lo_thresh = lo_thresh_lowres $
, hi_thresh = hi_thresh_lowres $
, hi_nchan = 2 $
, min_area = 2.0*lowres_ppbeam $
, min_pix = 4.0*lowres_ppbeam $
, outmask=mask ;lowres_mask
mask = grow_mask(mask, /z_only, iter=4)
if this_gal[0] eq 'ngc0300' then begin
mask[*,*,0:25] = 0B
mask[*,*,150:*] = 0B
mask = grow_mask(mask, /xy_only, iter=20)
endif
if total(this_gal[0] eq has_bright_center) ge 1 then begin
s = gal_data(this_gal)
make_axes, lowres_hdr, ri=ri, di=di
rad = sphdist(ri, di, s.ra_deg, s.dec_deg, /deg)
center_mask = rad le 20./3600.
sz = (size(lowres_cube))
for kk = 0, sz[3]-1 do begin
mask[*,*,kk] = mask[*,*,kk] or center_mask
endfor
endif
;conv_with_gauss $
; , data=lowres_mask*1.0 $
; , hdr=lowres_hdr $
; , target = [1,1,0.] * 33.0 $
; , out_data=out_lowres_mask $
; , /perbeam
;if total(gals[ii] eq expand_in_space) gt 0 then begin
; lowres_mask = out_lowres_mask ge 0.5
;endif else begin
; lowres_mask = out_lowres_mask ge 1.0
;endelse
writefits, clean_mask_fname, mask, lowres_hdr
inspect_clean_masks $
, nopause=nopause $
, only=this_gal $
, array='7m'
;inspect_clean_masks $
; , nopause=nopause $
; , only=this_gal $
; , array='12m+7m'
endfor
end