""" This script was written for CASA 5.1.1 Datasets calibrated (in order of date observed): SB1: 2016.1.00484.L Observed 14 May 2017, 17 May 2017, and 19 May 2017 (3 execution blocks) LB1: 2016.1.00484.L Observed 23 September 2017 and 07 October 2017 (2 execution blocks) reducer: S. Andrews """ """ Starting matter """ import os execfile('reduction_utils.py') """ Input for loading data """ prefix = 'Elias20' SB1_path = '/full_path/to_calibrated/msfile.ms' LB1_path = '/full_path/to_calibrated/msfile.ms' # Note that if you are downloading data from the archive, your SPW numbering # may differ from this script, depending on how you split your data out! data_params = {'SB1': {'vis' : SB1_path, 'name' : 'SB1', 'field': 'Elias_20', 'line_spws': np.array([0,4,8]), # CO SPWs 'line_freqs': np.array([2.30538e11, 2.30538e11, 2.30538e11]), }, 'LB1': {'vis' : LB1_path, 'name' : 'LB1', 'field' : 'Elias_20', 'line_spws': np.array([3,7]), # CO SPWs 'line_freqs': np.array([2.30538e11, 2.30538e11]), } } """ Split out the SB data, with the continuum SPWs averaged down """ os.system('rm -rf %s*' % prefix+'_SB1_lines_exec0') split(vis=data_params['SB1']['vis'], field=data_params['SB1']['field'], spw='0~3', outputvis=prefix+'_SB1_lines_exec0.ms', width=[1,128,128,128], datacolumn='data', intent='OBSERVE_TARGET#ON_SOURCE', keepflags=False) os.system('rm -rf %s*' % prefix+'_SB1_lines_exec1') split(vis=data_params['SB1']['vis'], field=data_params['SB1']['field'], spw='4~7', outputvis=prefix+'_SB1_lines_exec1.ms', width=[1,128,128,128], datacolumn='data', intent='OBSERVE_TARGET#ON_SOURCE', keepflags=False) os.system('rm -rf %s*' % prefix+'_SB1_lines_exec2') split(vis=data_params['SB1']['vis'], field=data_params['SB1']['field'], spw='8~11', outputvis=prefix+'_SB1_lines_exec2.ms', width=[1,128,128,128], datacolumn='data', intent='OBSERVE_TARGET#ON_SOURCE', keepflags=False) """ Split out the LB data, with the continuum SPWs averaged down """ os.system('rm -rf '+prefix+'_LB1_lines_exec0*') split(vis=data_params['LB1']['vis'], field='3', spw='0~3', outputvis=prefix+'_LB1_lines_exec0.ms', width=[128,128,128,1], timebin='6s', datacolumn='data', intent='OBSERVE_TARGET#ON_SOURCE', keepflags=False) os.system('rm -rf '+prefix+'_LB1_lines_exec1*') split(vis=data_params['LB1']['vis'], field='3', spw='4~7', outputvis=prefix+'_LB1_lines_exec1.ms', width=[128,128,128,1], timebin='6s', datacolumn='data', intent='OBSERVE_TARGET#ON_SOURCE', keepflags=False) """ Apply same shifts and re-scalings as for continuum """ rescale_flux(prefix+'_SB1_lines_exec0.ms', [0.961]) rescale_flux(prefix+'_LB1_lines_exec0.ms', [1.106]) rescale_flux(prefix+'_LB1_lines_exec1.ms', [1.034]) """ Apply the self-calibration solutions to the SB data """ SB_CO = prefix+'_SB_CO' os.system('rm -rf %s*' % SB_CO) concat(vis=[prefix+'_SB1_lines_exec0_rescaled.ms', prefix+'_SB1_lines_exec1.ms', prefix+'_SB1_lines_exec2.ms'], concatvis=SB_CO+'.ms', dirtol='0.1arcsec', copypointing=False) applycal(vis=SB_CO+'.ms', spw='0~11', gaintable=[prefix+'_SB.p1', prefix+'_SB.p2', prefix+'_SB.ap'], interp='linearPD', calwt=True, flagbackup=False) os.system('rm -rf '+SB_CO+'_selfcal.ms*') split(vis=SB_CO+'.ms', outputvis=SB_CO+'_selfcal.ms', datacolumn='corrected', keepflags=False) # save some space by deleting intermediate files os.system('rm -rf '+SB_CO+'.ms*') os.system('rm -rf '+prefix+'_SB1_lines_exec*ms*') """ Now apply the self-calibration solutions to the combined dataset """ combined_CO = prefix+'_combined_CO' os.system('rm -rf '+combined_CO+'.ms*') concat(vis=[SB_CO+'_selfcal.ms', prefix+'_LB1_lines_exec0_rescaled.ms', prefix+'_LB1_lines_exec1_rescaled.ms'], concatvis=combined_CO+'.ms', dirtol='0.1arcsec', copypointing=False) applycal(vis=combined_CO+'.ms', spw='0~19', spwmap=[[0,0,0,0,4,4,4,4,8,8,8,8,12,12,12,12,16,16,16,16]]*6, gaintable=[prefix+'_combined.p1', prefix+'_combined.p2', prefix+'_combined.p3', prefix+'_combined.p4', prefix+'_combined.p5', prefix+'_combined.ap'], interp='linearPD', calwt=True, applymode='calonly') os.system('rm -rf '+combined_CO+'_selfcal.ms*') split(vis=combined_CO+'.ms', outputvis=combined_CO+'_selfcal.ms', field='', spw='0,4,8,15,19', datacolumn='corrected', keepflags=False) # save some space by deleting intermediate files os.system('rm -rf '+combined_CO+'.ms*') os.system('rm -rf '+prefix+'_LB1_lines_exec*ms*') """ Continuum subtraction """ fitspw = '0~4:0~1855;1985~3839' os.system('rm -rf '+combined_CO+'_selfcal.ms.contsub*') uvcontsub(vis=combined_CO+'_selfcal.ms', spw='0~4', fitspw=fitspw, excludechans=False, solint='int', fitorder=1, want_cont=False) """ Define the channels of interest """ chanstart = '-6.5km/s' chanwidth = '0.35km/s' nchan = 60 """ Split and regrid into the channels of interest """ # Continuum-subtracted SB_only = prefix+'_CO_SBonly.ms.contsub' os.system('rm -rf '+SB_only+'*') split(vis=combined_CO+'_selfcal.ms.contsub', outputvis=SB_only, spw='0,1,2', datacolumn='data') SB_cvel = SB_only+'.cvel' os.system('rm -rf '+SB_cvel+'*') mstransform(vis=SB_only, outputvis=SB_cvel, keepflags=False, datacolumn='data', regridms=True, mode='velocity', start=chanstart, width=chanwidth, nchan=nchan, outframe='LSRK', veltype='radio', restfreq='230.538GHz') LB_only = prefix+'_CO_LBonly.ms.contsub' os.system('rm -rf '+LB_only+'*') split(vis=combined_CO+'_selfcal.ms.contsub', outputvis=LB_only, spw='3,4', datacolumn='data') LB_cvel = LB_only+'.cvel' os.system('rm -rf '+LB_cvel+'*') mstransform(vis=LB_only, outputvis=LB_cvel, keepflags=False, datacolumn='data', regridms=True, mode='velocity', start=chanstart, width=chanwidth, nchan=nchan, outframe='LSRK', veltype='radio', restfreq='230.538GHz') contsub_concat = prefix+'_COcube.ms.contsub' os.system('rm -rf '+contsub_concat) concat(vis=[SB_cvel, LB_cvel], concatvis=contsub_concat, dirtol='0.1arcsec', copypointing=False) # With continuum cSB_only = prefix+'_CO_SBonly.ms' os.system('rm -rf '+cSB_only) split(vis=combined_CO+'_selfcal.ms', outputvis=cSB_only, spw='0,1,2', datacolumn='data') cSB_cvel = cSB_only+'.cvel' os.system('rm -rf '+cSB_cvel) mstransform(vis=cSB_only, outputvis=cSB_cvel, keepflags=False, datacolumn='data', regridms=True, mode='velocity', start=chanstart, width=chanwidth, nchan=nchan, outframe='LSRK', veltype='radio', restfreq='230.538GHz') cLB_only = prefix+'_CO_LBonly.ms' os.system('rm -rf '+cLB_only) split(vis=combined_CO+'_selfcal.ms', outputvis=cLB_only, spw='3,4', datacolumn='data') cLB_cvel = cLB_only+'.cvel' os.system('rm -rf '+cLB_cvel) mstransform(vis=cLB_only, outputvis=cLB_cvel, keepflags=False, datacolumn='data', regridms=True, mode='velocity', start=chanstart, width=chanwidth, nchan=nchan, outframe='LSRK', veltype='radio', restfreq='230.538GHz') cont_concat = prefix+'_COcube.ms' os.system('rm -rf '+cont_concat) concat(vis=[cSB_cvel, cLB_cvel], concatvis=cont_concat, dirtol='0.1arcsec', copypointing=False) """ Imaging (continuum-subtracted only) """ imagename = prefix+'_CO' for ext in ['.image','.mask','.model','.pb','.psf','.residual','.sumwt']: os.system('rm -rf '+ imagename + ext) tclean(vis=prefix+'_COcube.ms.contsub', imagename=imagename, specmode='cube', imsize=1500, deconvolver='multiscale', start=chanstart, width=chanwidth, nchan=nchan, outframe='LSRK', veltype='radio', restfreq='230.538GHz', cell='0.01arcsec', scales = [0,10,30,100,200], gain=0.1, niter=50000, weighting='briggs', robust=1.0, threshold='3mJy', uvtaper='0.04arcsec', interactive=True, nterms=1, restoringbeam='common') # Note that masking is done interactively """ Final outputs """ """ Save the final MS files """ os.system('tar cvzf '+prefix+'_CO.ms.tgz '+prefix+'_COcube.ms.contsub') os.system('tar cvzf '+prefix+'_COcont.ms.tgz '+prefix+'_COcube.ms') """ Save the imaged datacube """ exportfits(imagename+'.image', imagename+'.fits')