# selfCalibrationDemo.py - A self-calibration script originally created by # Anita Richards in 2018 and modified by George Bendo in 2023. This example # is based on the object RXCJ2341.1+0018. The input data (RXCJ2341.split) # contains the pipeline calibrated data for only the target. # Define the dataset to be used. vis = 'RXCJ0439.split' # Define general inputs to be used in tclean. target = 'RXCJ0439.0+0520' # Target name. interactive = True # Setting for interactive cleaning. cell = '0.05arcsec' # Pixel size. imsize = [300, 300] # Image size in pixels. contchannels = '0,1,2,3:0~44;70~119' # Channels to use when creating a # continuum image. robust = 0.5 # Robust parameter value. threshold = '2.0e-6Jy' # Expected stopping threshold for # cleaning. # Define general inputs to be used in the calibration steps. refant = 'DA47' # Reference antenna. # The Python variable 'mysteps' will control which steps are executed when # the script is started using # # >>> execfile('scriptForCalibration.py') # # For example, 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. # Define the calibration steps (in the style of a standard ALMA manual # calibration or imaging script). thesteps = [] step_title = {0: 'Creation of plots and listobs file for data inspection', 1: 'Optional flagging', 2: 'Creation of a continuum image with no self-calibration', 3: 'First round of phase self-calibration', 4: 'Application of phase solutions', 5: 'Re-imaging of data after application of phase solutions', 6: 'First round of amplitude self-calibration', 7: 'Application of amplitude solutions', 8: 'Re-imaging of data after application of amplitude solutions' } 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) # Step 0 sets up the measurement set for self-calibration and produces some # plots and files for inspecting the data. mystep = 0 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) # Remove any previous self-calibration tables. clearcal(vis = vis) #clearcal(vis=linevis) # Create a listobs file with information about the dataset. listobs(vis = vis, overwrite = True, listfile = vis+'.listobs') # Create a plot for identifying line channels to exclude from the continuum # emission. for spw in ['0','1','2','3']: plotms(vis = vis, xaxis = 'channel', yaxis = 'amp', spw = spw, avgtime = '3600', avgscan = True, avgbaseline = True, overwrite = True, plotfile = vis+'spw'+spw+'amp-chan.png') # Step 1 applies additional flags if needed. mystep = 1 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) flagmanager(vis = vis, mode = 'save', versionname = 'post-split') #flagmanager(vis=linevis, # mode='save', # versionname='post-split') # Step 2 produces an initial image of the data without self-calibration and # then inserts the model into the measurement set. 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 '+target+'.clean*') tclean(vis = vis, imagename = target+'.clean', specmode = 'mfs', spw = contchannels, imsize = imsize, cell = cell, niter = 1000, weighting = 'briggs', robust = robust, gridder = 'standard', pbcor = True, threshold = threshold, interactive = interactive ) ft(vis = vis, model = target+'.clean.model', nterms = 1, usescratch = True) # Step 3 derives phase corrections from the science target data. mystep = 3 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) # Run gaincal to derive the phase corrections. os.system('rm -rf '+vis+'.p1') gaincal(vis = vis, caltable = vis+'.p1', solint = '60s', refant = refant, calmode = 'p', minsnr = 2, gaintype = 'G') # Step 4 applies the new phase calibration table to the data. mystep = 4 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) flagmanager(vis = vis, mode = 'save', versionname = 'beforeapplycal') applycal(vis = vis, gaintable = vis+'.p1', calwt = False, applymode = 'calapply', flagbackup = False) # Step 5 images the data after the phase calibration step. Note that the # image is created using the mtmfs deconvolver, which creates images using # a Taylor series expansion with a number of terms set by the nterms parameter # (which is 2 in this case). This is needed for the amplitude self- # calibration in the subsequent steps. When the image is created, the model # is inserted into the measurement set. 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 '+target+'.cleanp1*') tclean(vis = vis, imagename = target+'.cleanp1', specmode = 'mfs', deconvolver = 'mtmfs', nterms = 2, spw = contchannels, imsize = imsize, cell = cell, niter = 1000, weighting = 'briggs', robust = robust, gridder = 'standard', pbcor = True, threshold = threshold, interactive = interactive ) ft(vis = vis, model = [target+'.cleanp1.model.tt0',target+'.cleanp1.model.tt1'], nterms = 2, usescratch = True) # Step 6 derives amplitude corrections from the science target data. Note that # the phase corrections are used as an input into gaincal. mystep = 6 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) os.system('rm -rf '+vis+'.a1') gaincal(vis = vis, caltable = vis+'.a1', solint = 'inf', refant = refant, calmode = 'a', gaintable = vis+'.p1', gaintype = 'T') # Step 7 applies the new amplitude calibration table to the data. mystep = 7 if(mystep in thesteps): casalog.post('Step '+str(mystep)+' '+step_title[mystep],'INFO') print('Step ', mystep, step_title[mystep]) applycal(vis = vis, gaintable = [vis+'.p1',vis+'.a1'], calwt = False, applymode = 'calonly', flagbackup = False) # Step 8 images the data after the amplitude calibration step. 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 '+target+'.cleanap1*') tclean(vis = vis, imagename = target+'.cleanap1', specmode = 'mfs', deconvolver='mtmfs', nterms = 2, spw = contchannels, imsize = imsize, cell = cell, niter = 1000, weighting = 'briggs', robust = robust, gridder = 'standard', pbcor = True, threshold = threshold, interactive = interactive )