#=====# # SCRIPT TO CALIBRATE THE MEASUREMENT SET uid___A002_Xbff114_X4684 FOR THE # MASSIVE STAR FORMING SOURCE IRAS13481-6124 # Generated by A.Avison # THIS FOLLOWS THE SAME STEPS AS THE IRAS16293 DATA USED IN THE TUTORIAL # AT THE DUBLIN INTERFEROMETRIC DATA REDUCTION WORKSHOP 10-12 SEP 2018 # BUT IS PROVIDED WITH NO TUTORIAL ACCOMPANIMENT AS A BONUS REDUCTION # EXERCISE. #=====# # ALMA Data Reduction Script # Calibration thesteps = [] step_title = {0: 'Import of the ASDM', 1: 'Fix of SYSCAL table times', 2: 'listobs', 3: 'A priori flagging', 4: 'Generation and time averaging of the WVR cal table', 5: 'Generation of the Tsys cal table', 6: 'Generation of the antenna position cal table', 7: 'Application of the WVR, Tsys and antpos cal tables', 8: 'Split out science SPWs and time average', 9: 'Listobs, and save original flags', 10: 'Initial flagging', 11: 'Putting a model for the flux calibrator(s)', 12: 'Save flags before bandpass cal', 13: 'Bandpass calibration', 14: 'Save flags before gain cal', 15: 'Gain calibration', 16: 'Save flags before applycal', 17: 'Application of the bandpass and gain cal tables', 18: 'Split out corrected column', 19: 'Save flags after applycal'} if 'applyonly' not in globals(): applyonly = False try: print 'List of steps to be executed ...', mysteps thesteps = mysteps except: print 'global variable mysteps not set.' if (thesteps==[]): thesteps = range(0,len(step_title)) print 'Executing all steps: ', thesteps # The Python variable 'mysteps' will control which steps # are executed when you start the script using # execfile('scriptForCalibration.py') # e.g. setting # mysteps = [2,3,4]# before starting the script will make the script execute # only steps 2, 3, and 4 # Setting mysteps = [] will make it execute all steps. import re import os import casadef if applyonly != True: es = aU.stuffForScienceDataReduction() if re.search('^5.1.1', '.'.join([str(i) for i in cu.version().tolist()[:-1]])) == None: sys.exit('ERROR: PLEASE USE THE SAME VERSION OF CASA THAT YOU USED FOR GENERATING THE SCRIPT: 5.1.1') # CALIBRATE_AMPLI: # CALIBRATE_ATMOSPHERE: IRAS13481-6124,J1329-5608,J1427-4206 # CALIBRATE_BANDPASS: J1427-4206 # CALIBRATE_DIFFGAIN: # CALIBRATE_FLUX: J1427-4206 # CALIBRATE_FOCUS: # CALIBRATE_PHASE: J1329-5608 # CALIBRATE_POINTING: J1427-4206 # OBSERVE_CHECK: J1337-6509 # OBSERVE_TARGET: IRAS13481-6124 # Using reference antenna = DA46 print '# Start-up and Apriori calibration' #======================================================================# # STEP 0: # Import of the ASDM #======================================================================# """ Here we import the Raw data from the ASDM binary table into a CASA measurement set. """ mystep = 0 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] if os.path.exists('uid___A002_Xbff114_X4684.ms') == False: importasdm('uid___A002_Xbff114_X4684', asis='Antenna Station Receiver Source CalAtmosphere CalWVR CorrelatorMode SBSummary', bdfflags=True, lazy=False, process_caldevice=False) if not os.path.exists('uid___A002_Xbff114_X4684.ms.flagversions'): print 'ERROR in importasdm. Output MS is probably not useful. Will stop here.' thesteps = [] if applyonly != True: es.fixForCSV2555('uid___A002_Xbff114_X4684.ms') #======================================================================# # STEP 1: # Fix of SYSCAL table times #======================================================================# """ Its best not to worry too much about this step... In essence, sometimes data from the ALMA correlator are assigned too many time stamps, when they should have one each. This step fixes that. """ mystep = 1 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] from recipes.almahelpers import fixsyscaltimes fixsyscaltimes(vis = 'uid___A002_Xbff114_X4684.ms') #======================================================================# # STEP 2: # Generate LISTOBS #======================================================================# """ This step generates a text file known as a LISTOBS file. Within this file is a lot of useful information regarding your observations, such as observing times, spectral setup, antenna positions, source positions. """ mystep = 2 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.listobs') listobs(vis = 'uid___A002_Xbff114_X4684.ms', listfile = 'uid___A002_Xbff114_X4684.ms.listobs') #======================================================================# # STEP 3: # A priori flagging #======================================================================# """ Here we flag (remove) data which was imported as part of the ASDM that we no longer need. E.g. the autocorrelations and scans which are not required for calibration or imaging. """ mystep = 3 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] """ Flagging to get rid of Auto Correlations """ flagdata(vis = 'uid___A002_Xbff114_X4684.ms', mode = 'manual', spw = '5~12,17~34', autocorr = True, flagbackup = False) """ Flagging to get rid of unneccessary POINTING AND ATMOSPHERE scans. These were used during observation but are no longer needed for calibration or imaging. """ flagdata(vis = 'uid___A002_Xbff114_X4684.ms', mode = 'manual', intent = '*POINTING*,*ATMOSPHERE*', flagbackup = False) """ Next we generate a couple of plots to show what was flagged when and why. This is a quick diagnostic check to make sure no antennas look heavily flagged early on. """ flagcmd(vis = 'uid___A002_Xbff114_X4684.ms', inpmode = 'table', useapplied = True, action = 'plot', plotfile = 'uid___A002_Xbff114_X4684.ms.flagcmd.png') flagcmd(vis = 'uid___A002_Xbff114_X4684.ms', inpmode = 'table', useapplied = True, action = 'apply') #======================================================================# # STEP 4: # Generation and time averaging of the WVR cal table #======================================================================# """ ALMA uses water vapour radiometer data to apply a correction to the phase of the visibilities based on the amount of preciptial water vapour in the atmosphere during observations. The task wvrgcal is used to preform this. """ mystep = 4 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.wvr') os.system('rm -rf uid___A002_Xbff114_X4684.ms.wvrgcal') mylogfile = casalog.logfile() casalog.setlogfile('uid___A002_Xbff114_X4684.ms.wvrgcal') wvrgcal(vis = 'uid___A002_Xbff114_X4684.ms', caltable = 'uid___A002_Xbff114_X4684.ms.wvr', spw = [25, 27, 29, 31, 33], smooth = '6.048s', toffset = 0, tie = ['J1337-6509,J1329-5608', 'IRAS13481-6124,J1329-5608'], statsource = 'IRAS13481-6124') casalog.setlogfile(mylogfile) if applyonly != True: aU.plotWVRSolutions(caltable='uid___A002_Xbff114_X4684.ms.wvr', spw='25', antenna='DA46', yrange=[-199,199],subplot=22, interactive=False, figfile='uid___A002_Xbff114_X4684.ms.wvr.plots/uid___A002_Xbff114_X4684.ms.wvr') #Note: If you see wraps in these plots, try changing yrange or unwrap=True #Note: If all plots look strange, it may be a bad WVR on the reference antenna. # To check, you can set antenna='' to show all baselines. #======================================================================# # STEP 5: # Generation of the Tsys cal table #======================================================================# """ We now generate a calibration table for the System Temperature, Tsys this is used to correct reciever responses based on measurements in wide spectral windows. This is an amplitude calibration to correct for atmospheric emission/opacity. Tsys for ALMA in Band 3 ~100K up to Band 9 ~1000K. """ mystep = 5 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.tsys') gencal(vis = 'uid___A002_Xbff114_X4684.ms', caltable = 'uid___A002_Xbff114_X4684.ms.tsys', caltype = 'tsys') # Flagging edge channels flagdata(vis = 'uid___A002_Xbff114_X4684.ms.tsys', mode = 'manual', spw = '17:0~3;124~127,19:0~3;124~127,21:0~3;124~127,23:0~3;124~127', flagbackup = False) if applyonly != True: aU.plotbandpass(caltable='uid___A002_Xbff114_X4684.ms.tsys', overlay='time', xaxis='freq', yaxis='amp', subplot=22, buildpdf=False, interactive=False, showatm=True,pwv='auto',chanrange='92.1875%',showfdm=True, showBasebandNumber=True, showimage=False, field='', figfile='uid___A002_Xbff114_X4684.ms.tsys.plots.overlayTime/uid___A002_Xbff114_X4684.ms.tsys') if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.tsys', msName='uid___A002_Xbff114_X4684.ms', interactive=False) #======================================================================# # STEP 6: # Generation of the antenna position cal table #======================================================================# """ Update the attenna positions for the dishes in the array. ALMA runs regular measurements of the positions of the dishes in the array and the antenna positions can be corrected for any changes. An incorrect antenna position will introduce a delay into the system resulting in rapidly changing phases. """ mystep = 6 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] # Warning: no baseline run found for following antenna(s): ['PM01', 'PM04']. # Position for antenna DV12 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV18 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA65 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA64 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA49 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA48 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA61 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA60 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV11 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA44 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA47 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA46 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DV14 is larger than 2mm. # Position for antenna DV14 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA43 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA42 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV23 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV25 is derived from baseline run made on 2017-04-18 06:59:13. # Position for antenna DA63 is derived from baseline run made on 2017-04-18 06:59:13. # Position for antenna DV15 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA62 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV08 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV09 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV19 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV10 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV04 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA52 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA53 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA51 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA56 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DA57 is larger than 2mm. # Position for antenna DA57 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA54 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA55 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA58 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DA59 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DV03 is larger than 2mm. # Position for antenna DV03 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DV20 is larger than 2mm. # Position for antenna DV20 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DV16 is larger than 2mm. # Position for antenna DV16 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV13 is derived from baseline run made on 2017-05-09 07:38:12. # Note: the correction for antenna DV05 is larger than 2mm. # Position for antenna DV05 is derived from baseline run made on 2017-05-09 07:38:12. # Position for antenna DV24 is derived from baseline run made on 2017-05-09 07:38:12. os.system('rm -rf uid___A002_Xbff114_X4684.ms.antpos') gencal(vis = 'uid___A002_Xbff114_X4684.ms', caltable = 'uid___A002_Xbff114_X4684.ms.antpos', caltype = 'antpos', antenna = 'DA42,DA43,DA44,DA46,DA47,DA48,DA49,DA51,DA52,DA53,DA54,DA55,DA56,DA57,DA58,DA59,DA60,DA61,DA62,DA63,DA64,DA65,DV03,DV04,DV05,DV08,DV09,DV10,DV11,DV12,DV13,DV14,DV15,DV16,DV18,DV19,DV20,DV23,DV24,DV25', # parameter = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) parameter = [-1.17612e-04,5.35836e-04,3.21571e-04,8.48647e-05,-2.65591e-04,-4.35480e-05,-2.87490e-04,7.34618e-04,1.75727e-04,-2.29632e-04,7.72762e-04,3.70186e-04,-2.83890e-04,9.68737e-04,5.14087e-04,-1.69196e-04,6.09098e-04,3.97519e-04,-1.37348e-05,4.43009e-04,2.27429e-04,-1.72001e-04,6.47702e-04,2.79528e-04,-5.38002e-05,6.17594e-04,2.30408e-04,-1.79229e-04,8.02680e-04,4.55212e-04,-2.20037e-04,6.09261e-04,3.43859e-04,-9.07321e-05,3.14302e-04,2.22007e-04,-7.03592e-05,4.38824e-04,2.21822e-04,-7.26476e-04,8.89340e-03,3.17645e-03,8.63634e-05,1.16415e-04,-1.77803e-04,1.10043e-04,1.69446e-04,1.25700e-04,-1.85137e-04,7.66962e-04,2.96833e-04,-1.87749e-04,6.80898e-04,4.11164e-04,1.02772e-04,4.54048e-04,6.85009e-06,-1.79997e-05,3.37000e-04,2.40000e-04,-1.22527e-04,5.10878e-04,2.76760e-04,-2.06408e-04,8.63710e-04,5.46426e-04,3.36093e-03,-8.07251e-03,-5.36903e-03,-1.82482e-05,5.91393e-04,3.48011e-04,-1.79277e-04,-2.11051e-03,3.03588e-04,9.97810e-06,4.69602e-04,5.92648e-05,7.50738e-05,5.27093e-04,1.84004e-06,-1.05188e-04,9.06800e-04,6.12171e-04,7.20460e-05,4.07631e-04,2.09648e-04,-9.79338e-05,5.37899e-04,3.39842e-04,-9.85505e-05,5.63236e-04,1.78333e-04,1.22375e-03,-2.69847e-03,-5.74085e-05,2.66971e-04,-1.64033e-04,7.44960e-05,-4.28577e-04,-2.94027e-03,-7.00456e-04,-1.90930e-04,9.07926e-04,3.73393e-04,-2.72890e-04,7.94088e-04,3.74625e-04,-1.01900e-04,2.18794e-03,1.11542e-03,-1.34450e-04,8.78142e-04,3.78776e-04,-5.20030e-05,6.73876e-04,4.86583e-04,-3.76510e-05,2.85148e-04,4.02611e-04]) # antenna x_offset y_offset z_offset total_offset baseline_date # DV03 3.36093e-03 -8.07251e-03 -5.36903e-03 1.02610e-02 2017-05-09 07:38:12 # DA57 -7.26476e-04 8.89340e-03 3.17645e-03 9.47154e-03 2017-05-09 07:38:12 # DV16 -4.28577e-04 -2.94027e-03 -7.00456e-04 3.05279e-03 2017-05-09 07:38:12 # DV14 1.22375e-03 -2.69847e-03 -5.74085e-05 2.96355e-03 2017-05-09 07:38:12 # DV20 -1.01900e-04 2.18794e-03 1.11542e-03 2.45797e-03 2017-05-09 07:38:12 # DV05 -1.79277e-04 -2.11051e-03 3.03588e-04 2.13976e-03 2017-05-09 07:38:12 # DA47 -2.83890e-04 9.68737e-04 5.14087e-04 1.13284e-03 2017-05-09 07:38:12 # DV10 -1.05188e-04 9.06800e-04 6.12171e-04 1.09914e-03 2017-05-09 07:38:12 # DA65 -2.06408e-04 8.63710e-04 5.46426e-04 1.04268e-03 2017-05-09 07:38:12 # DV18 -1.90930e-04 9.07926e-04 3.73393e-04 1.00010e-03 2017-05-09 07:38:12 # DV23 -1.34450e-04 8.78142e-04 3.78776e-04 9.65755e-04 2017-05-09 07:38:12 # DA53 -1.79229e-04 8.02680e-04 4.55212e-04 9.40019e-04 2017-05-09 07:38:12 # DV19 -2.72890e-04 7.94088e-04 3.74625e-04 9.19450e-04 2017-05-09 07:38:12 # DA46 -2.29632e-04 7.72762e-04 3.70186e-04 8.87091e-04 2017-05-09 07:38:12 # DA60 -1.85137e-04 7.66962e-04 2.96833e-04 8.42981e-04 2017-05-09 07:38:12 # DV24 -5.20030e-05 6.73876e-04 4.86583e-04 8.32813e-04 2017-05-09 07:38:12 # DA61 -1.87749e-04 6.80898e-04 4.11164e-04 8.17269e-04 2017-05-09 07:38:12 # DA44 -2.87490e-04 7.34618e-04 1.75727e-04 8.08204e-04 2017-05-09 07:38:12 # DA48 -1.69196e-04 6.09098e-04 3.97519e-04 7.46759e-04 2017-05-09 07:38:12 # DA54 -2.20037e-04 6.09261e-04 3.43859e-04 7.33385e-04 2017-05-09 07:38:12 # DA51 -1.72001e-04 6.47702e-04 2.79528e-04 7.26112e-04 2017-05-09 07:38:12 # DV04 -1.82482e-05 5.91393e-04 3.48011e-04 6.86433e-04 2017-05-09 07:38:12 # DA52 -5.38002e-05 6.17594e-04 2.30408e-04 6.61366e-04 2017-05-09 07:38:12 # DV12 -9.79338e-05 5.37899e-04 3.39842e-04 6.43754e-04 2017-05-09 07:38:12 # DA42 -1.17612e-04 5.35836e-04 3.21571e-04 6.35894e-04 2017-05-09 07:38:12 # DV13 -9.85505e-05 5.63236e-04 1.78333e-04 5.98957e-04 2017-05-09 07:38:12 # DA64 -1.22527e-04 5.10878e-04 2.76760e-04 5.93806e-04 2017-05-09 07:38:12 # DV09 7.50738e-05 5.27093e-04 1.84004e-06 5.32415e-04 2017-05-09 07:38:12 # DA49 -1.37348e-05 4.43009e-04 2.27429e-04 4.98167e-04 2017-05-09 07:38:12 # DA56 -7.03592e-05 4.38824e-04 2.21822e-04 4.96711e-04 2017-05-09 07:38:12 # DV25 -3.76510e-05 2.85148e-04 4.02611e-04 4.94796e-04 2017-04-18 06:59:13 # DV08 9.97810e-06 4.69602e-04 5.92648e-05 4.73432e-04 2017-05-09 07:38:12 # DA62 1.02772e-04 4.54048e-04 6.85009e-06 4.65585e-04 2017-05-09 07:38:12 # DV11 7.20460e-05 4.07631e-04 2.09648e-04 4.64011e-04 2017-05-09 07:38:12 # DA63 -1.79997e-05 3.37000e-04 2.40000e-04 4.14117e-04 2017-04-18 06:59:13 # DA55 -9.07321e-05 3.14302e-04 2.22007e-04 3.95354e-04 2017-05-09 07:38:12 # DV15 2.66971e-04 -1.64033e-04 7.44960e-05 3.22071e-04 2017-05-09 07:38:12 # DA43 8.48647e-05 -2.65591e-04 -4.35480e-05 2.82200e-04 2017-05-09 07:38:12 # DA59 1.10043e-04 1.69446e-04 1.25700e-04 2.37954e-04 2017-05-09 07:38:12 # DA58 8.63634e-05 1.16415e-04 -1.77803e-04 2.29401e-04 2017-05-09 07:38:12 #======================================================================# # STEP 7: # Application of the WVR, Tsys and antpos cal tables #======================================================================# """ Using the task applycal, we apply the WVR, Tsys and antpos calibration tables to the data. Important to note in each applycal call below is that the gainfield parameter. For the Tsys it is important that we apply the solutions for each source to itself and not other sources as the soultions are specific to that target. """ mystep = 7 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] from recipes.almahelpers import tsysspwmap tsysmap = tsysspwmap(vis = 'uid___A002_Xbff114_X4684.ms', tsystable = 'uid___A002_Xbff114_X4684.ms.tsys', tsysChanTol = 1) applycal(vis = 'uid___A002_Xbff114_X4684.ms', field = '0', spw = '25,27,29,31,33', gaintable = ['uid___A002_Xbff114_X4684.ms.tsys', 'uid___A002_Xbff114_X4684.ms.wvr', 'uid___A002_Xbff114_X4684.ms.antpos'], gainfield = ['0', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) applycal(vis = 'uid___A002_Xbff114_X4684.ms', field = '1', spw = '25,27,29,31,33', gaintable = ['uid___A002_Xbff114_X4684.ms.tsys', 'uid___A002_Xbff114_X4684.ms.wvr', 'uid___A002_Xbff114_X4684.ms.antpos'], gainfield = ['1', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) # Note: J1337-6509 didn't have any Tsys measurement, so I used the one made on IRAS13481-6124. This is probably Ok. applycal(vis = 'uid___A002_Xbff114_X4684.ms', field = '2', spw = '25,27,29,31,33', gaintable = ['uid___A002_Xbff114_X4684.ms.tsys', 'uid___A002_Xbff114_X4684.ms.wvr', 'uid___A002_Xbff114_X4684.ms.antpos'], gainfield = ['3', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) applycal(vis = 'uid___A002_Xbff114_X4684.ms', field = '3', spw = '25,27,29,31,33', gaintable = ['uid___A002_Xbff114_X4684.ms.tsys', 'uid___A002_Xbff114_X4684.ms.wvr', 'uid___A002_Xbff114_X4684.ms.antpos'], gainfield = ['3', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) if applyonly != True: es.getCalWeightStats('uid___A002_Xbff114_X4684.ms') #======================================================================# # STEP 8: # Split out science SPWs and time average #======================================================================# """ With Apriori calibration complete we can now use the task 'split' to create a new measurement set which only include the spectral windows which we will need for the rest of calibration and science. """ mystep = 8 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.split') os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.flagversions') split(vis = 'uid___A002_Xbff114_X4684.ms', outputvis = 'uid___A002_Xbff114_X4684.ms.split', datacolumn = 'corrected', spw = '25,27,29,31,33', keepflags = True) print "# Calibration" #======================================================================# # STEP 9: # Listobs, and save original flags #======================================================================# """ This step generates another LISTOBS file. This time on the split MS which contains just the science spectral windows. This step also create and initial entry in the flag manager so that any flagging done in future steps can be reverted back to a clean slate if required. """ mystep = 9 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.listobs') listobs(vis = 'uid___A002_Xbff114_X4684.ms.split', listfile = 'uid___A002_Xbff114_X4684.ms.split.listobs') if not os.path.exists('uid___A002_Xbff114_X4684.ms.split.flagversions/Original.flags'): flagmanager(vis = 'uid___A002_Xbff114_X4684.ms.split', mode = 'save', versionname = 'Original') #======================================================================# # STEP 10: # Initial flagging #======================================================================# """ This step now flags data likely to lead to poorer calibration going forward. In general this may be a bad antenna (high Tsys etc) or bad baseline (phase wrapping etc). In this case the only data we need to flag is the shadowed antenna data. Shadowed antennas are antennas which have their view of the target obscured by the other telescope in the array. """ mystep = 10 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] # Flagging shadowed data flagdata(vis = 'uid___A002_Xbff114_X4684.ms.split', mode = 'shadow', flagbackup = False) #======================================================================# # STEP 11: # Putting a model for the flux calibrator(s) #======================================================================# """ In order to scale the visibility amplitudes correctly we use the task setjy to set the scale of the amplitudes relative the known value (and spectral index) of our Flux Calibrator 'J1427-4206'. Flux calibrators for ALMA are typically quasars or planets / larger moons. """ mystep = 11 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] setjy(vis = 'uid___A002_Xbff114_X4684.ms.split', standard = 'manual', field = 'J1427-4206', fluxdensity = [1.59906731438, 0, 0, 0], spix = -0.551424072303, reffreq = '352.603550622GHz') #======================================================================# # STEP 12: # Save flags before bandpass cal #======================================================================# """ This step, like the second part of step 9, saves state of flagging of what we have flagged up to now. This can be used to revert the data to incase of problems with the next step, bandpass. """ mystep = 12 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] flagmanager(vis = 'uid___A002_Xbff114_X4684.ms.split', mode = 'save', versionname = 'BeforeBandpassCalibration') # Bandpass calibration mystep = 13 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.ap_pre_bandpass') gaincal(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.ap_pre_bandpass', field = '0', # J1427-4206 spw = '0:0~1919,1:0~1919,2:0~239,3:0~239,4:0~3839', scan = '1,3', solint = 'int', refant = 'DA46', calmode = 'p') if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.split.ap_pre_bandpass', msName='uid___A002_Xbff114_X4684.ms.split', interactive=False) os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.bandpass') bandpass(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.bandpass', field = '0', # J1427-4206 scan = '1,3', solint = 'inf', combine = 'scan', refant = 'DA46', solnorm = True, bandtype = 'B', gaintable = 'uid___A002_Xbff114_X4684.ms.split.ap_pre_bandpass') if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.split.bandpass', msName='uid___A002_Xbff114_X4684.ms.split', interactive=False) # Save flags before gain cal mystep = 14 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] flagmanager(vis = 'uid___A002_Xbff114_X4684.ms.split', mode = 'save', versionname = 'BeforeGainCalibration') # Gain calibration mystep = 15 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.phase_int') gaincal(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.phase_int', field = '0~1', # J1427-4206,J1329-5608 solint = 'int', refant = 'DA46', gaintype = 'G', calmode = 'p', gaintable = 'uid___A002_Xbff114_X4684.ms.split.bandpass') if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.split.phase_int', msName='uid___A002_Xbff114_X4684.ms.split', interactive=False) os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.ampli_inf') gaincal(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.ampli_inf', field = '0~1', # J1427-4206,J1329-5608 solint = 'inf', refant = 'DA46', gaintype = 'T', calmode = 'a', gaintable = ['uid___A002_Xbff114_X4684.ms.split.bandpass', 'uid___A002_Xbff114_X4684.ms.split.phase_int']) if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.split.ampli_inf', msName='uid___A002_Xbff114_X4684.ms.split', interactive=False) os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.flux_inf') os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.fluxscale') mylogfile = casalog.logfile() casalog.setlogfile('uid___A002_Xbff114_X4684.ms.split.fluxscale') fluxscaleDict = fluxscale(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.ampli_inf', fluxtable = 'uid___A002_Xbff114_X4684.ms.split.flux_inf', reference = '0') # J1427-4206 casalog.setlogfile(mylogfile) if applyonly != True: es.fluxscale2(caltable = 'uid___A002_Xbff114_X4684.ms.split.ampli_inf', removeOutliers=True, msName='uid___A002_Xbff114_X4684.ms', writeToFile=True, preavg=10000) os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.phase_inf') gaincal(vis = 'uid___A002_Xbff114_X4684.ms.split', caltable = 'uid___A002_Xbff114_X4684.ms.split.phase_inf', field = '0~1', # J1427-4206,J1329-5608 solint = 'inf', refant = 'DA46', gaintype = 'G', calmode = 'p', gaintable = 'uid___A002_Xbff114_X4684.ms.split.bandpass') if applyonly != True: es.checkCalTable('uid___A002_Xbff114_X4684.ms.split.phase_inf', msName='uid___A002_Xbff114_X4684.ms.split', interactive=False) # Save flags before applycal mystep = 16 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] flagmanager(vis = 'uid___A002_Xbff114_X4684.ms.split', mode = 'save', versionname = 'BeforeApplycal') # Application of the bandpass and gain cal tables mystep = 17 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] for i in ['0']: # J1427-4206 applycal(vis = 'uid___A002_Xbff114_X4684.ms.split', field = str(i), gaintable = ['uid___A002_Xbff114_X4684.ms.split.bandpass', 'uid___A002_Xbff114_X4684.ms.split.phase_int', 'uid___A002_Xbff114_X4684.ms.split.flux_inf'], gainfield = ['', i, i], interp = 'linear,linear', calwt = True, flagbackup = False) applycal(vis = 'uid___A002_Xbff114_X4684.ms.split', field = '1,2~3', # J1337-6509,IRAS13481-6124 gaintable = ['uid___A002_Xbff114_X4684.ms.split.bandpass', 'uid___A002_Xbff114_X4684.ms.split.phase_inf', 'uid___A002_Xbff114_X4684.ms.split.flux_inf'], gainfield = ['', '1', '1'], # J1329-5608 interp = 'linear,linear', calwt = True, flagbackup = False) # Split out corrected column mystep = 18 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.cal') os.system('rm -rf uid___A002_Xbff114_X4684.ms.split.cal.flagversions') listOfIntents = ['CALIBRATE_BANDPASS#ON_SOURCE', 'CALIBRATE_FLUX#ON_SOURCE', 'CALIBRATE_PHASE#ON_SOURCE', 'CALIBRATE_WVR#ON_SOURCE', 'OBSERVE_CHECK_SOURCE#ON_SOURCE', 'OBSERVE_TARGET#ON_SOURCE'] split(vis = 'uid___A002_Xbff114_X4684.ms.split', outputvis = 'uid___A002_Xbff114_X4684.ms.split.cal', datacolumn = 'corrected', intent = ','.join(listOfIntents), keepflags = True) # Save flags after applycal mystep = 19 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print 'Step ', mystep, step_title[mystep] flagmanager(vis = 'uid___A002_Xbff114_X4684.ms.split.cal', mode = 'save', versionname = 'AfterApplycal')