#################################################################### ##################### General information ########################### ########## This script contains the steps that have already been performed to create the measurement set SDP81_B4_uncalibrated.ms.split, which can be found in the Calibration directory. This script does not need to run by the students, it is purely informative. #################################################################### ##################### Startup ########################### ########## importing packages and aliases import re import os import analysisUtils as au import analysisUtils as aU es = aU.stuffForScienceDataReduction() ############################################################################# ##################### Creating the measurement set ########################### ######### The format of raw ALMA datasets in the archive is the 'ASDM' format. One ASDM corresponds to one execution of a Scheduling Block (SB). An ASDM contains, in addition to the target observations, observations of the Bandpass Calibrator, Flux Calibrator and Phase Calibrator, as well as system temperature and radiometric measurements (WVR). ######## The first step consists in creating a measurement set based on the ASDM. importasdm('uid___A002_X924c91_X34f', asis='Antenna Station Receiver Source CalAtmosphere CalWVR CorrelatorMode SBSummary', bdfflags=True, lazy=False, process_caldevice=False) ######### rename the created measurement set os.system('mv uid___A002_X924c91_X34f.ms SDP81_B4_uncalibrated.ms') ############ The following are a few fixes of the metadata, based on known problems at the time of the observations es.fixForCSV2555('SDP81_B4_uncalibrated.ms') from casarecipes.almahelpers import fixsyscaltimes fixsyscaltimes(vis = 'SDP81_B4_uncalibrated.ms') ############################################################################ ##################### Inital flagging ########################### ########### We proceed by flagging the data which will not use for the calibration: pointing measurements and tsys measurements, as well as autocorrelations (correlations within a given antenna). Note that the information on tsys is still contained in the measurement step, as a table (which we extract later) flagdata(vis = 'SDP81_B4_uncalibrated.ms', mode = 'manual', spw = '1~21', autocorr = True, flagbackup = False) flagdata(vis = 'SDP81_B4_uncalibrated.ms', mode = 'manual', intent = '*POINTING*,*ATMOSPHERE*', flagbackup = False) ####### A list of data to be flagged for a variety of reasons is also contained in the measurement set. Let's see what those reasons are by created a plot of flagging reasons Vs time flagcmd(vis = 'SDP81_B4_uncalibrated.ms', inpmode = 'table', useapplied = True, action = 'plot', plotfile = 'SDP81_B4_uncalibrated.ms.flagcmd.png') ##### Now we can apply those proposed flags flagcmd(vis = 'SDP81_B4_uncalibrated.ms', inpmode = 'table', useapplied = True, action = 'apply') ############################################################################################## ##################### WVR: create a table of radiometer phase corrections ########################### ##### We create a table for the radiometer phase corrections, which we will later apply to the data: os.system('rm -rf SDP81_B4_uncalibrated.ms.wvr') os.system('rm -rf SDP81_B4_uncalibrated.ms.wvrgcal') mylogfile = casalog.logfile() casalog.setlogfile('SDP81_B4_uncalibrated.ms.wvrgcal') wvrgcal(vis = 'SDP81_B4_uncalibrated.ms', caltable = 'SDP81_B4_uncalibrated.ms.wvr', spw = [11, 13, 15, 17], smooth = '2.016s', toffset = 0, tie = ['SDP.81,J0909+0121'], statsource = 'SDP.81') casalog.setlogfile(mylogfile) ### and create plots to inspect the table aU.plotWVRSolutions(caltable='SDP81_B4_uncalibrated.ms.wvr', spw='11', antenna='DA56', yrange=[-199,199],subplot=22, interactive=False, figfile='SDP81_B4_uncalibrated.ms.wvr.plots/SDP81_B4_uncalibrated.ms.wvr') ############################################################################################## ##################### create a table of system temperatures ########################### ##### We create a table for the system temperature corrections, which we will also later apply to the data: os.system('rm -rf SDP81_B4_uncalibrated.ms.tsys') gencal(vis = 'SDP81_B4_uncalibrated.ms', caltable = 'SDP81_B4_uncalibrated.ms.tsys', caltype = 'tsys') ## We flag the edges of the spectral windows where tsys is measured. Note that The tsys is measured on wide spectral windows which encompass the science spectral windows flagdata(vis = 'SDP81_B4_uncalibrated.ms.tsys', mode = 'manual', spw = '9:0~3;124~127,11:0~3;124~127,13:0~3;124~127,15:0~3;124~127', flagbackup = False) ### We create plots to inspect the table. aU.plotbandpass(caltable='SDP81_B4_uncalibrated.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='SDP81_B4_uncalibrated.ms.tsys.plots.overlayTime/SDP81_B4_uncalibrated.ms.tsys') ############################################################################################## ##################### create a table of antenna positions corrections ########################### ######## Now we generate a table to use the most appropriate antenna positions. The antenna positions in the raw data correspond to position measured in the latest 'baseline run' before the observations. But the positions of the antennas may have been refined during a baseline run AFTER the observations. In that case some corrections may be derived, to be applied later. Based on our comparison to the antenna position database, we determine that 10 antennas need slight corrections. os.system('rm -rf SDP81_B4_uncalibrated.ms.antpos') gencal(vis = 'SDP81_B4_uncalibrated.ms', caltable = 'SDP81_B4_uncalibrated.ms.antpos', caltype = 'antpos', antenna = 'DA41,DA50,DA54,DA62,DA64,DV04,DV08,DV14,DV17,DV22', 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]) ############################################################################################## ##################### appyings tsys, wvr and antenna positions corrections ########################### ###### Now that we derived radiometer phase corrections, tsys corrections and antenna position corrections - we will apply those ### The tsys is recorded on different spectral windows than the observations. A 'map' must be created from casarecipes.almahelpers import tsysspwmap tsysmap = tsysspwmap(vis = 'SDP81_B4_uncalibrated.ms', tsystable = 'SDP81_B4_uncalibrated.ms.tsys', tsysChanTol = 1) ##### The correction tables are then applied applycal(vis = 'SDP81_B4_uncalibrated.ms', field = '0', spw = '11,13,15,17', gaintable = ['SDP81_B4_uncalibrated.ms.tsys', 'SDP81_B4_uncalibrated.ms.wvr', 'SDP81_B4_uncalibrated.ms.antpos'], gainfield = ['0', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) applycal(vis = 'SDP81_B4_uncalibrated.ms', field = '1', spw = '11,13,15,17', gaintable = ['SDP81_B4_uncalibrated.ms.tsys', 'SDP81_B4_uncalibrated.ms.wvr', 'SDP81_B4_uncalibrated.ms.antpos'], gainfield = ['1', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) applycal(vis = 'SDP81_B4_uncalibrated.ms', field = '2', spw = '11,13,15,17', gaintable = ['SDP81_B4_uncalibrated.ms.tsys', 'SDP81_B4_uncalibrated.ms.wvr', 'SDP81_B4_uncalibrated.ms.antpos'], gainfield = ['2', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) applycal(vis = 'SDP81_B4_uncalibrated.ms', field = '3', spw = '11,13,15,17', gaintable = ['SDP81_B4_uncalibrated.ms.tsys', 'SDP81_B4_uncalibrated.ms.wvr', 'SDP81_B4_uncalibrated.ms.antpos'], gainfield = ['3', '', ''], interp = 'linear,linear', spwmap = [tsysmap,[],[]], calwt = True, flagbackup = False) ### The weights associated to each visibility are re-calculated es.getCalWeightStats('SDP81_B4_uncalibrated.ms') ##################### Create a new measurement set from corrected data ########################### ### After application of correction tables, the measurement set SDP81_B4_uncalibrated.ms now has the uncorrected data in its 'raw' column, and the corrected data in its 'corrected' column ### We will now split the corrected column to another measurement set, conveniently called SDP81_B4_uncalibrated.ms.split. The calibrated data in the 'corrected' column of SDP81_B4_uncalibrated.ms will be placed in the 'data' column of SDP81_B4_uncalibrated.ms.split. ### We also applied to the split data spectral averaging by a factor 2, in order to reduce the dataset size. os.system('rm -rf SDP81_B4_uncalibrated.ms.split') os.system('rm -rf SDP81_B4_uncalibrated.ms.split.flagversions') split(vis = 'SDP81_B4_uncalibrated.ms', outputvis = 'SDP81_B4_uncalibrated.ms.split', datacolumn = 'corrected', spw = '11,13,15,17', width=[2,2,2,2,], keepflags = True)