-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIRAS16253_spectral_line_SBLB_archivalSB.py
437 lines (375 loc) · 21.2 KB
/
IRAS16253_spectral_line_SBLB_archivalSB.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
"""
eDisk data reduction script
This script was written for CASA 6.1.1/6.2
Originally derived from DSHARP reduction scripts
Datasets calibrated (in order of date observed):
SB1: 2013.1.00879.S (2015/01/28)
SB2: 2013.1.00879.S (2015/05/04)
SB3: 2016.1.00598.S (2017/08/18)
LB1: 2019.1.00261.L (2021/10/05)
LB2: 2019.1.00261.L (2021/10/26)
LB3: 2019.1.00261.L (2021/10/27)
LB4: 2019.1.00261.L (2021/10/28)
reducer: Y. Aso
Note: spws_string is manually set to be '0,1,2,3,4,5' in the continuum subtraction for SB1 and SB2 because the number of spws was limited for SB1 and SB2 in the continuum reduction. The continuum subtraction shows extrapolation.
vis for tclean is selected from vislist because some SBs do not include a given line.
Spw23 of SB1 and SB2 includes H2CO and DCN but is not included in the imaging because the resolution 15.6 MHz is too wide. Thus H2CO and DCN are made only from LBs. As a result, only 12CO, 13CO, C18O, and SO use LB+SB.
Though tclean for CH3OH suggests changing auto-masking parameters, I did not change because of non-detection (also the extended auto-masking takes very long).
"""
""" Starting matter """
#sys.path.append('/home/casa/contrib/AIV/science/analysis_scripts/') #CHANGE THIS TO YOUR PATH TO THE SCRIPTS!
import analysisUtils as au
import analysisUtils as aU
import string
import os
import glob
import numpy as np
import sys
import pickle
execfile('../edisk/reduction_utils3.py', globals())
###############################################################
################ SETUP/METADATA SPECIFICATION #################
################ USERS NEED TO SET STUFF HERE #################
###############################################################
### Use MPI CASA for faster imaging (start casa with mpicasa -n XX CASA; where XX is the number of processes >= 2)
parallel=True
### if True, can run script non-interactively if later parameters properly set
skip_plots = True
### Add field names (corresponding to the field in the MS) here and prefix for
### filenameing (can be different but try to keep same)
### Only make different if, for example, the field name has a space
field = {'SB1':'IRAS_16253-2422', 'SB2':'IRAS_16253-2422', 'SB3':'IRAS_16253-2429', 'LB':'IRAS16253-2429'}
prefix = 'IRAS16253'
### always include trailing slashes!!
WD_path = '/lustre/cv/projects/edisk/IRAS16253/'
SB_path = WD_path+'SB/'
LB_path = WD_path+'LB/'
### scales for multi-scale clean
SB_scales = [0, 5] #[0, 5, 10, 20]
LB_scales = [0, 5, 30] #[0, 5, 30, 100, 200]
### automasking parameters for very extended emission
#sidelobethreshold=2.0
#noisethreshold=3.75
#lownoisethreshold=1.0
#smoothfactor=2.0
### automasking parameters for compact emission (uncomment to use)
sidelobethreshold=2.0
noisethreshold=4.0
lownoisethreshold=1.5
smoothfactor=1.0
#read in final data_params from continuum to ensure we get the phase centers for each MS
with open(prefix+'.pickle', 'rb') as handle:
data_params = pickle.load(handle)
###############################################################
#################### SHIFT PHASE CENTERS ######################
###############################################################
#selectedVis='vis'
selectedVis='vis_shift'
if selectedVis == 'vis_shift':
for i in data_params.keys():
data_params[i]['vis_shift']=prefix+'_'+i+'_shift.ms'
os.system('rm -rf '+data_params[i]['vis_shift']+'*')
fixvis(vis=data_params[i]['vis'], outputvis=data_params[i]['vis_shift'],
field=data_params[i]['field'],
phasecenter='J2000 '+data_params[i]['phasecenter'])
fixplanets(vis=data_params[i]['vis_shift'], field=data_params[i]['field'],
direction=data_params[i]['common_dir'])
###############################################################
############### SCALE DATA RELATIVE TO ONE EB #################
###############################################################
### Uses scaling from continuum data
for i in data_params.keys():
rescale_flux(data_params[i][selectedVis].replace(WD_path,''), [data_params[i]['gencal_scale']])
data_params[i]['vis_rescaled']=data_params[i][selectedVis].replace('.ms','_rescaled.ms')
with open(prefix+'.pickle', 'wb') as handle:
pickle.dump(data_params, handle, protocol=pickle.HIGHEST_PROTOCOL)
###############################################################
##### APPLY SELF-CALIBRATION SOLUTIONS TO LINE DATA ###########
###############################################################
### Gain tables and spw mapping saved to data dictionaries during selfcal and used as arguments here
for i in data_params.keys():
n_tables=len(data_params[i]['selfcal_tables'])
interp_list=['linearPD']*n_tables
applycal(vis=data_params[i]['vis_rescaled'], spw='',
gaintable=data_params[i]['selfcal_tables'],spwmap=data_params[i]['selfcal_spwmap'], interp=interp_list,
calwt=True, applymode='calonly')
split(vis=data_params[i]['vis_rescaled'],outputvis=data_params[i]['vis_rescaled'].replace('.ms','.ms.selfcal'),datacolumn='corrected')
data_params[i]['vis_selfcal']=data_params[i]['vis_rescaled'].replace('.ms','.ms.selfcal')
### cleanup
os.system('rm -rf '+data_params[i]['vis_rescaled'])
if selectedVis=='vis_shift':
os.system('rm -rf '+data_params[i]['vis_shift'])
with open(prefix+'.pickle', 'wb') as handle:
pickle.dump(data_params, handle, protocol=pickle.HIGHEST_PROTOCOL)
###############################################################
################## DO CONTINUUM SUBTRACTION ###################
###############################################################
### Get channels to exclude for continuum fitting (same as the ones
### we flagged for doing making continuum MS)
for i in data_params.keys():
flagchannels_string = get_flagchannels(data_params[i], prefix)
print(flagchannels_string)
### Get spws for argument list to uvcontsub
spws_string = get_contsub_spws_indivdual_ms(data_params[i], prefix,only_cont_spws=True)
if i in ['SB1', 'SB2']:
spws_string = '0,1,2,3,4,5'
print(spws_string)
### Run uvcontsub on combined, self-cal applied dataset; THIS WILL TAKE MANY HOURS PER EB
contsub(data_params[i]['vis_selfcal'], prefix, spw=spws_string,flagchannels=flagchannels_string,excludechans=True)
os.system('rm -rf '+prefix+'_'+i+'_spectral_line.ms') ### remove existing spectral line MS if present
os.system('mv '+data_params[i]['vis_selfcal'].replace('.selfcal','.selfcal.contsub')+' '+prefix+'_'+i+'_spectral_line.ms')
os.system('rm -rf '+data_params[i]['vis_selfcal'])
data_params[i]['vis_contsub']=prefix+'_'+i+'_spectral_line.ms'
with open(prefix+'.pickle', 'wb') as handle:
pickle.dump(data_params, handle, protocol=pickle.HIGHEST_PROTOCOL)
###############################################################
################ TAR UP FINAL CONTSUBBED DATA #################
###############################################################
for i in data_params.keys():
os.system('rm -rf '+data_params[i]['vis_contsub']+'.tgz')
os.system('tar czf '+data_params[i]['vis_contsub']+'.tgz '+data_params[i]['vis_contsub'])
###############################################################
############ RUN A FINAL SPECTRAL LINE IMAGE SET ##############
###############################################################
### generate list of MS files to image
vislist=[]
vislist_sb=[]
for i in data_params.keys():
vislist.append(data_params[i]['vis_contsub'])
if 'SB' in i:
vislist_sb.append(data_params[i]['vis_contsub'])
### Dictionary defining the spectral line imaging parameters.
include = {
"C18O":[True, True, True, True, True, True, True],
"13CO":[True, True, False, True, True, True, True],
"12CO":[True, True, True, True, True, True, True],
"SO":[True, True, False, True, True, True, True],
"H2CO_3_21-2_20_218.76GHz":[False, False, False, True, True, True, True],
"H2CO_3_03-2_02_218.22GHz":[False, False, False, True, True, True, True],
"H2CO_3_22-2_21_218.47GHz":[False, False, False, True, True, True, True],
"c-C3H2_217.82":[False, False, False, True, True, True, True],
"c-C3H2_217.94":[False, False, False, True, True, True, True],
"c-C3H2_218.16":[False, False, False, True, True, True, True],
"DCN":[False, False, False, True, True, True, True],
"CH3OH":[False, False, False, True, True, True, True],
"SiO":[False, False, False, True, True, True, True]
}
image_list = {
### C18O images
"C18O":dict(chanstart='-11.0km/s', chanwidth='0.167km/s',
nchan=180, linefreq='219.56035410GHz', linespw=['3','3','0','3','3','3','3'],
robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### 13CO images
"13CO":dict(chanstart='-9.33km/s', chanwidth='0.167km/s',
nchan=160, linefreq='220.39868420GHz', linespw=['1','1','1','1','1','1'],
robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### 12CO images
"12CO":dict(chanstart='-56.0km/s', chanwidth='0.635km/s',
nchan=180, linefreq='230.538GHz', linespw=['4','4','2','6','6','6','6'],
robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### SO Images
"SO":dict(chanstart='-11.0km/s', chanwidth='0.167km/s',
nchan=180, linefreq='219.94944200GHz', linespw=['2','2','2','2','2','2'],
robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### H2CO 3(2,1)-2(2,0) Images
"H2CO_3_21-2_20_218.76GHz":dict(chanstart='-11.0km/s',
chanwidth='0.167km/s', nchan=180, linefreq='218.76006600GHz',
linespw=['0','0','0','0'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### H2CO 3(0,3)-2(0,2) Images
"H2CO_3_03-2_02_218.22GHz":dict(chanstart='-11km/s',
chanwidth='1.34km/s', nchan=23, linefreq='218.22219200GHz',
linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### H2CO 3(2,2)-2(2,1) Images
"H2CO_3_22-2_21_218.47GHz":dict(chanstart='-11km/s',
chanwidth='1.34km/s', nchan=23, linefreq='218.47563200GHz',
linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### c-C3H2 217.82 GHz Images
"c-C3H2_217.82":dict(chanstart='-11km/s', chanwidth='1.34km/s',
nchan=23, linefreq='217.82215GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### c-C3H2 217.94 GHz Images
"c-C3H2_217.94":dict(chanstart='-11km/s', chanwidth='1.34km/s',
nchan=23, linefreq='217.94005GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.015arcsec',uvtaper=['2000klambda']),
### c-C3H2 218.16 GHz Images
"c-C3H2_218.16":dict(chanstart='-11km/s', chanwidth='1.34km/s',
nchan=23, linefreq='218.16044GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### DCN Images
"DCN":dict(chanstart='-11km/s', chanwidth='1.34km/s', nchan=23,
linefreq='217.2386GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### CH3OH Images
"CH3OH":dict(chanstart='-11km/s', chanwidth='1.34km/s', nchan=23,
linefreq='218.44006300GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda']),
### SiO Images
"SiO":dict(chanstart='-11km/s', chanwidth='1.34km/s', nchan=23,
linefreq='217.10498000GHz', linespw=['4','4','4','4'], robust=[0.5],imsize=4000,cellsize='0.01arcsec',uvtaper=['2000klambda'])
}
'''
image_list_sb = {
### C18O images
"C18O":dict(chanstart='-11.0km/s', chanwidth='0.167km/s',
nchan=180, linefreq='219.56035410GHz', linespw='3',
robust=[1.0],imsize=1600,cellsize='0.025arcsec'),
### 13CO images
"13CO":dict(chanstart='-11.0km/s', chanwidth='0.167km/s',
nchan=180, linefreq='220.39868420GHz', linespw='1',
robust=[1.0],imsize=1600,cellsize='0.025arcsec'),
### 12CO images
"12CO":dict(chanstart='-56.0km/s', chanwidth='0.635km/s',
nchan=180, linefreq='230.538GHz', linespw='6',
robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### SO Images
"SO":dict(chanstart='-11.0km/s', chanwidth='0.167km/s',
nchan=180, linefreq='219.94944200GHz', linespw='2',
robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### H2CO 3(2,1)-2(2,0) Images
"H2CO_3_21-2_20_218.76GHz":dict(chanstart='-11.0km/s',
chanwidth='0.167km/s', nchan=120, linefreq='218.76006600GHz',
linespw='0', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### H2CO 3(0,3)-2(0,2) Images
"H2CO_3_03-2_02_218.22GHz":dict(chanstart='-10km/s',
chanwidth='1.34km/s', nchan=23, linefreq='218.22219200GHz',
linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### H2CO 3(2,2)-2(2,1) Images
"H2CO_3_22-2_21_218.47GHz":dict(chanstart='-10km/s',
chanwidth='1.34km/s', nchan=23, linefreq='218.47563200GHz',
linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### c-C3H2 217.82 GHz Images
"cC3H2_217.82":dict(chanstart='-10km/s', chanwidth='1.34km/s',
nchan=23, linefreq='217.82215GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### c-C3H2 217.94 GHz Images
"cC3H2_217.94":dict(chanstart='-10km/s', chanwidth='1.34km/s',
nchan=23, linefreq='217.94005GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### c-C3H2 218.16 GHz Images
"cC3H2_218.16":dict(chanstart='-10km/s', chanwidth='1.34km/s',
nchan=23, linefreq='218.16044GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### DCN Images
"DCN":dict(chanstart='-10km/s', chanwidth='1.34km/s', nchan=23,
linefreq='217.2386GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### CH3OH Images
"CH3OH":dict(chanstart='-10km/s', chanwidth='1.34km/s', nchan=23,
linefreq='218.44006300GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec'),
### SiO Images
"SiO":dict(chanstart='-100km/s', chanwidth='1.34km/s', nchan=150,
linefreq='217.10498000GHz', linespw='4', robust=[2.0],imsize=1600,cellsize='0.025arcsec')
}
'''
### Loop through the spectral line images and make images.
'''
for line in image_list_sb:
for robust in image_list_sb[line]["robust"]:
imagename = prefix+f'_SB_'+line+'_robust_'+str(robust)
data_params_sb = {k: v for k, v in data_params.items() if k.startswith('SB')}
sigma = get_sensitivity(data_params_sb, specmode='cube', \
spw=[image_list_sb[line]["linespw"]], chan=450)
tclean_spectral_line_wrapper(vislist_sb, imagename,
image_list_sb[line]["chanstart"], image_list_sb[line]["chanwidth"],
image_list_sb[line]["nchan"], image_list_sb[line]["linefreq"],
image_list_sb[line]["linespw"], SB_scales, threshold=3.0*sigma,
imsize=image_list_sb[line]["imsize"], cellsize=image_list_sb[line]["cellsize"],robust=robust,
sidelobethreshold=sidelobethreshold, noisethreshold=noisethreshold,
lownoisethreshold=lownoisethreshold,smoothfactor=smoothfactor,parallel=parallel,
phasecenter=data_params['SB1']['common_dir'].replace('J2000','ICRS'))
if selectedVis=='vis_shift':
tclean_spectral_line_wrapper(data_params['SB1']['vis'], imagename.replace(prefix,'temporary.pbfix'),
image_list_sb[line]["chanstart"], image_list_sb[line]["chanwidth"],
image_list_sb[line]["nchan"], image_list_sb[line]["linefreq"],
image_list_sb[line]["linespw"], SB_scales, threshold=3.0*sigma,
imsize=image_list_sb[line]["imsize"],
cellsize=image_list_sb[line]["cellsize"], robust=robust,
sidelobethreshold=sidelobethreshold, noisethreshold=noisethreshold,
lownoisethreshold=lownoisethreshold, smoothfactor=smoothfactor,
parallel=parallel,niter=0,
phasecenter=data_params['SB1']['common_dir'].replace('J2000','ICRS'))
os.system('mv '+imagename+'.pb orig_pbimages/')
os.system('cp -r '+imagename.replace(prefix,'temporary.pbfix')+'.pb '+imagename+'.pb')
os.system('rm -rf '+imagename.replace(prefix,'temporary.pbfix')+'*')
'''
bname = list(data_params.keys())
for line in image_list:
print(line)
if line in ['13CO']:
sidelobethreshold=2.0
noisethreshold=3.75
lownoisethreshold=1.0
smoothfactor=2.0
else:
sidelobethreshold=2.0
noisethreshold=4.0
lownoisethreshold=1.5
smoothfactor=1.0
for robust in image_list[line]["robust"]:
imagename = prefix+f'_SBLB_'+line+'_robust_'+str(robust)
data_params_include = {}
for i in range(len(vislist)):
if include[line][i]:
data_params_include[bname[i]] = data_params[bname[i]]
sigma = get_sensitivity(data_params_include, specmode='cube', \
spw=[image_list[line]["linespw"]], chan=10,robust=robust,)
vislist_include = [vislist[i] for i in range(len(vislist)) if include[line][i]]
tclean_spectral_line_wrapper(vislist_include, imagename,
image_list[line]["chanstart"], image_list[line]["chanwidth"],
image_list[line]["nchan"], image_list[line]["linefreq"],
image_list[line]["linespw"], SB_scales, threshold=3.0*sigma,
imsize=image_list[line]["imsize"], cellsize=image_list[line]["cellsize"],
robust=robust, uvtaper=image_list[line]["uvtaper"],
sidelobethreshold=sidelobethreshold, noisethreshold=noisethreshold,
lownoisethreshold=lownoisethreshold,smoothfactor=smoothfactor,parallel=parallel,
phasecenter=data_params['SB1']['common_dir'].replace('J2000','ICRS'))
if selectedVis=='vis_shift':
tclean_spectral_line_wrapper(data_params['LB1']['vis'], imagename.replace(prefix,'temporary.pbfix'),
image_list[line]["chanstart"], image_list[line]["chanwidth"],
image_list[line]["nchan"], image_list[line]["linefreq"],
image_list[line]["linespw"][1], LB_scales, threshold=3.0*sigma,
imsize=image_list[line]["imsize"],
cellsize=image_list[line]["cellsize"],
robust=robust, uvtaper=image_list[line]["uvtaper"],
sidelobethreshold=sidelobethreshold, noisethreshold=noisethreshold,
lownoisethreshold=lownoisethreshold, smoothfactor=smoothfactor,
parallel=parallel,
phasecenter=data_params['SB1']['common_dir'].replace('J2000','ICRS'))
os.system('mv '+imagename+'.pb orig_pbimages/')
os.system('cp -r '+imagename.replace(prefix,'temporary.pbfix')+'.pb '+imagename+'.pb')
os.system('rm -rf '+imagename.replace(prefix,'temporary.pbfix')+'*')
###############################################################
################ CLEANUP AND FITS CONVERSION ##################
###############################################################
import glob
### Remove extra image products
os.system('rm -rf *.residual* *.psf* *.model* *dirty* *.sumwt* *.gridwt* *.workdirectory')
### Remove fits files and pbcor files from previous iterations.
os.system("rm -rf *.pbcor* *.fits")
imagelist=glob.glob('*.image') + glob.glob('*.image.tt0')
for image in imagelist:
if selectedVis=='vis_shift':
immath(imagename=[image,image.replace('image', 'pb')],expr='IM0/IM1',outfile=image.replace('image', 'pbcor'),imagemd=image)
else:
impbcor(imagename=image, pbimage=image.replace('image', 'pb'),
outfile=image.replace('image', 'pbcor'))
exportfits(imagename=image.replace('image','pbcor'),fitsimage=image.replace('image','pbcor')+'.fits',overwrite=True,dropdeg=True)
exportfits(imagename=image,fitsimage=image+'.fits',overwrite=True,dropdeg=True)
imagelist=glob.glob('*.mask')
for image in imagelist:
exportfits(imagename=image,fitsimage=image+'.fits',overwrite=True,dropdeg=True)
os.system('gzip '+image+'.fits')
os.system('rm -rf *initcont*.pb')
imagelist=glob.glob('*.pb') + glob.glob('*.pb.tt0')
for image in imagelist:
exportfits(imagename=image,fitsimage=image+'.fits',overwrite=True,dropdeg=True)
os.system('gzip '+image+'.fits')
###############################################################
################# Make Plots of Everything ####################
###############################################################
import sys
sys.argv = ['../edisk/plot_final_images_SBLB.py', prefix]
execfile('../edisk/plot_final_images_SBLB.py')
### Remove rescaled selfcal MSfiles
os.system('rm -rf *rescaled.ms.*')
os.system('rm -rf scale*')
### Remove extra image products
os.system('rm -rf *.residual* *.psf* *.model* *dirty* *.sumwt* *.gridwt* *.workdirectory')
### Make a directory to put the final products
os.system('rm -rf export')
os.system('mkdir export')
os.system('mv *.fits export/')
os.system('mv *.fits.gz export/')
os.system('mv *.tgz export/')
os.system('mv *.pdf export/')