Difference between revisions of "Polarization Calibration based on CASA pipeline standard reduction: The radio galaxy 3C75-CASA5.4.2"

From CASA Guides
Jump to navigationJump to search
(Created page with "Category:EVLACategory:CalibrationCategory:VLA <b>This CASA Guide is for Version 5.4.0 of CASA.</b> If you are using a later version of CASA and this is the most r...")
 
 
(161 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]
 
[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]
  
<b>This CASA Guide is for Version 5.4.0 of CASA.</b> If you are using a later version of CASA and this is the most recent available guide, then you should be able to use most, if not all, of this tutorial.
+
<b>This CASA Guide is for version 5.4.2-5 of CASA that includes the VLA pipeline and is also verified to work with 5.4.1-32, but not 5.4.0-70 that does not include a pipeline.</b> If you are using a later version of CASA and this is the most recent available guide, then you should be able to use most, if not all, of this tutorial.
  
 
== Overview ==
 
== Overview ==
This CASA guide describes the calibration and imaging of a multiple-pointing continuum data set taken with the Karl G. Jansky Very Large Array (VLA) of the supernova remnant
+
This CASA guide describes the calibration and imaging of a single-pointing continuum data set taken with the Karl G. Jansky Very Large Array (VLA) of the binary black hole system 3C 75 in Abell 400 cluster of galaxies.
[http://simbad.u-strasbg.fr/simbad/sim-id?Ident=3C+391&NbIdent=1&Radius=2&Radius.unit=arcmin&submit=submit+id 3C 391].  The data were taken in early science shared-risk observing mode, with 128 MHz of bandwidth in each of two widely spaced spectral windows, centered at 4.6 and 7.5 GHz, and were set up for full polarization calibration.
+
[http://simbad.u-strasbg.fr/simbad/sim-id?Ident=3C75].  The data were taken as a demonstration for the VLA data reduction workshops under project code TDRW0001. To reduce the dataset size, the data was recorded with a single 1 GHz baseband centered at 3.0 GHz, resulting in 8x128 MHz wide spectral windows with 64 channels each. The observation was set up to allow for full polarization calibration.
  
<div style="background-color: salmon">
+
== How to Use This CASA Guide ==
<div style="background-color: salmon; margin: 20px">
+
 
<br>
+
Here are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In brief, there are at least three different ways to run CASA:
IMPORTANT DISCLAIMER:
+
 
Steps for polarization calibration often depend closely on science goals, type of polarization calibrators, and observing procedure. The polarization calibration presented in this tutorial is specific to this data set. If you are unsure whether this strategy is relevant for your own polarization data set, we encourage you to contact us through the [http://go.nrao.edu/obshelp NRAO HelpDesk]. We are currently developing a CASAguide specific to polarization in order to address this topic more broadly.
+
* Interactively examining task inputs. In this mode, one types '''taskname''' to load the task, '''inp''' to examine the inputs, and '''go''' once those inputs have been set to your satisfaction. Allowed inputs are colored blue and bad inputs are colored red. The input parameters themselves are changed one by one, e.g., ''selectdata=True''. Screenshots of the inputs to various tasks used in the data reduction are provided to illustrate which parameters need to be set. More detailed help can be obtained on any task by typing '''help ''taskname'''''. Once a task is run, the set of inputs are stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.
<br><br>
+
 
</div>
+
* Pseudo-interactively via task function calls. In this case, all of the desired inputs to a task are provided at once on the CASA command line. This tutorial is made up of such calls, which were developed by looking at the inputs for each task and deciding what needed to be changed from default values. For task function calls, only parameters that you want to be different from their defaults need to be set.
</div>
+
 
 +
* Non-interactively via a script. A series of task function calls can be combined together into a script and run from within CASA via '''execfile('scriptname.py')'''. This and other CASA Tutorial Guides have been designed to be extracted into a script via the script extractor by using the method described at the [[Extracting_scripts_from_these_tutorials]] page. Should you decide to use the script generated by the script extractor for this CASA Guide, be aware that it will require some small amount of interaction related to the plotting, occasionally suggesting that you close the graphics window and hitting return in the terminal to proceed. It is, in fact, unnecessary to close the graphics windows (it is suggested that you do so purely to keep your desktop uncluttered).
 +
 
 +
If you are a relative novice or just new to CASA, it is strongly recommended to work through this tutorial by cutting and pasting the task function calls provided below after you have read all the associated explanations. Work at your own pace, look at the inputs to the tasks to see what other options exist, and read the help files. Later, when you are more comfortable, you might try to extract the script, modify it for your purposes, and begin to reduce other data.
  
 
== Obtaining the Data ==
 
== Obtaining the Data ==
  
For the purposes of this tutorial, we have created a starting data set, upon which several initial processing steps have already been conducted.  You may obtain the data set from here:
+
If starting from scratch, you can obtain the dataset from the [https://archive.nrao.edu/ NRAO archive] and search for the Archive File ID: 'TDRW0001.sb35624494.eb35628826.58395.23719237269'. The uncalibrated visibilities have a size of 12.5 GB.
[http://casa.nrao.edu/Data/EVLA/3C391/3c391_ctm_mosaic_10s_spw0.ms.tgz http://casa.nrao.edu/Data/EVLA/3C391/3c391_ctm_mosaic_10s_spw0.ms.tgz] (dataset size: 3.1GB).
+
 
 +
For those that want to skip the step of obtaining a continuum Stokes I calibrated measurement set, we have created a starting dataset on which the polarization calibration steps and final imaging can be performed: [https://casa.nrao.edu/Data/EVLA/TDRW0001/TDRW0001_calibrated.ms.tgz https://casa.nrao.edu/Data/EVLA/TDRW0001/TDRW0001_calibrated.ms.tgz] (size: 10 GB). Recommended to use the command line tool '''wget''' to download. You will need to untar and unzip the file using the command: 'tar -xzvf TDRW0001_calibrated.ms.tgz'. Then you can skip ahead to the section 'The Observation'.
 +
 
 +
== Pipeline Calibration of Parallel Hands (RR/LL) ==
 +
 
 +
If you start with the uncalibrated visibilities obtained from the archive, you will need to first perform a standard continuum calibration of the parallel-hand (RR/LL) cross-correlation visibilities. In this guide we use the standard VLA pipeline that is packaged with the CASA release. You can find more information on the latest release of the VLA pipeline here: [https://science.nrao.edu/facilities/vla/data-processing/pipeline https://science.nrao.edu/facilities/vla/data-processing/pipeline].
 +
 
 +
In this example, we will not run the pipeline in its standard way but tweak it to force a certain reference antenna. The pipeline typically tries to pick a reference antenna at the center of the array; however this dataset was observed in D array configuration with very short baselines. It was found to be better to use one of the outer antennas for reference, which provides more longer baselines and more stable phase solutions. To set the reference antenna, we specify the ''refantignore'' parameter in some of the pipeline tasks to exclude all but the reference antenna, and use a pipeline execution script ('casa_pipescript.py'). Take the script given below and paste it into a text file inside your working directory that also contains the dataset you downloaded from the NRAO archive and name it casa_pipescript.py.
 +
 
 +
<source lang="python">
 +
# casa_pipescript.py
  
If you wish to start from the very beginning, you may download the dataset from the [https://archive.nrao.edu/archive/archiveproject.jsp NRAO Archive]: TDEM0001_sb1218006_1.55310.33439732639
+
__rethrow_casa_exceptions = True
 +
context = h_init()
 +
context.set_state('ProjectSummary', 'proposal_code', 'VLA/null')
 +
context.set_state('ProjectSummary', 'observatory', 'Karl G. Jansky Very Large Array')
 +
context.set_state('ProjectSummary', 'telescope', 'EVLA')
 +
context.set_state('ProjectSummary', 'piname', 'unknown')
 +
context.set_state('ProjectSummary', 'proposal_title', 'unknown')
 +
try:
 +
    hifv_importdata(vis=['TDRW0001.sb35624494.eb35628826.58395.23719237269'], session=['session_1'], createmms='automatic', asis='Receiver CalAtmosphere', ocorr_mode='co', nocopy=False, overwrite=False)
 +
    hifv_hanning(pipelinemode="automatic")
 +
    hifv_flagdata(tbuff=0.0, flagbackup=False, scan=True, fracspw=0.05, intents='*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*, *UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*', clip=True, baseband=True, shadow=True, quack=True, edgespw=True, autocorr=True, hm_tbuff='1.5int', template=True, online=True)
 +
    hifv_vlasetjy(fluxdensity=-1, scalebychan=True, spix=0, reffreq='1GHz')
 +
    hifv_priorcals(tecmaps=False)
 +
    hifv_testBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_flagbaddef(doflagundernspwlimit=True)
 +
    hifv_checkflag(pipelinemode="automatic")
 +
    hifv_semiFinalBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_checkflag(checkflagmode='semi')
 +
    hifv_semiFinalBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_solint(refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_fluxboot(refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_finalcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
 +
    hifv_applycals(flagdetailedsum=True, gainmap=False, flagbackup=True, flagsum=True)
 +
    hifv_targetflag(intents='*CALIBRATE*,*TARGET*')
 +
    hifv_statwt(pipelinemode="automatic")
 +
    hifv_plotsummary(pipelinemode="automatic")
 +
    hif_makeimlist(nchan=-1, calcsb=False, intent='PHASE,BANDPASS', robust=-999.0, per_eb=False, calmaxpix=300, specmode='cont', clearlist=True)
 +
    hif_makeimages(tlimit=2.0, hm_minbeamfrac=-999.0, hm_dogrowprune=True, hm_negativethreshold=-999.0, calcsb=False, target_list={}, hm_noisethreshold=-999.0, hm_masking='none', hm_minpercentchange=-999.0, parallel='automatic', masklimit=4, hm_lownoisethreshold=-999.0, hm_growiterations=-999, cleancontranges=False, hm_sidelobethreshold=-999.0)
 +
finally:
 +
    h_save()
 +
</source>
  
We are providing this starting data set, rather than the true initial data set for at least two reasons.  First, many of these initial processing steps can be rather time consuming (> 1 hr).  Second, while necessary, many of these steps are not fundamental to the calibration and imaging process, which is the focus of this tutorial. For completeness, however, here are the steps that were taken from the initial data set to produce the starting data set.
+
Now that we have the script, we can execute the pipeline. Type on the command line the following.
  
* The initial Science Data Model (SDM) file was converted into a measurement set.
+
<source lang="bash">
* Basic data flagging was applied, to account for shadowing of the antennas. These data are from the D configuration, in which antennas are particularly susceptible to being blocked (shadowed) by other antennas in the array, depending upon the elevation of the source.
+
# On the command line, for your own installation of CASA 5.4.2-5
* The data were averaged from the initial 1-second correlator sample time to 10-second samples.  In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern.
+
casa --pipeline --nogui -c casa_pipescript.py
* The data were acquired with two subbands (spectral windows) around 4.6 and 7.5 GHz.  Because of disk space concerns on some machines, the focus will be on only one of the two spectral windows.
 
  
All of these steps can be done directly from the NRAO Archive's Download page, by selecting '''CASA MS''' as the download format (it's a good idea to also check the '''Create MS or SDM tar file''' box), checking the '''Apply flags generated during observing''' box, and setting '''Time Averaging''' to 10s.
+
# If using an NRAO computer, to select the right CASA version use instead
 +
casa -r 5.4.2-5 --pipeline --nogui -c casa_pipescript.py
 +
</source>
  
Once the download is complete, unzip and unpack the file (within a working directory, which you will then run CASA):
+
Now you can go and get a cup of coffee or lunch. This is going to take a while. On a beefy computer expect about two hours. Once the pipeline has successfully finished you will see some similar messages on the command line prompt.
 +
<pre style="background-color: #E0FFFF;">
 +
2019-03-21 19:18:01 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.residual.tt0
 +
2019-03-21 19:18:01 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.model.tt0
 +
2019-03-21 19:18:02 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.mask
  
<pre style="background-color: lightgrey;”>
+
2019-03-21 19:18:06 INFO: Saving context to 'pipeline-20190321T171946.context'
# In a Terminal:
 
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz
 
 
</pre>
 
</pre>
  
== How to Use This CASA Guide ==
+
In order to be able to continue calibration for polarization, i.e. the cross-hand correlations (RL/LR), on pre-calibrated visibilities, we need to perform some additional steps that remove the parallactic angle correction that was applied by the standard pipeline. To do so, start CASA and execute the following commands.
 +
 
 +
<source lang="python">
 +
# In CASA
 +
flagmanager(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',mode='restore',versionname='applycal_5')
  
Here are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In brief, there are at least three different ways to run CASA:
+
applycal(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',
 +
antenna='*&*',  
 +
gaintable=['TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_2.gc.tbl','TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_3.opac.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_4.rq.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_6.ants.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_2.finaldelay.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_4.finalBPcal.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_5.averagephasegain.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_7.finalampgaincal.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_8.finalphasegaincal.tbl'],
 +
gainfield=['', '', '', '', '', '', '', '', ''], interp=['', '', '', '', '', 'linear,linearflag', '', '', ''],
 +
spwmap=[[], [], [], [], [], [], [], [], []],
 +
calwt=[False, False, False, False, False, False, False, False, False],
 +
parang=False,
 +
applymode='calflagstrict',
 +
flagbackup=False)
  
* Interactively examining task inputs. In this mode, one types '''taskname''' to load the task, '''inp''' to examine the inputs, and '''go''' once those inputs have been set to your satisfaction. Allowed inputs are shown in blue and bad inputs are colored red. The input parameters themselves are changed one by one, e.g., ''selectdata=True''. Screenshots of the inputs to various tasks used in the data reduction below are provided, to illustrate which parameters need to be set. More detailed help can be obtained on any task by typing '''help ''taskname'''''. Once a task is run, the set of inputs are stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.
+
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', mode='rflag', correlation='ABS_LL,RR', intent='*CALIBRATE*', datacolumn='corrected', ntime='scan', combinescans=False, extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0, action='apply', flagbackup=False, savepars=True)
 +
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', mode='rflag', correlation='ABS_LL,RR', intent='*TARGET*', datacolumn='corrected', ntime='scan', combinescans=False, extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0, action='apply', flagbackup=False, savepars=True)
  
* Pseudo-interactively via task function calls. In this case, all of the desired inputs to a task are provided at once on the CASA command line. This tutorial is made up of such calls, which were developed by looking at the inputs for each task and deciding what needed to be changed from default values. For task function calls, only parameters that you want to be different from their defaults need to be set.
+
statwt(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', minsamp=8, datacolumn='corrected', flagbackup=False)
  
* Non-interactively via a script. A series of task function calls can be combined together into a script, and run from within CASA via '''execfile('scriptname.py')'''. This and other CASA Tutorial Guides have been designed to be extracted into a script via the script extractor by using the method described at the [[Extracting_scripts_from_these_tutorials]] page. Should you use the script generated by the script extractor for this CASA Guide, be aware that it will require some small amount of interaction related to the plotting, occasionally suggesting that you close the graphics window and hitting return in the terminal to proceed. It is in fact unnecessary to close the graphics windows (it is suggested that you do so purely to keep your desktop uncluttered).
+
split(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',outputvis='TDRW0001_calibrated.ms',datacolumn='corrected',spw='2~9')
 +
</source>
  
If you are a relative novice or just new to CASA, it is strongly recommended to work through this tutorial by cutting and pasting the task function calls provided below after you have read all the associated explanations. Work at your own pace, look at the inputs to the tasks to see what other options exist, and read the help files. Later, when you are more comfortable, you might try to extract the script, modify it for your purposes, and begin to reduce other data.
+
This applies the flagging state before the final {{applycal}} stage of the pipeline, then reapplies the calibration to the corrected column with ''parang=False'', thus disabling the parallactic angle corrections. After that, we rerun target field flagging, and recompute the weights based on the new flags that were applied and split out the corrected column for the target spectral windows. Essentially, we repeated what pipeline tasks hifv_applycals, hifv_targetflag, and hifv_statwt did, but disabling application of parallactic angle corrections. This is the measurement set we will be using in the following to demonstrate polarization calibration.
  
 
== The Observation ==
 
== The Observation ==
  
Before starting the calibration process, we want to get some basic information about the data set. To examine the observing conditions during the observing run, and to find out any known problems with the data, download the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log]. Simply fill in the known observing date (in our case 2010-Apr-24) as both the Start and Stop date, and click on the '''Show Logs''' button.  The relevant log is labeled with the project code, TDEM0001, and can be downloaded as a PDF file. From this, we find the following:
+
Before starting the calibration process, we want to get some basic information about the data set. To examine the observing conditions during the observing run, and to find out any known problems with the data, download the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log]. Simply fill in the known observing date (in our case 2018-Oct-04) as both the Start and Stop date and click on the '''Show Logs''' button.  The relevant log is labelled with the project code, TDRW0001, and can be downloaded as a [http://www.vla.nrao.edu/operators/logs/2018/10/2018-10-04_0541_TDRW0001.pdf PDF file]. From this, we find the following:
  
 
<pre style="background-color: #E0FFFF;">
 
<pre style="background-color: #E0FFFF;">
 
Information from observing log:
 
Information from observing log:
There is no C-band receivers on ea13
+
Antennas in the D-array may be shadowed at low elevations.  If shadowing
Antenna ea06 is out of the array
+
occurs, sensitivity will be affected.
Antenna ea15 has some corrupted data
+
 
 +
NOTE!: The VLA is still recovering from a long power outage, and these data may
 +
have unusual artifacts, missing antennas or IFs, ect., in them. NRAO staff will
 +
examine the data closely after observing to determine if they meet the criteria for
 +
a successful observation.
 +
 
 +
Antenna ea05: S-band receiver cooling after work performed, currently 65/177K,
 +
              thus we expect lower sensitivity from this antenna.
 +
Antenna ea12: C-band receiver warm for cold head replacement.
 
Antennas ea10, ea12, ea22 do not have good baseline positions
 
Antennas ea10, ea12, ea22 do not have good baseline positions
Gusty winds, mixed clouds, API rms up to 11.5.
+
Winds at 7-5 m/s, API RMS phase around 4 deg., 10-20% sky cover, cumuliform and stratiform clouds.  
 
</pre>
 
</pre>
  
Before beginning our data reduction, we must start CASA. If you have not used CASA before, some helpful tips are available on the [[Getting Started in CASA]] page.
+
Before beginning our data reduction, we should inspect the pipeline calibration weblog for any obvious issues. You can download the weblog from [https://casa.nrao.edu/Data/EVLA/TDRW0001/weblog.tgz https://casa.nrao.edu/Data/EVLA/TDRW0001/weblog.tgz] or directly access it at [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/ https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/].
  
Once you have CASA up and running in the directory containing the data, then start your data reduction by getting some basic information about the data.  The task {{listobs}} can be used to get a listing of the individual scans comprising the observation, the frequency setup, source list, and antenna locations.
+
Inside the weblog, you have access to the [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t2-1.html?sidebar=sidebar_TDRW0001_sb35624494_eb35628826_58395_23719237269_ms&subpage=t2-1_details.html overview page] and the [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t2-1.html?sidebar=sidebar_TDRW0001_sb35624494_eb35628826_58395_23719237269_ms&subpage=listobs.txt listobs] task output that provide some basic information about the data.   
 
 
<source lang="python">
 
# In CASA
 
listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')
 
</source>
 
  
One will note that there are ten sources observed. Here the various sources are introduced briefly, with more detail contained in the sections below in which they are used.
+
You will note that there are four sources observed. Here the various sources are introduced briefly, with more detail contained in the sections below in which they are used
* J1331+3030 = 3C 286, which will later serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density; the spectral bandpass; and the polarization position angle;
+
* 0137+331=3C48, which will serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, the spectral bandpass, and the polarization position angle;
* J1822-0938, which will serve as a calibrator for the visibility phases;
+
* J0259+0747, which will serve as a calibrator for the visibility phases and can be used to determine the instrumental polarization;
* J0319+4130 = 3C 84, which will serve as a polarization calibrator; and
+
* J2355+4950, which can serve as a secondary instrumental polarization calibrator or to check residual instrumental polarization, and;
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.
+
* 3C75, which is the science target.
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.
 
  
  
 
<pre style="background-color: #fffacd;">
 
<pre style="background-color: #fffacd;">
##########################################
 
##### Begin Task: listobs            #####
 
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",
 
        uvrange="",timerange="",correlation="",scan="",intent="",
 
        feed="",array="",observation="",verbose=True,listfile="",
 
        listunfl=False,cachesize=50,overwrite=False)
 
 
================================================================================
 
================================================================================
           MeasurementSet Name:  3c391_ctm_mosaic_10s_spw0.ms      MS Version 2
+
           MeasurementSet Name:  /lustre/aoc/sciops/dmedlin/4fs/TDRW0001.sb35624494.eb35628826.58395.23719237269.ms      MS Version 2
 
================================================================================
 
================================================================================
   Observer: Dr. James Miller-Jones     Project: T.B.D.  
+
   Observer: Dr. Emmanuel Momjian     Project: uid://evla/pdb/35621723  
 
Observation: EVLA
 
Observation: EVLA
Data records: 845379       Total integration time = 28681.5 seconds
+
Data records: 5752188       Total elapsed time = 10270 seconds
   Observed from  24-Apr-2010/08:02:10.0  to  24-Apr-2010/16:00:11.5 (UTC)
+
   Observed from  04-Oct-2018/05:41:35.0  to  04-Oct-2018/08:32:45.0 (UTC)
 
+
 
 
   ObservationID = 0        ArrayID = 0
 
   ObservationID = 0        ArrayID = 0
 
   Date        Timerange (UTC)          Scan  FldId FieldName            nRows    SpwIds  Average Interval(s)    ScanIntent
 
   Date        Timerange (UTC)          Scan  FldId FieldName            nRows    SpwIds  Average Interval(s)    ScanIntent
   24-Apr-2010/08:02:10.0 - 08:02:30.0    1      0 J1331+3030                650 [0]  [10]  
+
   04-Oct-2018/05:41:35.0 - 05:42:31.0    1      0 0137+331=3C48            39312 [0,1]  [1, 1] [SYSTEM_CONFIGURATION#UNSPECIFIED]
               08:02:20.0 - 08:09:30.0    2      0 J1331+3030              13975 [0]  [10]  
+
               05:42:32.0 - 05:47:30.0    2      0 0137+331=3C48          209196 [0,1]  [1, 1] [SYSTEM_CONFIGURATION#UNSPECIFIED]
               08:09:20.0 - 08:16:28.0    3      0 J1331+3030              13975 [0]  [10]
+
               05:47:35.0 - 05:48:30.0    3      0 0137+331=3C48            30888 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]
               08:19:38.0 - 08:24:26.5     4      1 J1822-0938                7035  [0] [10]  
+
               05:48:35.0 - 05:49:00.0     4      0 0137+331=3C48            14040 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]
               08:24:48.0 - 08:29:48.0    5      2 3C391 C1                  7590 [0] [10]  
+
               05:49:05.0 - 05:53:25.0    5      0 0137+331=3C48          146016  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_POL_ANGLE#UNSPECIFIED]
               08:29:38.0 - 08:34:48.0    6      3 3C391 C2                  7821 [0] [10]  
+
               05:53:30.0 - 05:57:55.0    6      1 J2355+4950              148824  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]
               08:34:38.0 - 08:39:48.0    7      4 3C391 C3                  7821 [0] [10]  
+
               05:58:00.0 - 06:03:55.0    7      2 J0259+0747              199368  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               08:39:38.0 - 08:44:48.0    8      5 3C391 C4                  7821 [0] [10]  
+
               06:04:00.0 - 06:18:55.0    8      3 3C75                    502632  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               08:44:38.0 - 08:49:48.0    9      6 3C391 C5                  7843 [0]  [10]  
+
               06:19:00.0 - 06:20:10.0    9      2 J0259+0747              39312 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               08:49:38.0 - 08:54:48.0    10      7 3C391 C6                  7843 [0]  [10]
+
               06:20:15.0 - 06:35:05.0    10      3 3C75                    499824 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               08:54:38.0 - 08:59:43.5   11      8 3C391 C7                  7843 [0]  [10]  
+
               06:35:10.0 - 06:36:20.0   11      2 J0259+0747              39312 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:00:03.0 - 09:01:31.0    12      1 J1822-0938                2925 [0]  [10]  
+
               06:36:25.0 - 06:51:20.0    12      3 3C75                    502632 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:01:52.0 - 09:06:52.0    13      2 3C391 C1                  7941 [0]  [10]  
+
               06:51:25.0 - 06:52:30.0    13      2 J0259+0747              36504 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:06:42.0 - 09:11:52.0    14      3 3C391 C2                  9801 [0]  [10]  
+
               06:52:35.0 - 07:07:30.0    14      3 3C75                    502632 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:11:42.0 - 09:16:52.0    15      4 3C391 C3                10075 [0] [10]  
+
               07:07:35.0 - 07:08:45.0    15      2 J0259+0747              39312  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:16:42.0 - 09:21:52.0    16      5 3C391 C4                10050 [0] [10]  
+
               07:08:50.0 - 07:23:40.0    16      3 3C75                    499824  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:21:42.0 - 09:26:52.0    17      6 3C391 C5                10075 [0] [10]  
+
               07:23:45.0 - 07:26:25.0    17      2 J0259+0747              89856  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:26:42.0 - 09:31:52.0    18      7 3C391 C6                10075 [0] [10]  
+
               07:26:30.0 - 07:41:25.0    18      3 3C75                    502632  [2,3,4,5,6,7,8,9] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:31:42.0 - 09:36:47.5   19      8 3C391 C7                10075 [0]  [10]
+
               07:41:30.0 - 07:42:40.0   19      2 J0259+0747              39312 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              09:37:07.0 - 09:38:35.0    20      1 J1822-0938                2900 [0]  [10]  
+
              07:42:45.0 - 07:57:35.0    20      3 3C75                    499824 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:38:57.0 - 09:43:57.0    21      2 3C391 C1                  9700 [0]  [10]  
+
               07:57:40.0 - 07:58:50.0    21      2 J0259+0747              39312 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:43:47.0 - 09:48:57.0    22      3 3C391 C2                10050 [0]  [10]
+
               07:58:55.0 - 08:13:50.0    22      3 3C75                    502632 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:48:47.0 - 09:53:57.0    23      4 3C391 C3                10075 [0]  [10]  
+
               08:13:55.0 - 08:15:05.0    23      2 J0259+0747              39312 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
               09:53:47.0 - 09:58:57.0    24      5 3C391 C4                10075 [0]  [10]  
+
               08:15:10.0 - 08:30:00.0    24      3 3C75                    499824 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
               09:58:47.0 - 10:03:57.0    25      6 3C391 C5                10075 [0]  [10]  
+
               08:30:05.0 - 08:32:45.0    25      2 J0259+0747              89856 [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              10:03:47.0 - 10:08:57.0    26      7 3C391 C6                10075  [0]  [10]
 
              10:08:47.0 - 10:13:47.0    27      8 3C391 C7                  9750  [0]  [10]
 
              10:14:12.0 - 10:15:39.5    28      1 J1822-0938                2925  [0]  [10]
 
              10:16:01.0 - 10:21:01.0    29      2 3C391 C1                  9000  [0]  [10]
 
              10:20:51.0 - 10:26:01.0    30      3 3C391 C2                10050  [0]  [10]
 
              10:25:51.0 - 10:31:01.0    31      4 3C391 C3                10075  [0]  [10]
 
              10:30:51.0 - 10:36:01.0    32      5 3C391 C4                10075  [0]  [10]
 
              10:35:51.0 - 10:41:01.0    33      6 3C391 C5                10075  [0]  [10]
 
              10:40:51.0 - 10:46:01.0    34      7 3C391 C6                10075  [0]  [10]
 
              10:45:51.0 - 10:50:51.0    35      8 3C391 C7                  9750  [0]  [10]
 
              10:51:15.0 - 10:52:42.5    36      1 J1822-0938                2925  [0]  [10]
 
              10:55:14.0 - 10:57:42.0    37      0 J1331+3030                3364  [0]  [10]
 
              11:00:13.0 - 11:02:41.0    38      1 J1822-0938                3883  [0]  [10]
 
              11:03:03.0 - 11:08:03.0    39      2 3C391 C1                  9750  [0]  [10]
 
              11:07:53.0 - 11:12:53.0    40      3 3C391 C2                  9725  [0]  [10]
 
              11:12:43.0 - 11:17:43.0    41      4 3C391 C3                  9750  [0]  [10]
 
              11:17:33.0 - 11:22:33.0    42      5 3C391 C4                  9750  [0]  [10]
 
              11:22:23.0 - 11:27:23.0    43      6 3C391 C5                  9750  [0]  [10]
 
              11:27:13.0 - 11:32:13.0    44      7 3C391 C6                  9750  [0]  [10]
 
              11:32:03.0 - 11:36:53.0    45      8 3C391 C7                  9425  [0]  [10]
 
              11:37:21.0 - 11:38:47.0    46      1 J1822-0938                2700  [0]  [10]
 
              11:39:11.0 - 11:44:11.0    47      2 3C391 C1                  9750  [0]  [10]
 
              11:44:01.0 - 11:49:01.0    48      3 3C391 C2                  9700  [0]  [10]
 
              11:48:51.0 - 11:53:41.0    49      4 3C391 C3                  8355  [0]  [10]
 
              11:53:41.0 - 11:58:31.0    50      5 3C391 C4                  9425  [0]  [10]
 
              11:58:21.0 - 12:03:21.0    51      6 3C391 C5                  9725  [0]  [10]
 
              12:03:11.0 - 12:08:11.0    52      7 3C391 C6                  9701  [0]  [10]
 
              12:08:01.0 - 12:12:59.0    53      8 3C391 C7                  9725  [0]  [10]
 
              12:13:29.0 - 12:14:48.0    54      1 J1822-0938                2600  [0]  [10]
 
              12:15:18.0 - 12:20:08.0    55      2 3C391 C1                  9425  [0]  [10]
 
              12:19:58.0 - 12:24:58.0    56      3 3C391 C2                  9750  [0]  [10]
 
              12:24:48.0 - 12:29:48.0    57      4 3C391 C3                  9750  [0]  [10]
 
              12:29:38.0 - 12:34:38.0    58      5 3C391 C4                  9725  [0]  [10]
 
              12:34:28.0 - 12:39:28.0    59      6 3C391 C5                  9725  [0]  [10]
 
              12:39:18.0 - 12:44:18.0    60      7 3C391 C6                  9750  [0]  [10]
 
              12:44:08.0 - 12:49:04.5    61      8 3C391 C7                  9750  [0]  [10]
 
              12:49:35.0 - 12:50:53.0    62      1 J1822-0938                2600  [0]  [10]
 
              12:51:24.0 - 12:56:14.0    63      2 3C391 C1                  9425  [0]  [10]
 
              12:56:04.0 - 13:01:04.0    64      3 3C391 C2                  9000  [0]  [10]
 
              13:00:54.0 - 13:05:54.0    65      4 3C391 C3                  9750  [0]  [10]
 
              13:05:44.0 - 13:10:44.0    66      5 3C391 C4                  9750  [0]  [10]
 
              13:10:34.0 - 13:15:34.0    67      6 3C391 C5                  9725  [0]  [10]
 
              13:15:24.0 - 13:20:24.0    68      7 3C391 C6                  9750  [0]  [10]
 
              13:20:14.0 - 13:25:10.0    69      8 3C391 C7                  9000  [0]  [10]
 
              13:25:40.0 - 13:26:57.5    70      1 J1822-0938                2600  [0]  [10]
 
              13:27:28.0 - 13:32:18.0    71      2 3C391 C1                  9425  [0]  [10]
 
              13:32:08.0 - 13:37:08.0    72      3 3C391 C2                  9750  [0]  [10]
 
              13:36:58.0 - 13:41:58.0    73      4 3C391 C3                  9750  [0]  [10]
 
              13:41:48.0 - 13:46:48.0    74      5 3C391 C4                  9750  [0]  [10]
 
              13:46:38.0 - 13:51:38.0    75      6 3C391 C5                  9725  [0]  [10]
 
              13:51:28.0 - 13:56:28.0    76      7 3C391 C6                  9750  [0]  [10]
 
              13:56:18.0 - 14:01:14.0    77      8 3C391 C7                  9750  [0]  [10]
 
              14:01:44.0 - 14:03:01.5    78      1 J1822-0938                2024  [0]  [10]
 
              14:03:33.0 - 14:08:23.0    79      2 3C391 C1                  8900  [0]  [10]
 
              14:08:13.0 - 14:13:13.0    80      3 3C391 C2                  9750  [0]  [10]
 
              14:13:03.0 - 14:18:03.0    81      4 3C391 C3                  9750  [0]  [10]
 
              14:17:53.0 - 14:22:53.0    82      5 3C391 C4                  9350  [0]  [10]
 
              14:22:43.0 - 14:27:43.0    83      6 3C391 C5                  9000  [0]  [10]
 
              14:27:33.0 - 14:32:33.0    84      7 3C391 C6                  8595  [0]  [10]
 
              14:32:23.0 - 14:37:18.5    85      8 3C391 C7                  7590  [0]  [10]
 
              14:37:48.0 - 14:39:05.5    86      1 J1822-0938                1848  [0]  [10]
 
              14:39:36.0 - 14:44:26.0    87      2 3C391 C1                  7337  [0]  [10]
 
              14:44:16.0 - 14:49:16.0    88      3 3C391 C2                  7568  [0]  [10]
 
              14:49:06.0 - 14:54:06.0    89      4 3C391 C3                  7590  [0]  [10]
 
              14:53:56.0 - 14:58:56.0    90      5 3C391 C4                  7527  [0]  [10]
 
              14:58:46.0 - 15:03:46.0    91      6 3C391 C5                  7568  [0]  [10]
 
              15:03:36.0 - 15:08:36.0    92      7 3C391 C6                  7590  [0]  [10]
 
              15:08:26.0 - 15:13:22.0    93      8 3C391 C7                  7590  [0]  [10]
 
              15:13:51.0 - 15:15:09.0    94      1 J1822-0938                1680  [0]  [10]
 
              15:15:40.0 - 15:20:30.0    95      2 3C391 C1                  7337  [0]  [10]
 
              15:20:20.0 - 15:25:20.0    96      3 3C391 C2                  7568  [0]  [10]
 
              15:25:10.0 - 15:30:10.0    97      4 3C391 C3                  7590  [0]  [10]
 
              15:30:00.0 - 15:35:00.0    98      5 3C391 C4                  7564  [0]  [10]
 
              15:34:50.0 - 15:39:50.0    99      6 3C391 C5                  7260  [0]  [10]
 
              15:39:40.0 - 15:44:40.0  100      7 3C391 C6                  6930  [0]  [10]
 
              15:44:30.0 - 15:49:26.0  101      8 3C391 C7                  6930  [0]  [10]
 
              15:49:55.0 - 15:51:13.5  102      1 J1822-0938                1088  [0]  [10]
 
              15:54:52.0 - 16:00:11.5  103      9 J0319+4130                8768  [0]  [10]  
 
 
           (nRows = Total number of rows per scan)  
 
           (nRows = Total number of rows per scan)  
Fields: 10
+
Fields: 4
 
   ID  Code Name                RA              Decl          Epoch  SrcId      nRows
 
   ID  Code Name                RA              Decl          Epoch  SrcId      nRows
   0    N    J1331+3030          13:31:08.287984 +30.30.32.95886 J2000  0         31964
+
   0    NONE 0137+331=3C48      01:37:41.299431 +33.09.35.13299 J2000  0         439452
   1    J    J1822-0938         18:22:28.704200 -09.38.56.83501 J2000  1         39733
+
   1    NONE J2355+4950         23:55:09.458169 +49.50.08.34001 J2000  1         148824
   2    NONE 3C391 C1            18:49:24.244000 -00.55.40.58001 J2000  2        105580
+
   2    NONE J0259+0747          02:59:27.076633 +07.47.39.64322 J2000  2        651456
   3    NONE 3C391 C2            18:49:29.149001 -00.57.48.00001 J2000  3         110533
+
   3    NONE 3C75                02:57:42.630000 +06.01.04.80000 J2000  3       4512456
   4   NONE 3C391 C3            18:49:19.339000 -00.57.48.00001 J2000   4        110331
+
Spectral Windows:  (10 unique spectral windows and 1 unique polarization setups)
   5   NONE 3C391 C4            18:49:14.434001 -00.55.40.58001 J2000   5        110862
+
  SpwID  Name          #Chans  Frame  Ch0(MHz)  ChanWid(kHz)  TotBW(kHz) CtrFreq(MHz) BBC Num  Corrs         
   6   NONE 3C391 C5            18:49:19.339000 -00.53.33.16000 J2000   6        110546
+
   0      EVLA_C#A0C0#0    64  TOPO    4832.000      2000.000   128000.0  4895.0000      12  RR  RL  LR  LL
   7   NONE 3C391 C6            18:49:29.149001 -00.53.33.16000 J2000   7        109884
+
  1      EVLA_C#B0D0#1    64  TOPO    4960.000      2000.000    128000.0   5023.0000      15  RR  RL  LR  LL
   8   NONE 3C391 C7            18:49:34.054000 -00.55.40.58001 J2000   8        107178
+
   2      EVLA_S#A0C0#2    64  TOPO   2488.000      2000.000    128000.0  2551.0000      12  RR  RL  LR  LL
   9   Z   J0319+4130          03:19:48.160102 +41.30.42.10305 J2000   9          8768
+
   3      EVLA_S#A0C0#3    64   TOPO   2616.000      2000.000    128000.0  2679.0000      12  RR  RL  LR  LL
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)
+
   4      EVLA_S#A0C0#4    64   TOPO   2744.000      2000.000    128000.0  2807.0000      12  RR  RL  LR  LL
   SpwID  Name     #Chans   Frame   Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs         
+
   5      EVLA_S#A0C0#5    64   TOPO   2872.000      2000.000    128000.0  2935.0000      12  RR  RL  LR  LL
   0     Subband:0     64  TOPO    4536.000      2000.000    128000.0  4599.0000   RR  RL  LR  LL
+
   6      EVLA_S#A0C0#6    64   TOPO   3000.000      2000.000   128000.0  3063.0000      12  RR  RL  LR  LL
Sources: 10
+
  7      EVLA_S#A0C0#7    64  TOPO    3128.000      2000.000    128000.0   3191.0000      12  RR  RL  LR LL
 +
   8     EVLA_S#A0C0#8    64   TOPO    3256.000      2000.000    128000.0   3319.0000      12  RR RL LR LL
 +
   9     EVLA_S#A0C0#9     64  TOPO    3384.000      2000.000    128000.0  3447.0000       12  RR  RL  LR  LL
 +
Sources: 34
 
   ID  Name                SpwId RestFreq(MHz)  SysVel(km/s)  
 
   ID  Name                SpwId RestFreq(MHz)  SysVel(km/s)  
   0    J1331+3030          0    -              -             
+
   0    0137+331=3C48      0    -              -             
   1    J1822-0938          0    -              -             
+
   0    0137+331=3C48      1     -              -           
   2   3C391 C1           0    -              -             
+
  0   0137+331=3C48      2    -             -           
   3   3C391 C2           0    -              -             
+
  0   0137+331=3C48      3     -              -             
   4   3C391 C3           0    -              -             
+
   0   0137+331=3C48      4    -              -            
   5    3C391 C4           0     -              -             
+
  0   0137+331=3C48      5     -              -             
   6   3C391 C5           0     -              -             
+
   0   0137+331=3C48      6    -              -            
   7   3C391 C6           0     -              -             
+
  0   0137+331=3C48      7     -              -             
   8   3C391 C7           0     -              -             
+
   0   0137+331=3C48      8    -              -            
   9   J0319+4130         0     -              -             
+
  0   0137+331=3C48      9    -              -           
Antennas: 26:
+
  1    J2355+4950          2     -              -             
 +
   1    J2355+4950          3    -              -           
 +
  1    J2355+4950          4    -              -           
 +
  1    J2355+4950          5     -              -           
 +
  1    J2355+4950          6    -              -           
 +
  1   J2355+4950          7    -              -            
 +
  1    J2355+4950          8    -              -           
 +
  1    J2355+4950          9     -              -             
 +
   2   J0259+0747          2    -              -            
 +
  2    J0259+0747          3    -              -           
 +
  2    J0259+0747          4     -              -             
 +
   2   J0259+0747          5    -              -            
 +
  2    J0259+0747          6     -              -             
 +
   2   J0259+0747          7    -              -            
 +
  2    J0259+0747          8     -              -             
 +
   2   J0259+0747         9    -              -           
 +
  3    3C75                2    -              -           
 +
  3    3C75                3    -              -           
 +
  3    3C75                4    -              -           
 +
  3    3C75                5    -              -           
 +
  3    3C75                6    -              -           
 +
  3    3C75                7    -              -           
 +
  3    3C75                8    -              -           
 +
  3    3C75                9     -              -             
 +
Antennas: 27:
 
   ID  Name  Station  Diam.    Long.        Lat.                Offset from array center (m)                ITRF Geocentric coordinates (m)         
 
   ID  Name  Station  Diam.    Long.        Lat.                Offset from array center (m)                ITRF Geocentric coordinates (m)         
 
                                                                     East        North    Elevation              x              y              z
 
                                                                     East        North    Elevation              x              y              z
   0    ea01  W09       25.0 m  -107.37.25.2 +33.53.51.0       -521.9407     -332.7782       -1.1977 -1601710.017000 -5042006.928200 3554602.355600
+
   0    ea01  W06       25.0 m  -107.37.15.6 +33.53.56.4       -275.8278     -166.7360       -2.0595 -1601447.195400 -5041992.497600 3554739.694800
   1    ea02  E02       25.0 m  -107.37.04.4 +33.54.01.1         9.8247     -20.4292       -2.7808 -1601150.059500 -5042000.619800 3554860.729400
+
   1    ea02  W04       25.0 m  -107.37.10.8 +33.53.59.1       -152.8711     -83.7955       -2.4675 -1601315.900500 -5041985.306670 3554808.309400
   2    ea03  E09       25.0 m  -107.36.45.1 +33.53.53.6        506.0591     -251.8666       -3.5832 -1600715.948000 -5042273.187000 3554668.184500
+
   2    ea03  W07       25.0 m  -107.37.18.4 +33.53.54.8      -349.9804     -216.7527       -1.7877 -1601526.383100 -5041996.851000 3554698.331400
   3    ea04  W01       25.0 m  -107.37.05.9 +33.54.00.5       -27.3562     -41.3030       -2.7418 -1601189.030140 -5042000.493300 3554843.425700
+
   3    ea04  N04       25.0 m  -107.37.06.5 +33.54.06.1       -42.6260     132.8521       -3.5428 -1601173.981600 -5041902.657800 3554987.528200
   4    ea05  W08       25.0 m  -107.37.21.6 +33.53.53.0      -432.1158    -272.1493       -1.5032 -1601614.091000 -5042001.655700 3554652.509300
+
   4    ea05  E05       25.0 m  -107.36.58.4 +33.53.58.8        164.9709      -92.7908       -2.5361 -1601014.465100 -5042086.235700 3554800.804900
   5    ea07 N06      25.0 m  -107.37.06.9  +33.54.10.3        -54.0667     263.8720       -4.2292 -1601162.593200 -5041829.000000 3555095.890500
+
   5    ea06 N06      25.0 m  -107.37.06.9  +33.54.10.3        -54.0745     263.8800       -4.2325 -1601162.598500 -5041828.990800 3555095.895300
   6    ea08 N01       25.0 m  -107.37.06.0 +33.54.01.8       -30.8810      -1.4664       -2.8597 -1601185.634945 -5041978.156586 3554876.424700
+
   6    ea07 E04       25.0 m  -107.37.00.8 +33.53.59.7       102.8035      -63.7671       -2.6299 -1601068.794800 -5042051.918100 3554824.842700
   7    ea09 E06       25.0 m  -107.36.55.6 +33.53.57.7       236.9058    -126.3369       -2.4443 -1600951.588000 -5042125.911000 3554773.012300
+
   7    ea08 E01       25.0 m  -107.37.05.7 +33.53.59.2       -23.8867      -81.1272       -2.5808 -1601192.486700 -5042022.840700 3554810.460900
   8    ea11 E04       25.0 m  -107.37.00.8 +33.53.59.7       102.8046     -63.7684       -2.6412 -1601068.791200 -5042051.910200 3554824.835300
+
   8    ea09 N05       25.0 m  -107.37.06.7 +33.54.08.0       -47.8569     192.6072       -3.8789 -1601168.794400 -5041869.042300 3555036.937000
   9    ea12 E08      25.0 m  -107.36.48.9  +33.53.55.1        407.8394     -206.0057       -3.2252 -1600801.916000 -5042219.371000 3554706.449900
+
   9    ea10 E08      25.0 m  -107.36.48.9  +33.53.55.1        407.8379     -206.0064       -3.2255 -1600801.917500 -5042219.370600 3554706.449200
   10  ea13 N07      25.0 m  -107.37.07.2  +33.54.12.9        -61.1040     344.2335       -4.6144 -1601155.635800 -5041783.843000 3555162.374100
+
   10  ea11 N07      25.0 m  -107.37.07.2  +33.54.12.9        -61.1072     344.2424       -4.6414 -1601155.630600 -5041783.816000 3555162.366400
   11  ea14 E05       25.0 m  -107.36.58.4  +33.53.58.8       164.9788      -92.8032       -2.5268 -1601014.462000 -5042086.252000 3554800.799800
+
   11  ea12 E07       25.0 m  -107.36.52.4  +33.53.56.5       318.0401    -164.1704       -2.6834 -1600880.582300 -5042170.386600 3554741.476400
   12  ea15 W06       25.0 m  -107.37.15.6 +33.53.56.4      -275.8288    -166.7451       -2.0590 -1601447.198000 -5041992.502500 3554739.687600
+
   12  ea13 W02       25.0 m  -107.37.07.5 +33.54.00.9        -67.9810      -26.5266       -2.7142 -1601225.261900 -5041980.363990 3554855.705700
   13  ea16 W02       25.0 m  -107.37.07.5 +33.54.00.9       -67.9687      -26.5614       -2.7175 -1601225.255200 -5041980.383590 3554855.675000
+
   13  ea14 E09       25.0 m  -107.36.45.1 +33.53.53.6       506.0539    -251.8836       -3.5735 -1600715.958300 -5042273.202200 3554668.175800
   14  ea17 W07       25.0 m  -107.37.18.4 +33.53.54.8      -349.9866    -216.7507       -1.7978 -1601526.386100 -5041996.840100 3554698.327400
+
   14  ea15 N03       25.0 m  -107.37.06.3 +33.54.04.8       -39.1086      93.0234       -3.3585 -1601177.399560 -5041925.041300  3554954.573300
   15   ea18 N09      25.0 m  -107.37.07.8  +33.54.19.0        -77.4352     530.6274       -5.5867 -1601139.485500 -5041679.036000 3555316.532800
+
  15  ea16  E02       25.0 m  -107.37.04.4  +33.54.01.1         9.8042      -20.4562      -2.7822 -1601150.083300 -5042000.626900 3554860.706200
   16   ea19 W04       25.0 m  -107.37.10.8 +33.53.59.1       -152.8599      -83.8054       -2.4614 -1601315.893000 -5041985.320170 3554808.304600
+
   16   ea17 N09      25.0 m  -107.37.07.8  +33.54.19.0        -77.4340     530.6515       -5.5829 -1601139.481300 -5041679.026500 3555316.554900
   17   ea20 N05       25.0 m  -107.37.06.7 +33.54.08.0        -47.8454      192.6015       -3.8723 -1601168.786100 -5041869.054000 3555036.936000
+
   17   ea18 W09       25.0 m  -107.37.25.2 +33.53.51.0       -521.9447    -332.7673       -1.2061 -1601710.016800 -5042006.914600 3554602.360000
   18   ea21 E01       25.0 m  -107.37.05.7 +33.53.59.2       -23.8638      -81.1510       -2.5851 -1601192.467800 -5042022.856800 3554810.438800
+
   18   ea19 W05       25.0 m  -107.37.13.0 +33.53.57.8      -210.1007    -122.3814       -2.2582 -1601377.012800 -5041988.659800 3554776.399200
   19   ea22 N04       25.0 m  -107.37.06.5 +33.54.06.1       -42.5986      132.8623       -3.5431 -1601173.953700 -5041902.660400 3554987.536500
+
   19   ea20 N02       25.0 m  -107.37.06.2 +33.54.03.5       -35.6257      53.1906       -3.1311 -1601180.861780 -5041947.450400 3554921.638900
   20   ea23 E07       25.0 m  -107.36.52.4 +33.53.56.5        318.0523    -164.1848       -2.6960 -1600880.570000 -5042170.388000 3554741.457400
+
   20   ea21 N01       25.0 m  -107.37.06.0 +33.54.01.8       -30.8742      -1.4746       -2.8653 -1601185.628465 -5041978.158516 3554876.414800
   21   ea24 W05       25.0 m  -107.37.13.0 +33.53.57.8      -210.0944     -122.3885       -2.2581 -1601377.008000 -5041988.665500 3554776.393400
+
   21   ea22 W03       25.0 m  -107.37.08.9 +33.54.00.1      -105.3218      -51.7280       -2.6013 -1601265.134100 -5041982.547450 3554834.851200
   22   ea25 N02       25.0 m  -107.37.06.2 +33.54.03.5        -35.6245      53.1806       -3.1345 -1601180.861480 -5041947.453400 3554921.628700
+
   22   ea23 E06       25.0 m  -107.36.55.6 +33.53.57.7        236.9085     -126.3395       -2.4685 -1600951.579800 -5042125.894100 3554772.996600
   23   ea26 W03       25.0 m  -107.37.08.9 +33.54.00.1      -105.3429     -51.7191       -2.6054 -1601265.151700 -5041982.533050 3554834.856300
+
   23   ea24 W08       25.0 m  -107.37.21.6 +33.53.53.0      -432.1080    -272.1502       -1.5080 -1601614.082500 -5042001.654800 3554652.505900
   24   ea27 E03      25.0 m  -107.37.02.8  +33.54.00.5        50.6647     -39.4832       -2.7249 -1601114.365500 -5042023.153700 3554844.945600
+
   24   ea25 N08       25.0 m  -107.37.07.5 +33.54.15.8        -68.9105     433.1823       -5.0689 -1601147.943900 -5041733.832200 3555235.945600
   25   ea28  N08       25.0 m  -107.37.07.5 +33.54.15.8       -68.9057     433.1889       -5.0602 -1601147.940400 -5041733.837000 3555235.956000
+
   25   ea26 E03      25.0 m  -107.37.02.8  +33.54.00.5        50.6698     -39.4668       -2.7317 -1601114.356200 -5042023.141200 3554844.955400
##### End Task: listobs              #####
+
   26   ea28  W01       25.0 m  -107.37.05.9 +33.54.00.5       -27.3603     -41.2944       -2.7520 -1601189.030040 -5042000.479400  3554843.427200
##########################################
+
</pre>
 +
 
 +
Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; 0 through 26 in this instance) do not correspond to the actual antenna names (ea01 through ea28; these numbers correspond to those painted on the side of the antennas). The antennas can be referenced using either convention; ''antenna='22' '' would correspond to ea23, whereas ''antenna='ea22' '' would correspond to ea22Note that the antenna numbers in the observer log correspond to the actual antenna names, i.e., the 'ea??' numbers given in {{listobs}}.
 +
 
 +
Both to get a sense of the array, as well as identify the location of the antenna that was picked by the pipeline for parallel hand calibration, have a look at the [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t2-1.html?sidebar=sidebar_TDRW0001_sb35624494_eb35628826_58395_23719237269_ms&subpage=t2-2-3.html antenna setup page]. Generally, for calibration purposes, you would prefer to select an antenna that is close to the center of the array (and that is not listed in the operator's log as having had problems!). As noted above, in a compact configuration there is a benefit to choose an outer antenna to increase the bias toward longer baselines.
 +
 
 +
At this point it is also a good idea to check the quality of the pipeline calibration. Go to the [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t1-4.html task overview page] and pay particular attention to [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t2-4m.html?sidebar=sidebar_stage14&ms=all&subpage=t2-4m_details.html hifv_finalcals] and [https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/t2-4m.html?sidebar=sidebar_stage18&ms=all&subpage=t2-4m_details.html hifv_plotsummary]. Try to see if you can recognize which reference antenna was picked. For more details on the pipeline output you can have a look at the [http://casaguides.nrao.edu/index.php/VLA_CASA_Pipeline VLA CASA Pipeline Guide]. Going forward we assume that the pipeline calibration is good and we can use it as a starting point for further calibration steps focusing on polarization calibration and imaging.
 +
 
 +
== Examining and Editing the Data ==
  
</pre>
+
At this point we must start CASA.  If you have not used CASA before, some helpful tips are available on the [[Getting Started in CASA]] page.
  
Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; 0 through 25 in this instance) do not correspond to the actual antenna names (ea01 through ea28; these numbers correspond to those painted on the side of the dishes). The antennas can be referenced using either convention; ''antenna='22' '' would correspond to ea25, whereas ''antenna='ea22' '' would correspond to ea22. Note that the antenna numbers in the observer log correspond to the actual antenna names, i.e., the 'ea??' numbers given in listobs.
+
It is always a good idea to examine the data before jumping straight into calibration. From the observer's log there were no major issues noted, besides a potentially warm receiver on antenna ea05. Even though the pipeline did a good job of calibrating and flagging the data, it isn't perfect. From the pipeline weblog, looking at the final amplitude gain calibration vs time plots in hifv_finalcals, we can see that during the second half of the observation antennas ea03, ea12, and ea16 shows some gain instability; otherwise there are no issues identified at this point.  
  
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task {{plotants}} (see Figure 1).  In general, for calibration purposes, one would like to select an antenna that is close to the center of the array (and that is not listed in the operator's log as having had problems!).   
+
Start by inspecting these three particular antennas using the CASA task {{plotms}}, plot frequency against amplitude and frequency against time for the parallel hands, iterate over field or scan, and note if you find something at odds.   
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')
+
plotms(vis='TDRW0001_calibrated.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')
clearstat() # This removes the table lock generated by plotants in script mode
 
 
</source>
 
</source>
 +
[[Image:Colorbyfield_CASA5.4.1.jpeg|200px|right|thumb|Figure 1: Overview of the observation: amplitude vs time, color-coded by field.]]
 +
* ''selectdata=True '': One can choose to plot only selected subsets of the data.
 +
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.
 +
* ''averagedata=True'': One can choose to average data points before plotting them.
 +
* ''avgchannel='64' '': With this plot, we are mainly interested in the fields vs time. Averaging over all 64 channels in the spectral window makes the plotting faster.
 +
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.
 +
The default x- and y-axis parameters are 'time' and 'amp', so the above call to {{plotms}} produces an amplitude vs time plot of the data for a selected subset of the data (if desired) and with data averaging (if desired). Many other values have also been left to defaults, but it is possible to select them from within the plotms GUI. 
 +
 +
Task {{plotms}} allows one to select and view the data in many ways. Figure 1 shows the result of running plotms with the field selection discussed above. You can quickly see that the first source observed, 3C48 (the primary flux density and polarization angle calibrator source), is the brightest source in this observation. The next brightest is the second source observed, J2355+4950, a CSO and the secondary instrumental polarization calibrator. The complex gain calibrator J0259+0747 (shown in orange) is around 1 Jy. The target scans on 3C75 are colored in green. The spread of amplitudes is primarily due to the presence of extended structure, thus every baseline sees a slightly different amplitude.
 +
 +
Across the top of the left panel of the GUI are a set of tabs labelled Plot, Flag, Tools, Annotate, and Options. By default, the Plot tab is visible. There are a number of tabs running down the side of the left hand panel: Data, Calibration, Axes, Page, Transform, Display, and Canvas; these allow you to make changes to the plotting selection without having to re-launch {{plotms}}. Even if it was started with ''xaxis=' ' '' (defaulting to 'time'), you can choose a different X-axis by selecting the Axes tab, then using the dropdown menu to switch (for example) to ''xaxis='Frequency' '' (to get something sensible when plotting with frequency, channel averaging must be turned off).
 +
 +
You should spend several minutes displaying the data in various formats. You can save the version of the {{plotms}} plot as a graphics file by using the menu bar in the {{plotms}} GUI to select the ''Export...'' option under the Export menu.
 +
 +
Another example of using {{plotms}} for a quick look at your data, select the Data tab and specify ''field 2'' (the complex gain calibrator J0259+0747) to display data associated with the target, then select the Axes tab and change the X-axis to be ''UVdist'' (baseline length in meters). Remove the channel averaging (Data tab), and plot the data using the ''Plot'' button at the bottom of the {{plotms}} GUI. The important observation is that the amplitude distribution is relatively constant as a function of UV distance or baseline length (i.e., <math>\sqrt{u^2+v^2}</math> ) (see Figure 2A). A relatively constant visibility amplitude as a function of baseline length means that the source is very nearly a point source. (The Fourier transform of a point source, i.e. a delta function, is a constant function.) You can see occasional spikes in the calibrated amplitudes. This is most likely caused by radio frequency interference that correlates on certain baselines. We will get to those further in the guide.
  
 +
By contrast, if you make a similar plot for ''field 3'' (our target 3C 75), the result is a visibility function that falls rapidly with increasing baseline length. Figure 2B shows this example, including time averaging of '1e6' seconds (any large number that encompasses more than a full scan will do). Such a visibility function indicates a highly resolved source. The baseline length at which the visibility function falls to some fiducial value (e.g., 1/2 of its peak value) gives a rough estimate of the angular scale of the source (Angular scale [in radians] ~ 1/baseline [in wavelengths]). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter.
  
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]
+
A final example is shown in Figure 2C. In this example, we have elected to show phase as a function of (frequency) channel for a single baseline (''antenna='ea01&ea21' '') on the bandpass calibrator, field 0. If you choose to iterate by baseline (e.g., ''antenna='ea01' '' and ''iteraxis='baseline' ''), you can see similar phase-frequency variations on all baselines. They center around zero phase, since we are looking at the calibrated visibilities, you are seeing, however, a butterfly shaped pattern with phase noise higher toward the channel edges. This pattern is due to a small mismatch in the delay measurement timing (also known as 'delay clunking') which is an internally generated effect and is typically averaged out over time. 
 +
{|
 +
| [[File:plotms-J0259+0747-Amp vs UVdist 5.4.1.jpeg|200px|left|thumb|Figure 2A: plotms view of amp vs. uvdist of J0259+0747, a point source]]
 +
| [[File:Plotms-3C75-Amp vs UVwave 5.4.1.jpeg|200px|center|thumb|Figure 2B: plotms view of amp vs. uvwave of 3C 75, a resolved source]]
 +
| [[File:Delays_ea01ea21_CASA5.4.1.jpeg|200px|right|thumb|Figure 2C: plotms view of phase vs. channel on one baselines, showing phase delay across the calibrated bandpass]]
 +
|}
  
== Examining and Editing the Data ==
+
You can find similar plots in the CASA pipeline weblog under the task hifv_plotsummary. At this stage the pipeline has taken care of most of the calibration; there might be some remaining issues, though, that were not caught by the pipeline.
  
It is always a good idea to examine the data before jumping  straight into calibration. Moreover, from the observer's log, we already know that one antenna will need to be flagged because it does not have a C-band receiver.  Start by flagging data known to be bad, then examine the data.
+
[[Image:plotms_3C75-datastream_CASA5.4.1.jpeg|200px|right|thumb|Figure 3: datastream view of MS]]
 +
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01. This shows, assuming that ea01 is in the entire observation, when various antennas drop out (see Figure 3).
  
In the scheduling block configuration, it is common to insert a setup scan as the first scan.  From the {{listobs}} output above, one may have noticed that the first scan is less than 1 minute long.  This first scan can safely be flagged.
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')
+
plotms(vis='TDRW0001_calibrated.ms',field='',correlation='RR,LL',
 +
      timerange='',antenna='ea01',spw='0:31',
 +
      xaxis='time',yaxis='antenna2',
 +
      plotrange=[-1,-1,0,26],coloraxis='field')
 
</source>
 
</source>
  
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup.  If set to True, {{flagdata}} will save a copy of the existing set of flags ''before'' entering any new flags.  The setting of flagbackup is therefore a matter of some taste.  You could choose not to save any flags or only save major flags, or you could save every flag.  ''flagbackup=True'' is the default.
+
From this display you can immediately that flagging performed by the pipeline is present. In the following we note on a couple issues that you might have found and will take care of those through additional flagging.
* ''mode='manual' '': Specific data are going to be selected to be edited. 
 
<!--* <tt>selectdata=True</tt> : In order to select the specific data to be flagged, selectdata has to be set to True.  Once selectdata is set to True, then the various data selection options become visible (use ''help flagdata'' to see the possible options). In this case, -->
 
* ''scan='1' '': is chosen to select only the first scan.  Note that scan expects an entry in the form of a string (scan=1 would generate an error).
 
 
 
If satisfied with the inputs, run this task. The initial display in the logger will include
 
  
 
<pre style="background-color: #fffacd;">
 
<pre style="background-color: #fffacd;">
##########################################
+
Issues that you might find:
##### Begin Task: flagdata          #####
+
- ea12, scan 17: amplitude spike at the end of the scan.
.
+
- Residual RFI
.
 
.
 
.
 
Backup original flags before applying new flags
 
Table type is Measurement Set
 
Creating new backup flag file called flagdata_1
 
Table type is Measurement Set
 
Manual mode is active
 
Initializing the agents
 
autocorr is 0
 
There are 1 valid agents in list
 
Running the agentflagger tool
 
------------------------------------------------------------------------------------
 
Chunk = 1 [progress: 100%], Observation = 0, Array = 0, Scan = 1, Field = 0 (J1331+3030), Spw = 0, Channels = 64, Corrs = [ RR RL LR LL ], Total Rows = 650
 
=> Data flagged so far 100%
 
====================================================================================
 
=> Percentage of data flagged in table selection: 100%
 
=> Writing flags to the MS
 
.
 
.
 
##### End Task: flagdata            #####
 
##########################################
 
 
</pre>
 
</pre>
  
which indicates that, among other things, the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''.  Should you ever desire to revert to the data prior to this run, the task {{flagmanager}} could be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.
+
We can flag this time period, by invoking the casa task {{flagdata}}. It is also a good idea to save the original flags before performing any flagging by setting '''flagbackup=True'''.  
  
From the observer's log, we know that antenna ea13 does not have a C-band receiver and antenna ea15 had some corrupted data, so they should be flagged as well.  The parameters are similar as before.
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')
+
flagdata(vis='TDRW0001_calibrated.ms', flagbackup=True, mode='manual', antenna='ea12',scan='17',timerange='07:25:57~07:26:18')
 
</source>
 
</source>
* ''antenna='ea13,ea15' '': Once again, this parameter requires a string input.  Remember that ''antenna='ea13' ''and'' 'antenna='13' ''are '''not''' the same antenna.  (See the discussion after our call to {{listobs}} above.)
 
  
Finally, it is common for the array to require a small amount of time to settle down at the start of a scan. Consequently, it has become standard practice to flag the initial samples from the start of each scan. This is known as 'quack' flagging.
+
You can check the effect of this flagging by replotting Figure 2A. The spikes we saw before on some baselines should have disappeared. If you plot frequency against amplitude without averaging, however, you will still see some channels with interference that we will need to flag, especially on the instrumental polarization calibrators. Polarization calibration is very sensitive to interference, especially in the cross-hand correlations RL,LR. The pipeline does not (yet) do a good job at this, therefore we will need to cover some additional flagging steps in the next section.  
 +
 
 +
=== Additional Flagging ===
 +
 
 +
At first, we try to get a good sense of additional flagging that might be needed by plotting frequency against amplitude for the RR,LL and RL,LR polarizations of our calibrators, fields 0 through 2. In particular we need to pay attention to RL,LR (see Figure 4A). We will perform additional flagging on the target field at a later stage.  
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')
+
# for parallel hands
</source>
+
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RR,LL')
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.
+
# for cross-hands
* ''quackmode='beg' '': In this case, data from the start of each scan will be flagged. Other options include flagging data at the end of the scan.
+
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RL,LR')
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, so this choice flags the first sample from all scans on all baselines.
+
</source>
 +
 
 +
{|
 +
| [[File:Plotms-preflag-Amp vs Freq 5.4.1.jpeg|200px|left|thumb|Figure 4a: plotms view of calibrators freq vs. amp RL/LR before additional flagging]]
 +
| [[File:Plotms-rflag-Amp vs Freq 5.4.1.jpeg|200px|right|thumb|Figure 4b: plotms view of calibrators freq vs. amp RL/LR after rflag]]
 +
|}
  
Having now done some basic editing of the data, based in part on ''a priori'' information, it is time to look at the data to determine if there are any other obvious problems. One task to examine the data themselves is {{plotms}}.
+
Since we are dealing with point sources, we do not have to worry about overflagging of shorter baselines, so we can run {{flagdata}} with ''mode='rflag' ''over the calibrator fields and cross-hand correlations to remove any residual RFI. For completeness, we also use ''mode='tfcrop' ''to reduce the amount of residual RFI in the parallel hands. This is not strictly needed at this point, since the polarization calibration is based on the cross-hand correlations.
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
clearstat() # This removes any existing table locks generated by flagdata
 
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')
 
</source>
 
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]
 
* ''selectdata=True '': One can choose to plot only selected subsets of the data.
 
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.
 
* ''averagedata=True'': One can choose to average data points before plotting them.
 
* ''avgchannel='64' '': With this plot, we are mainly interested in the fields vs time. Averaging over all 64 channels in the spectral window makes the plotting faster.
 
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.
 
The default x- and y-axis parameters are 'time' and 'amp', so the above call to plotms produces an amplitude vs time plot of the data for a selected subset of the data (if desired) and with data averaging (if desired). Many other values have also been left to defaults, but it is possible to select them from within the plotms GUI. 
 
  
Task {{plotms}} allows one to select and view the data in many ways. Figure 2 shows the result of running plotms with the field selection discussed above. You can quickly see that the last source observed (J0319+4130, the polarization calibrator source) is the brightest source in this observation.  The next brightest is the first source observed (J1331+3030, a.k.a. 3C286), which was also observed about a third of the way through the scheduling block. The complex gain calibrator (J1822-0938, shown in magenta) is slightly brighter than the target fields. Even though each of the target scans is on the same source (3C391), the observation is done as a mosaic of 7 fields (see the {{listobs}} output above). Each of the 7 3C391 fields is given its own field number/name identification, so each is shown as its own color. The spread of amplitudes in each field is partly due to the difference in gain on each antenna and baseline. Data calibration will take care of much of that scatter.
+
# for the parallel hands
 +
flagdata(vis='TDRW0001_calibrated.ms',
 +
mode='tfcrop',
 +
field='0~2',
 +
correlation='',
 +
freqfit='line',
 +
extendflags=False,
 +
flagbackup=False)
  
Across the top of the left panel are a set of tabs labeled Plot, Flag, Tools, Annotate, and Options. In the default view, the Plot tab is visible, and there are a number of tabs running down the side of the left hand panel, including Data, Calibration, Axes, Page, Transform, Display, and Canvas.  These allow you to make changes to the plotting selection without having to re-launch plotms. Even if was started with ''xaxis=' ' '' (defaulting to 'time'), you can choose a different X-axis by selecting the Axes tab, then using the dropdown menu to switch to (for example) ''xaxis='Frequency' '' (although to get something sensible when plotting with frequency, channel averaging must be turned off).
+
# for the cross-hands
 +
flagdata(vis='TDRW0001_calibrated.ms',
 +
mode='rflag',
 +
datacolumn='data',
 +
field='0~2',
 +
correlation='RL,LR',
 +
extendflags=True,
 +
flagbackup=False)
 +
</source>
  
You should spend several minutes displaying the data in various formats. You can save the version of the plotms plot as a graphics file by using the menu bar in the plotms GUI to select the ''Export...'' option under the Export menu.
+
As you can see in Figure 4B, this additional flagging step took care of most of the obvious residual RFI. We are now ready to move on to calibrate the visibilities for linear polarization.
  
As another example of using {{plotms}} for a quick look at your data, select the Data tab and specify ''field 0'' (source J1331+3030, a.k.a. 3C 286) to display data associated with the amplitude calibrator, then select the Axes tab and change the X-axis to be ''UVdist'' (baseline length in meters). Remove the channel averaging (Data tab), and plot the data using the ''Plot'' button at the bottom of the plotms GUI.  The result should be similar to Figure 3A.  Again, the scatter is normal at this pre-calibration stage. The important observation is that the amplitude distribution is relatively constant as a function of UV distance or baseline length (i.e., <math>\sqrt{u^2+v^2}</math> ).  A relatively constant visibility amplitude as a function of baseline length means that the source is very nearly a point source.  (The Fourier transform of a point source, i.e. a delta function, is a constant function.)
+
== Polarization Calibration ==
  
By contrast, if you make a similar plot for ''field 8'' (one of the 3C 391 fields), the result is a visibility function that falls rapidly with increasing baseline length. Figure 3B shows this example, including time averaging of '1e6' seconds (any large number that encompasses more than a full scan will do).  Such a visibility function indicates a highly resolved source.  The baseline length at which the visibility function falls to some fiducial value (e.g., 1/2 of its peak value) gives a rough estimate of the angular scale of the source(Angular scale [in radians] ~ 1/baseline [in wavelengths]. To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter.)
+
Polarization calibration is done in three steps:
 +
* First, we determine the instrumental delay between the two polarization outputs;
 +
* Second, we solve for the instrumental polarization (the frequency-dependent leakage terms ('D-terms')), using either an unpolarized source or a source which has sufficiently good parallactic angle coverage;
 +
* Third, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C48 here).  
  
A final example is shown in Figure 3C. In this example, we have elected to show phase as a function of (frequency) channel for a single baseline (''antenna='ea01&ea21' '') on the bandpass calibrator. If you choose to iterate by baseline (e.g., ''antenna='ea01' '' and ''iteraxis='baseline' ''), you can see similar phase-frequency variations on all baselines, but with different slopes. These linear variations are 'delays' that need to be calibrated for, below.  We have chosen to colorize by scan; it's clear that the slopes are steady over time. The two different lines for each baseline correspond to the 'RR' and 'LL' polarizations.
+
For information on polarization calibrators suitable for VLA observations, see the [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/pol VLA Observing Guide on Polarimetry]. The [https://casa.nrao.edu/casadocs/casa-5.4.1/synthesis-calibration/instrumental-polarization-calibration CASA related documentation] also provides helpful information on polarization calibration steps and the different options that are available.  
  
{|
+
Before solving for the calibration solutions, we first use {{setjy}} to set the polarization model for our polarized position-angle calibrator. The pipeline only set the total intensity of the flux density calibrator source 3C48, which did not include any polarization information. This source is known to have a fairly stable linear fractional polarization (measured to be 2% in S-band around the time of the observations), a polarization position angle of -100 degrees at 3 GHz, and a rotation measure of -68 rad/m^2. Note at higher frequencies, 3C48 has had an outburst in 2017 and thus is expected to show a significant degree of variability. Since we have applied the pipeline calibration and not corrected for parallactic angle, we can continue polarization calibration using a split measurement set.  
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|200px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286, a point source]]
 
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|200px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391, a resolved source]]
 
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baselines, showing phase delay across the uncalibrated bandpass]]
 
|}
 
  
At this stage in the data reduction process, the general data editing and examination strategy is to focus on the calibrators. The reduction strategy is to determine various corrections from the calibrators, then apply these correction factors to the science data.  The 3C 286 data look relatively clean in that there are no wildly egregious data (e.g., amplitudes that are 100,000x larger than the rest of the data). You may notice that there are antenna-to-antenna variations (under the Display tab select Colorize by Antenna1). These antenna-to-antenna variations are acceptable, this variation is taken care of by the calibration process.
+
The [https://casa.nrao.edu/casadocs/latest/global-task-list/task_setjy/about setjy] task will calculate the values of Stokes Q and U (in the reference channel) for user inputs of the reference frequency, Stokes I, polarization fraction, polarization angle, and rotation measure. The setjy input parameters can be obtained from Perley & Butler (2017) for Stokes I information and Perley & Butler (2013) for polarization information. Other sources can also be consulted, such as archival observations of variable polarization calibrators available under the project code TPOL0003 or TCAL0009. It is possible to capture a frequency variation in Q, U, and alpha terms by providing coefficients of polynomial expansion for polarization fraction, polarization angle, and spectral index as a function of frequency. At this time, it is left to the user to derive these coefficients, which can be accomplished by fitting a polynomial to observed values of the polarization fraction (here also called polarization index), polarization angle, and flux density (for the case of spectral index). Updated values of the broad band polarimetric information for the four calibration sources 3C48, 3C138, 3C147, and 3C286 (Of these sources, 3C48, 3C138, and 3C147 have been noticed to be variable) can be found at (https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/fdscale) and at (https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/pol). These coefficients are then passed to the setjy task as lists along with the reference frequency and the Stokes I flux density.
  
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]
+
The calibrator used for this guide, 3C48, has a rotation measure and thus changes its Q and U with frequency. Therefore, for our purposes, it is not sufficient to use only the first Taylor term of the expansion. For deriving the setjy input parameters you can consult the [https://casa.nrao.edu/casadocs/latest/global-task-list/task_setjy/about setjy CASA documentation]. Currently setjy only supports unresolved polarized emission models assuming that the Stokes I,Q,U peak are co-located on the sky. This is not necessarily the case for more complicated objects or even for 3C48 in extended VLA configurations.
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.
 
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',
 
      timerange='',antenna='ea01',spw='0:31',
 
      xaxis='time',yaxis='antenna2',
 
      plotrange=[-1,-1,0,26],coloraxis='field')
 
</source>
 
  
From this display (see Figure 4), you see immediately that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken affect. For the remaining antennas, you see that 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and also toward the end of the run. Antenna 3 (ea04) is missing the last scan (on the polarization calibrator, 3C84) and antenna 23 (ea26) is missing scans near the end. None of these antennas should be chosen as the reference antenna during the calibration process, below.
+
# Reference Frequency for fit values
 +
reffreq = '3.0GHz'
 +
# Stokes I flux density
 +
I =        8.45650174
 +
# Spectral Index
 +
alpha =    [-0.90366565, -0.14262821]
 +
# Polarization Fraction
 +
polfrac = [0.021429,0.0391826,0.00234878,-0.0230125]
 +
# Polarization Angle
 +
polangle = [1.4215,1.36672,-2.12678,3.48384,-2.71914]
  
== Calibrating the Data ==
+
setjy(vis='TDRW0001_calibrated.ms',
 +
      field='0137+331=3C48',
 +
      spw='',
 +
      selectdata=False,
 +
      timerange="",
 +
      scan="",
 +
      intent="",
 +
      observation="",
 +
      scalebychan=True,
 +
      standard="manual",
 +
      model="",
 +
      modimage="",
 +
      listmodels=False,
 +
      fluxdensity=[I,0,0,0],
 +
      spix=alpha,
 +
      reffreq=reffreq,
 +
      polindex=polfrac,
 +
      polangle=polangle,
 +
      rotmeas=0,
 +
      fluxdict={},
 +
      useephemdir=False,
 +
      interpolation="nearest",
 +
      usescratch=True,
 +
      ismms=False,
 +
)
 +
</source>
 +
* ''field='0137+331=3C48' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.
 +
* ''standard='manual' '': the user will supply the flux density, spectral index, and polarization parameters rather than giving a model (the CASA models currently do not include polarization).
 +
* ''fluxdensity=[I,0,0,0] '': you may provide values of Q and U rather than having setjy calculate them.However, if you set Q and U as input using the ''fluxdensity'' parameter, then the first value given in polindex or polangle will be ignored.
 +
* ''spix=[-0.90366565, -0.14262821] '': set the spectral index using the value above. This will apply to all non-zero Spokes parameters. In this example, we only use the first two coefficients of the Taylor expansion.
 +
* ''reffreq='3.0GHz' '': The reference frequency for the input Stokes values.
 +
* ''polindex=[0.021429,0.0391826,0.00234878,-0.0230125 '': The coefficients of polynomial expansion for the polarization index as a function of frequency.
 +
* ''polangle=[1.4215,1.36672,-2.12678,3.48384,-2.71914] '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.
 +
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.
 +
* ''usescratch=True'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space by not filling the model column)
 +
The Stokes V flux has been set to zero, corresponding to no circular polarization.
  
It is now time to begin calibrating the dataThe general data reduction strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data.   
+
{{Setjy}} returns a Python dictionary (CASA record) that reports the Stokes I, Q, U and V terms. This is reported to the CASA command line window:
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casa.nrao.edu/casadocs/latest/synthesis-calibration/ Synthesis Calibration] in the CASA documentation.
+
<pre>
 +
{'0': {'0': {'fluxd': array([ 9.99287353, -0.08937082,  0.11939692,  0.        ])},
 +
  '1': {'fluxd': array([ 9.55959057, -0.11709484,  0.10568676,  0.        ])},
 +
  '2': {'fluxd': array([ 9.16182831, -0.13997047,  0.08921149, 0.        ])},
 +
  '3': {'fluxd': array([ 8.7953302 , -0.15846661,  0.07143732,  0.        ])},
 +
  '4': {'fluxd': array([ 8.45650174, -0.1731959 , 0.05330882, 0.        ])},
 +
  '5': {'fluxd': array([ 8.14228548, -0.1847571 , 0.03537654, 0.        ])},
 +
  '6': {'fluxd': array([ 7.85006343, -0.193661  ,  0.01792025,  0.        ])},
 +
  '7': {'fluxd': array([  7.57758019e+00,  -2.00307499e-01,  1.05166484e-03,
 +
            0.00000000e+00])},
 +
  'fieldName': '0137+331=3C48'},
 +
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}
 +
</pre>
 +
Alternatively, you may capture this dictionary in a return variable, if you call {{setjy}} as '''myset=setjy(...)'''.
  
Recall that the observed visibility <math>V^{\prime}</math> between two antennas <math>(i,j)</math> is related to the true visibility <math>V</math> by:
+
We can see the results in the model column in {{plotms}} (Figure 5A) showing the model source spectrum:
 +
<source lang="python">
 +
# In CASA
 +
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RR',
 +
      timerange='',antenna='ea01&ea02',
 +
      xaxis='frequency',yaxis='amp',ydatacolumn='model')
  
<math>
+
</source>
V^{\prime}_{i,j}(u,v,f) = b_{ij}(t)\,[B_i(f,t) B^{*}_j(f,t)]\,g_i(t) g_j(t)\,V_{i,j}(u,v,f)\,e^{i [\theta_i(t) - \theta_j(t)]}
+
We can see this translates to the spectrum in QU (Figure 5B):
</math>
+
<source lang="python">
 
+
# In CASA
Here, for generality, we show the visibility as a function of frequency <math>f</math> and spatial wave numbers <math>u</math> and <math>v</math>.  The other terms are:  
+
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',
* <math>g_i</math> and <math>\theta_i</math> are the amplitude and phase portions of what is commonly termed the complex gain.  They are shown separately here because they are usually determined separately.  For completeness, these are shown as a function of time <math>t</math> to indicate that they can change with temperature, atmospheric conditions, etc.
+
      timerange='',antenna='ea01&ea02',
* <math>B_i</math> is the complex bandpass, the instrumental response as a function of frequency <math>f</math>.  As shown here, the bandpass may also vary as a function of time.
+
      xaxis='frequency',yaxis='amp',ydatacolumn='model')
* <math>b(t)</math> is the often-neglected baseline term. It can be important to include for the highest dynamic range images or shortly after a configuration change at the VLA, when antenna positions may not be known well. 
+
</source>
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.
 
 
 
=== ''A priori'' Antenna Position Corrections ===
 
 
 
As mentioned in the observing log above, antennas ea10, ea12, and ea22 do not have good baseline positions. Antenna ea10 was not in the array, but, for the other two antennas, any improved baseline positions need to be incorporated.  The importance of this step is that the visibility function is a function of <math>u</math> and <math>v</math>.  If the baseline positions are incorrect, then <math>u</math> and <math>v</math> will be calculated incorrectly and there will be errors in the image.  These corrections could also be determined later by a baseline-based calibration incorporating the <math>b_{ij}</math> term from the equation above, but since they are known ''a priori'' it makes sense to incorporate them now.
 
 
 
NRAO monitors the positions of the VLA antennas on a regular basis.  The corrections are then placed into an NRAO database.  If updated positions were entered into the database AFTER your observation date, the corrections to the newly measured positions can still be applied during your data reduction process in this step.  Any updated positions that were entered into the database BEFORE your observations will already be accounted for in your data.
 
 
 
The calculations are inserted via {{gencal}} which allows automated lookup of the corrections.  To see how to calculate corrections manually, go to the [http://www.vla.nrao.edu/astro/archive/baselines/ VLA Baseline Corrections] site.
 
  
 +
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization
 +
angle) as desired (Figure 5C):
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')
+
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',
 +
      timerange='',antenna='ea01&ea02',
 +
      xaxis='frequency',yaxis='phase',ydatacolumn='model')
 
</source>
 
</source>
  
In the logger you can see the corrections reported:
+
{|
 +
| [[Image:plotms_3C48-model-amp-RR_CASA5.4.1.png|200px|thumb|left|Figure 5A: model RR amplitudes]]
 +
| [[Image:plotms_3C48-model-amp-RL_CASA5.4.1.png|200px|thumb|center|Figure 5B: model RL amplitudes]]
 +
| [[Image:plotms_3C48-model-phase-RL_CASA5.4.1.png|200px|thumb|right|Figure 5C: model RL phases]]
 +
|}
 +
 
 +
In order to obtain the correct amplitude scaling for instrumental polarization calibration, we need to also specify the Stokes I model that was used for the D-term calibrator(s). If we carried all tables, instead of splitting out the calibrated data from the pipeline, we wouldn't need to do this since the gain amplitudes provide the correct Stokes I scale for all the calibrators. The model values of the two D-term calibrators can be obtained from the pipeline weblog under the task hifv_fluxboot2 inside the CASA log.
 +
 
 
<pre style="background-color: #fffacd;">
 
<pre style="background-color: #fffacd;">
##########################################
+
Fitted spectrum for J2355+4950 with fitorder=2: Flux density = 1.76852 +/- 0.000723163 (freq=2.98457 GHz) spidx=-0.603023 +/- 0.00307991 curv=-0.20303 +/- 0.0750626
##### Begin Task: gencal            #####
+
Fitted spectrum for J0259+0747 with fitorder=2: Flux density = 0.970631 +/- 0.000745372 (freq=2.98457 GHz) spidx=0.172459 +/- 0.00531882 curv=-0.191716 +/- 0.140254
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",
 
        antenna="",pol="",parameter=[])
 
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.
 
Initializing nominal selection to the whole MS.
 
Determine antenna position offests from the baseline correction database
 
offsets for antenna ea01 :  0.00000  0.00300  0.00000
 
offsets for antenna ea02 : -0.00080  0.00000  0.00000
 
offsets for antenna ea03 : -0.00280  0.00000  0.00000
 
offsets for antenna ea05 :  0.00000  0.00280  0.00000
 
offsets for antenna ea11 :  0.00090  0.00000  0.00000
 
offsets for antenna ea12 : -0.01000  0.00450  -0.00170
 
offsets for antenna ea13 :  0.00000  -0.00080  0.00000
 
offsets for antenna ea17 : -0.00120  0.00000  0.00000
 
offsets for antenna ea18 :  0.00040  -0.00080  0.00040
 
offsets for antenna ea22 : -0.02570  0.00270  -0.01900
 
offsets for antenna ea23 : -0.00140  0.00000  0.00000
 
offsets for antenna ea24 : -0.00150  0.00000  0.00000
 
offsets for antenna ea26 : -0.00190  0.00000  0.00210
 
offsets for antenna ea27 :  0.00000  0.00190  -0.00160
 
Beginning specifycal-----------------------
 
Creating KAntPos Jones table from specified parameters.
 
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos
 
##### End Task: gencal              #####
 
##########################################
 
 
</pre>
 
</pre>
  
This particular set of observations was taken 24 April 2010, so the corrections shown above are for antennas that were moved BEFORE that date, but whose updated positions were not placed into the online database until later. Most likely, the antenna positions were re-measured after 24 April. You can verify this by looking at the [http://www.vla.nrao.edu/astro/archive/baselines/ online database] for the first part of 2010:
+
This translates to the following {{setjy}} calls.
  
<pre style="background-color: #E0FFFF;">
+
<source lang="python">
;                2010 BASELINE CORRECTIONS IN METERS
+
setjy(vis='TDRW0001_calibrated.ms',
;ANT
+
      field='J2355+4950',
;MOVED OBSDATE  Put_In_ MC(IAT)  ANT  PAD    Bx      By      Bz
+
      spw='',
;
+
      selectdata=False,
JAN27  FEB12    FEB21  01:57    11  E04  0.0000  0.0000  0.0000
+
      timerange="",
JAN27  FEB12    FEB21  01:57    26  W03 -0.0170  0.0204  0.0041
+
      scan="",
MAR24  MAR25    MAR26  18:28    17  W07 -0.0061 -0.0069 -0.0055
+
      intent="",
APR21  MAY02    MAY04  23:25    12  E08 -0.0072  0.0045 -0.0017
+
      observation="",
MAR09  MAY02    MAY04  23:25    22  N04 -0.0220  0.0040 -0.0190
+
      scalebychan=True,
JUN08  JUN20    JUN22  03:00    10  N03  0.0046 -0.0196  0.0090
+
      standard="manual",
        JUL17    JUL18  21:44    1  W09  0.0000  0.0030  0.0000
+
      model="",
        JUL17    JUL18  21:44    2  E02 -0.0008  0.0000  0.0000
+
      modimage="",
        JUL17    JUL18  21:44    3  E09 -0.0028  0.0000  0.0000
+
      listmodels=False,
        JUL17    JUL18  21:44    5  W08  0.0000 0.0028  0.0000
+
      fluxdensity=[1.76852,0,0,0],
JUL01  JUL17    JUL18  21:44    6  N06  0.0022  0.0010  0.0059
+
      spix=[-0.603023,-0.20303],
        JUL17    JUL18  21:44    10  N03  0.0008  0.0030 -0.0014
+
      reffreq='2.98457GHz',
        JUL17    JUL18  21:44    11  E04  0.0009  0.0000  0.0000
+
      polindex=[],
        JUL17    JUL18  21:44    12  E08 -0.0028  0.0000  0.0000
+
      polangle=[],
        JUL17    JUL18  21:44    13  N07  0.0000 -0.0008  0.0000
+
      rotmeas=0,
        JUL17    JUL18  21:44    17  W07 -0.0012  0.0000  0.0000  
+
      fluxdict={},
        JUL17    JUL18  21:44    18  N09  0.0004 -0.0008  0.0004
+
      useephemdir=False,
        JUL17    JUL18  21:44    22  N04 -0.0037 -0.0013  0.0000
+
      interpolation="nearest",
        JUL17    JUL18  21:44    23  E07 -0.0014  0.0000  0.0000
+
      usescratch=True,
        JUL17    JUL18  21:44    24  W05 -0.0015  0.0000  0.0000
+
      ismms=False,
        JUL17    JUL18  21:44    26  W03 -0.0019  0.0000  0.0021
+
)
        JUL17    JUL18  21:44    27  E03  0.0000  0.0019 -0.0016
 
</pre>
 
  
=== Initial Flux Density Scaling ===
+
setjy(vis='TDRW0001_calibrated.ms',
 +
      field='J0259+0747',
 +
      spw=spw,
 +
      selectdata=False,
 +
      timerange="",
 +
      scan="",
 +
      intent="",
 +
      observation="",
 +
      scalebychan=True,
 +
      standard="manual",
 +
      model="",
 +
      modimage="",
 +
      listmodels=False,
 +
      fluxdensity=[0.970631,0,0,0],
 +
      spix=[0.172459,-0.191716],
 +
      reffreq='2.98457GHz',
 +
      polindex=[],
 +
      polangle=[],
 +
      rotmeas=0,
 +
      fluxdict={},
 +
      useephemdir=False,
 +
      interpolation="nearest",
 +
      usescratch=True,
 +
      ismms=False,
 +
)
 +
</source>
  
The next step is to provide a flux density value for the amplitude calibrator J1331+3030 (a.k.a. 3C 286).  Later, for the final step in determining the calibration solutions, we will use the calibrated gains of the different sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938) and to the polarization calibrator (J0319+4130). At this stage, we only set the flux density model and not the polarization model for 3C 286; otherwise the early calibration steps would use the low signal-to-noise in the uncalibrated Stokes Q and U to provide poor calibration solutions.
+
==== Solving for the Cross-Hand delays ====
  
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux scaling was then transferred to a small number of primary flux density calibrators, including 3C 286.  For the upgraded Karl G. Jansky VLA, the flux density scale at most frequencies is determined from WMAP observations of the planet Mars, which, in turn, was transferred to a small number of primary flux density calibrators. The procedure is to assume that the flux density of a primary calibrator source is known and, by comparison with the observed data for that calibrator, determine the <math>g_i</math> values (the antenna gains).
+
Just as the pipeline did for the parallel-hand (RR,LL) delays before bandpass calibration, we solve for the cross-hand (RL, LR) delays due to the residual delay difference between the R and L on the reference antenna (''ea10'') used for the original delay calibration. In our case we simply use 3C48, which has a moderately polarized signal in the RL, LR correlations, and we set its polarized model above using {{setjy}}. In this CASA version and going forward there are two options to solve for the cross-hand delays, both of them will be illustrated here. The first option fits the cross-hand delay for the entire baseband (8 spectral windows in this example form a single baseband), which we call multiband delay. The second option solves the cross-hand delay independently per spectral window. Note that if a dataset contains multiple basebands and you wanted to solve for multiband delays, {{gaincal}} has to be executed for each baseband separately, selecting the appropriate spectral windows and appending the results to a single calibration table for later use.
 
 
To start, let's find the available calibrator models with {{setjy}} and setting the parameter ''listmodels=True'':
 
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)
 
</source>
 
  
This command will show all available calibrator models:
+
# Solve using Multiband Delay
<pre style="background-color: #fffacd;">
+
kcross_mbd = "TDRW0001_calibrated.Kcross_mbd"
No candidate modimages matching '*.im* *.mod*' found in .
+
gaincal(vis='TDRW0001_calibrated.ms',
 +
    caltable=kcross_mbd,
 +
    field='0137+331=3C48',
 +
    spw='0~7:5~58',
 +
    refant='ea10',
 +
    gaintype="KCROSS",
 +
    solint="inf",
 +
    combine="scan,spw",
 +
    calmode="ap",
 +
    append=False,
 +
    gaintable=[''],
 +
    gainfield=[''],
 +
    interp=[''],
 +
    spwmap=[[]],
 +
    parang=True)
  
Candidate modimages (*) in /home/casa/packages/RHEL6/release/casa-release-4.4.0/data/nrao/VLA/CalModels:
+
# Solve using Single Band Delay
3C138_A.im  3C138_S.im  3C147_K.im  3C147_X.im  3C286_Q.im  3C48_C.im  3C48_U.im
+
kcross_sbd = "TDRW0001_calibrated.Kcross_sbd"
3C138_C.im  3C138_U.im  3C147_L.im  3C286_A.im  3C286_S.im  3C48_K.im  3C48_X.im
+
gaincal(vis='TDRW0001_calibrated.ms',
3C138_K.im  3C138_X.im  3C147_Q.im  3C286_C.im  3C286_U.im  3C48_L.im  README
+
    caltable=kcross_sbd,
3C138_L.im  3C147_A.im  3C147_S.im  3C286_K.im  3C286_X.im  3C48_Q.im
+
    field='0137+331=3C48',
3C138_Q.im  3C147_C.im  3C147_U.im  3C286_L.im  3C48_A.im  3C48_S.im
+
    spw='0~7:5~58',
</pre>
+
    refant='ea10',
Since any image could be a potential calibrator model, {{setjy}} will list all ''*.im'' and ''*.mod'' images in the working directory. In addition, it will list all models that are provided by NRAO with the CASA package, and they will be picked by their names. We will be using the C-band VLA standard model for 3C286 which is aptly named '3C286_C.im':
+
    gaintype="KCROSS",
 +
    solint="inf",
 +
    combine="scan",
 +
    calmode="ap",
 +
    append=False,
 +
    gaintable=[''],
 +
    gainfield=[''],
 +
    interp=[''],
 +
    spwmap=[[]],
 +
    parang=True)
 +
</source>
  
 +
[[Image:plotms_3c48-Kcross-delay_CASA5.4.1.png|200px|thumb|right|Figure 6: single band cross-hand delay solutions]]
 +
We can plot the single band solutions (see Figure 6):
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',
+
plotms(vis=kcross_sbd,xaxis='frequency',yaxis='delay',antenna='ea10',coloraxis='corr')
      model='3C286_C.im',usescratch=False,scalebychan=True,spw='')
 
 
</source>
 
</source>
 +
You can also look at the solutions reported in the logger.
 +
<pre style="background-color: #fffacd;">
 +
For multiband delay there is one solution:
 +
Time=2018/10/04/05:51:10.9 Multi-band cross-hand delay=3.72173 nsec
  
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]-->
 
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.
 
* ''standard='Perley-Butler 2017' '': The flux density scale at the VLA is periodically revised, updated, or expanded.  The specified value represents the most recent determination of the flux density scale by R. Perley and B. Butler in 2017, ApJS, 230, 7 (now the default); older scales can also be specified, and might be important if, for example, one was attempting to conduct a careful comparison with a previously published result.
 
* ''model='3C286_C.im' '': From plotms above, it was estimated that 3C 286 is roughly a point source. Depending upon the frequency and configuration, the source may be slightly resolved.  Fiducial model images have been determined from a painstaking set of observations, and, if one is available, it should be used to compensate for slight resolution effects (any deviation of the calibrator from a point source model).  In this case, spectral window 0 (at 4.536 GHz) is in the C-band, so we use the C-band model image.
 
* ''usescratch=False '': To save disk space, we will NOT force the writing of the model visibilities to the MODEL_DATA scratch column.  For ''usescratch=False'', CASA saves the model information, and calculates the individual model visibilities on-the-fly when needed for calibration and for plotms.
 
* ''scalebychan=True '': In order to take account for the intrinsic spectral index of our flux density calibrator 3C286 when we use it as our bandpass calibrator, we let setjy determine a flux density value per channel rather than one value for the entire spectral window.
 
* ''spw=' ' '': The original data contained two spectral windows.  Having split off spectral window 0, it is not necessary to specify spw.  Had the spectral window 0 not been split off, we might wish to specify the spectral window because, in this observation, the spectral windows were sufficiently separated that two different model images for 3C 286 would be appropriate; 3C286_C.im at 4.6 GHz and 3C286_X.im at 7.5 GHz.  This would require two separate runs of {{setjy}}, one for each spectral window.  If the spectral windows were much closer together, it might be possible to calibrate both using the same model.
 
  
In this case, a model image of a primary flux density calibrator exists. However, for some kinds of polarization calibration or in extreme situations (e.g., there are problems with the scan on the flux density calibrator), it can be useful (or necessary) to set the flux density of the source explicitly.
+
For single band delay there are 8 solutions:
 +
Time=2018/10/04/05:51:12.0 Spw=0 Global cross-hand delay=5.72152 nsec
 +
Time=2018/10/04/05:51:10.6 Spw=1 Global cross-hand delay=1.5355 nsec
 +
Time=2018/10/04/05:51:11.8 Spw=2 Global cross-hand delay=-1.33454 nsec
 +
Time=2018/10/04/05:51:11.5 Spw=3 Global cross-hand delay=0.511222 nsec
 +
Time=2018/10/04/05:51:10.5 Spw=4 Global cross-hand delay=4.33985 nsec
 +
Time=2018/10/04/05:51:10.6 Spw=5 Global cross-hand delay=1.27817 nsec
 +
Time=2018/10/04/05:51:10.4 Spw=6 Global cross-hand delay=3.76724 nsec
 +
Time=2018/10/04/05:51:10.5 Spw=7 Global cross-hand delay=3.08443 nsec
  
The most important output from {{setjy}} should look similar to the following:
 
 
<pre style="background-color: #fffacd;">
 
Selected 31964 out of 845379 rows.
 
  J1331+3030 (fld ind 0) spw 0  [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)
 
Scaling spw(s) [0]'s model image by channel to  I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz ...
 
 
</pre>
 
</pre>
  
As set, the flux density scale is being calculated only for spectral window 0 (''spw='0' ''), as it is the only one in the dataset. The flux density in each Stokes (IQUV) for the reference channel 0 is reported, followed by the I flux density in each channel of the spectral window that will be used to scale the data. This value is determined from an analytical formula for the spectrum of the source as a function of frequency; this value must be determined so that the flux density in the image can be scaled to it, as it is unlikely that the observation was taken at exactly the same frequency as the model image. Also, setjy will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.
+
Notice that the per spectral window solutions are very scattered. The mean delay is 2.36 ns, quite different from the multiband delay. This demonstrates the strength of fitting the cross-hand delay across multiple spectral windows, especially when using a calibrator with a significant frequency dependence, i.e. rotation measure and a polarization fraction of only a few percent. We will continue calibration using the single multiband delay that was derived at 3.71 ns.  
  
Note that setjy also returns a python dictionary (CASA record) containing the reference flux density used. In our case, you will find the return value in the CASA command line window:
+
Note that if we did not solve for this delay, it would be absorbed into the phases per channel of the following Df and Xf solutions. This would not cause us problems if we used an unpolarized D-term calibrator like J2355+4950, as we would not be solving for the Q+iU polarization. But if we were (e.g., using our gain calibrator J0259+0747 with parameter ''poltype='Df+QU' ''), then this step is essential.
<pre>
 
{'0': {'0': {'fluxd': array([ 7.6685524, 0.       ,  0.       ,  0.       ])},
 
  'fieldName': 'J1331+3030'},
 
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}
 
</pre>
 
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.
 
  
=== Initial Phase Calibration ===
+
==== Solving for the Leakage Terms ====
  
Before solving for the bandpass, we will do an initial phase calibration. The reason for this step is to average over the (typically small) variations of phase with time in the bandpass, before solving for the bandpass solution itself. Depending upon frequency and configuration, there could be significant gain variations between different scans of the bandpass calibrator, particularly if the scans happen at much different elevations. One can solve for an initial set of antenna-based gains, which will later be discarded, in order to moderate the effects of variations from integration to integration and from scan to scan on the bandpass calibrator. While amplitude variations with time will have little effect on the bandpass solutions, it is important to solve for phase variations with time to prevent de-correlation when vector averaging the data for computing the final bandpass solution.
+
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J2355+4950 to demonstrate solving for the instrumental polarization. Task {{polcal}} uses the Stokes I, Q, and U values in the model data (Q and U being zero for an unpolarized calibrator) to derive the leakage solutions. We also observed the polarized calibrator J0259+0747 (which has about 4.7% fractional polarization) that is our complex gain calibrator. The observations of J0259+0747 has a parallactic angle coverage of 31 degrees with 10 visits/slices, 3 of which were a bit longer to boost the signal-to-noise to at least 1000 per channel for each of the three passes. We will showcase solving for D-terms for both cases. The function calls are:
  
We use the CASA task {{gaincal}} to solve for phase versus time for the central channels on our three calibrators: 
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all',
 
        field='0,1,9', refant='ea21', spw='0:27~36',
 
        gaintype='G',calmode='p', solint='int',
 
        minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])
 
</source>
 
  
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.
+
# J2355+4950 / Df
* ''field='0,1,9' '': Specify the calibrators. Although the bandpass solution will be based only on the bandpass calibrator, We will use this opportunity to inspect solutions for ALL calibrators in order to potentially identify any bad data.
+
dtab_J2355 = 'TDRW0001_calibrated.Df'  
* ''refant='ea21' '': Earlier, by looking at the output from {{plotants}}, a reference antenna near the center of the array was noted.  Here is the first time that that choice will be used.  Strictly, all of the gain corrections derived will be relative to this reference antenna.
+
polcal(vis='TDRW0001_calibrated.ms',
* ''spw='0:27~36' '': Choose a subset of the channels from which to determine the gain corrections.  These should be near the center of the band, and there should be enough channels chosen so that a reasonable signal-to-noise ratio can be obtained; the central 10% of the channels is a good guideline.  Particularly at lower frequencies where RFI can manifest itself, one should choose RFI-free frequency channels; the [http://go.nrao.edu/vla-rfi VLA Observing Guide RFI page] lists the known RFI frequencies for each band. Also note that, even though these data have only a single spectral window, the syntax requires specifying the spectral window ('0') in order to specify specific channels ('27~36' in this example).
+
      caltable=dtab_J2355,
* ''gaintype='G' '': Compute the complex gain solutions, one per antenna per spw per polarization per solution interval.  Note that ''gaintype='G' '' assumes the V stokes is zero if not told otherwise, so for the case where the calibrator has significant circular polarization, a model incorporating polarization must be used (this can be set with {{setjy}}).  For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set.
+
      field='J2355+4950',
* ''calmode='p' '': Solve for only the phase portion of the gain.
+
      spw='0~7',
* ''solint='int' '': To track the phases, a short solution interval is chosen.  (''int'' refers to a single integration time or 10 seconds for this case)
+
      refant='ea10',
* ''minsnr=5 '': Restrict the solutions to be at relatively high signal-to-noise ratios, although this parameter may need to be varied depending upon the source and frequency.
+
      poltype='Df',
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections, they should now be applied.
+
      solint='inf,2MHz',
 +
      combine='scan',
 +
      gaintable=[kcross_mbd],
 +
      gainfield=[''],
 +
      spwmap=[[0,0,0,0,0,0,0,0]],  
 +
      append=False)
  
To really see what is going on, we use {{plotms}} to inspect the solutions from {{gaincal}} for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (rightward pointing single green arrow) on the GUI to advance the displayed antenna.
+
# J0259+0747 / Df+QU
<source lang="python">
+
dtab_J0259 = 'TDRW0001_calibrated.DfQU'
# In CASA
+
polcal(vis='TDRW0001_calibrated.ms',
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',
+
      caltable=dtab_J0259,
        coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])
+
      intent='CALIBRATE_POL_LEAKAGE#UNSPECIFIED',
 +
      spw='0~7',
 +
      refant='ea10',
 +
      poltype='Df+QU',
 +
      solint='inf,2MHz',
 +
      combine='scan',
 +
      gaintable=[kcross_mbd],
 +
      gainfield=[''],
 +
      spwmap=[[0,0,0,0,0,0,0,0]],
 +
      append=False)
 
</source>
 
</source>
  
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions
+
* ''caltable '': {{polcal}} will create a new calibration table containing the leakage solutions, which we specify with the ''caltable'' parameter.
* ''xaxis='time' '': plotting phase solutions vs time
+
* ''field='' or ''intent='' : The unpolarized source J2355+4950 is used to solve for the leakage terms in the unpolarized case. For the polarized source J0259+0747 we set the intent leakage polarization.
* ''yaxis=phase '': plotting phase solutions vs time
+
* ''spw='0~7' '': Select all spectral windows.
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)
+
* ''poltype='Df' ''or ''poltype='Df+QU' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization, +QU will also solve for the calibrator polarization Q,U per spectral window.
 +
* ''solint='inf,2MHz', combine='scan' '': One solution over the entire run, per spectral channel of 2 MHz
 +
* ''gaintable=['kcross_mbd']'': The previous Kcross multiband delay is applied
 +
* ''spwmap=[[0,0,0,0,0,0,0,0]]'': This applies a spectral window map, where the first spw solution in the kcross_mbd table is mapped to all other spectral windows. Note there is only one value listed inside the kcross calibration table which is for the lowest spectral window that was used when solving using the multiband delay option (i.e. ''combine='spw' '').
  
[[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|200px|thumb|right|Figure 5: Initial gain phases colorized by polarization, stepped through to show ea05]]<pre style="background-color: lightgrey;>
+
In the case of Df+QU, the logger window will show the Q/U values it derived for the calibrator and the corresponding polarization fraction and angle that can be derived.
Note: plotms was originally designed to plot visibility data, while the task plotcal (no longer maintained as of CASA version 5.4.0) was used for plotting calibration tables. Plotms has now taken over the functionality of plotcal. However, some of the input parameter names (e.g., "vis" instead of "caltable") still reflect the original design for plotms. Examples of using plotcal to examine calibration tables can be found in the earlier versions of this and other CASAguide tutorials.
+
<pre style="background-color: #fffacd;">
 +
Fractional polarization solution for J0259+0747 (spw = 0): : Q = 0.0223384, U = 0.0360936  (P = 0.042447, X = 29.1233 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 1): : Q = 0.011474, U = 0.0394478  (P = 0.0410826, X = 36.8911 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 2): : Q = 0.0144008, U = 0.0399272  (P = 0.0424448, X = 35.0834 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 3): : Q = 0.0105389, U = 0.0418852  (P = 0.0431908, X = 37.9384 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 4): : Q = 0.00887324, U = 0.0403241  (P = 0.0412889, X = 38.795 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 5): : Q = 0.00801921, U = 0.0406811  (P = 0.0414639, X = 39.4243 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 6): : Q = 0.00157598, U = 0.0433005  (P = 0.0433292, X = 43.9578 deg)
 +
Fractional polarization solution for J0259+0747 (spw = 7): : Q = -0.00255713, U = 0.0481376  (P = 0.0482055, X = 46.5204 deg)
 
</pre>
 
</pre>
  
Antennas that have been flagged will show a blank plot, as there are no solutions for these antennas. For most antennas, we see a fairly smooth variation with time, so we expect to be able to calibrate the data nicely. However, when you get to ''ea05'', note that there are phase jumps where the phase appears to be oscillating between two states. Stepping through to that antenna reveals Figure 5.
+
From this you can see that J0259+0747 has a fractional polarization of 4.1&ndash;4.8% across the 1 GHz bandwidth with a small rotation measure causing a change in angle from 29 to 46 degrees over 1 GHz. In cases where the derived Q/U values seem random and the fractional polarization seems to be very small you might be able to derive better D-term solutions by using ''poltype='Df' ''.
 +
 
 +
After we run the two executions of {{polcal}}, you are strongly advised to examine the solutions with {{plotms}} to ensure that everything looks good and to compare the results using two different calibrators and poltype methods.
 +
{|
 +
|[[Image:plotms_J0259-Damp-ea01_CASA5.4.1.png|thumb|Figure 7a: J0259+0747 Df amp vs. freq for ea01]]
 +
|[[Image:plotms_J2355-Damp-ea01_CASA5.4.1.png|thumb|Figure 7b: J2355+4950 Df+QU amp vs. freq for ea01]]
 +
|[[Image:plotms_J0259-Dphase-ea01_CASA5.4.1.png|thumb|Figure 7c: J0259+0747 Df phase vs. freq for ea01]]
 +
|[[Image:plotms_J2355-Dphase-ea01_CASA5.4.1.png|thumb|Figure 7d: J2355+4950 Df+QU phase vs. freq for ea01]]
 +
|}
  
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',
+
plotms(vis=dtab_J2355,xaxis='freq',yaxis='amp',  
        flagbackup=True, mode='manual', antenna='ea05')
+
      iteraxis='antenna',coloraxis='corr')
 +
 
 +
plotms(vis=dtab_J0259,xaxis='freq',yaxis='amp',  
 +
      iteraxis='antenna',coloraxis='corr')
 +
 
 +
plotms(vis=dtab_J2355,xaxis='chan',yaxis='phase',
 +
      iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])
 +
 
 +
plotms(vis=dtab_J0259,xaxis='chan',yaxis='phase',
 +
      iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])
 
</source>
 
</source>
 +
This will produce plots similar to those shown in Figures 7A-D. You can cycle through the antennas by clicking the Next button. You should see leakages of between 5&ndash;15% in most cases. Both Df and Df+QU results should be comparable. However, we will be using the solutions from J0259+0747 to continue calibration and will use J2355+4950 to verify the polarization calibration.
  
For the following bandpass solution we need only solve for our bandpass calibrator, and we will do so now after flagging. The following call to {{gaincal}} is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). This is the calibration table we will use when solving for the bandpass solution, below.
+
We can also display these in a single plot versus antenna index (see Figure 8):
 +
[[Image:plotms_J0259-DfQU_CASA5.4.1.png|thumb|Figure 8: Df+QU solutions for J0259+0747 versus antenna index]]
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0',
+
plotms(vis=dtab_J0259,xaxis='antenna1',yaxis='amp',coloraxis='corr')
        field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int',  
 
        minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])
 
 
</source>
 
</source>
You can inspect this with {{plotms}} as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:
+
 
 +
In some cases there are outlier solutions above 0.25 that are most likely due to residual RFI. You can flag those from the Dterm table using {{flagdata}}. If everything went correctly, then this step is not necessary for this dataset.
 
<source lang="python">
 
<source lang="python">
# In CASA
+
flagdata(vis=dtab_J2355, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',
+
flagdata(vis=dtab_J0259, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)
        xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',
 
        plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')
 
 
</source>
 
</source>
  
=== Delay Calibration ===
+
==== Solving for the R-L polarization angle ====
  
The first stage of bandpass calibration involves solving for the antenna-based delays which put a phase ramp versus frequency channel in each spectral window (Figure 3C).  The K gain type in {{gaincal}} solves for the relative delays of each antenna relative to the reference antenna (parameter ''refant''), so be sure you pick one that is there for this entire scan and good.  This is not a full global delay, but gives one value per spw per polarization.
+
Having calibrated for the instrumental polarization, the total polarization is now correct, but the R-L phase still needs to be calibrated in order to obtain an accurate polarization position angle.  We use the same task, {{polcal}}, but this time set parameter ''poltype='Xf', ''which specifies a frequency-dependent (''f'') position angle (''X'') calibration using the source 3C48, whose position angle is known, having set this earlier using {{setjy}}. Note that we must correct for the leakages before determining the R-L phase, which we do by adding the calibration table made in the previous step ('''dtab_J0259''') to the kcross table that is applied on-the-fly.
  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0',  
+
xtab = "TDRW0001_calibrated.Xf"
        field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K',  
+
polcal(vis='TDRW0001_calibrated.ms',
        solint='inf',combine='scan',minsnr=5,
+
      caltable=xtab,
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
+
      spw='0~7',
                  '3c391_ctm_mosaic_10s_spw0.G0'])
+
      field='0137+331=3C48',
 +
      solint='inf,2MHz',
 +
      combine='scan',
 +
      poltype='Xf',
 +
      refant = 'ea10',
 +
      gaintable=[kcross_mbd,dtab_J0259],
 +
      gainfield=['',''],
 +
      spwmap=[[0,0,0,0,0,0,0,0],[]],
 +
      append=False)
 
</source>
 
</source>
  
* ''field='J1331+3030' '': For the bandpass calibrator
+
[[Image:plotms_3c48-Xf_CASA5.4.1.png|thumb|Figure 9: Xf solutions versus frequency.]]
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!
+
Strictly speaking, there is no need to specify a reference antenna for ''poltype='Xf' ''(for circularly polarized receivers only) because the X solutions adjust the cross-hand phases for each antenna to match the given polarization angle of the model. However, for consistency/safety, it is recommended to always specify a refant when performing polarization calibration.
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity
 
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval
 
* ''solint='inf ',combine='scan' '': Only need one solution averaged over all times and scans. ''solint='inf ' '' sets the solution interval to 'infinite' but respects scan boundaries; ''combine='scan' '' combines data across scan boundaries
 
* ''minsnr=5 '': Restrict the solutions to be at relatively high signal-to-noise ratios, although this parameter may need to be varied depending upon the source and frequency.
 
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier
 
  
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]
+
It is strongly suggested you check that the calibration worked properly by plotting up the newly-generated calibration table using {{plotms}} (see Figure 9):
We can plot these solutions (in nanoseconds) as a function of antenna:
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')
+
plotms(vis=xtab,xaxis='frequency',yaxis='phase',coloraxis='spw')
 
</source>
 
</source>
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.
+
Because the Xf term captures the residual R-L phase on the reference antenna over the array, there is only one value for all antennas. Also, as we took out the RL delays using the Kcross solution, these Xf variations do not show a significant slope in phase. And since we were using a single multiband delay, the phases connect from one spectral window to another; had we used the single band delays, we would see phase jumps from one to another spectral window.
 +
 
 +
At this point, you have all the necessary polarization calibration tables.
  
=== Bandpass Calibration ===
+
== Applying the Calibration ==
  
This step solves for the complex bandpass, <math>B_i</math>. 
+
Now that we have derived all the calibration solutions, we need to apply them to the actual data using the task {{applycal}}. The measurement set DATA column contains the original split data. To apply the calibration we have derived, we specify the appropriate calibration tables which are then applied to the DATA column, with the results being written in the CORRECTED_DATA column. If the dataset does not already have a CORRECTED_DATA scratch column, then one will be created in the first {{applycal}} run.
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]
 
All data with the VLA are taken in spectral line mode, even if the science that one is conducting is continuum, and therefore requires a bandpass solution to account for gain variations with frequency. Solving for the bandpass won't hurt for continuum data, and, for moderate or high dynamic range image, it is essential. To motivate the need for solving for the bandpass, consider Figure 7.  It shows the right circularly polarized data (RR polarization) for the source J1331+3030, which will serve as the bandpass calibrator.  The data are color coded by spectral window, as earlier plots from {{plotms}} indicated that the visibility data are nearly constant with baseline length.  Ideally, the visibility data would be constant as a function of frequency as well.  The variations with frequency are a reflection of the (slightly) different antenna bandpasses. (''Exercise for the reader, reproduce Figure 7 using {{plotms}}.'') <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlator=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>
 
  
Now form the bandpass, using the phase solutions just derived.
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',
+
applycal(vis = 'TDRW0001_calibrated.ms',
         field='J1331+3030',spw='',refant='ea21',combine='scan',  
+
        field='',
         solint='inf',bandtype='B',
+
         gainfield=['', '', ''],  
         gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
+
        flagbackup=True,
                    '3c391_ctm_mosaic_10s_spw0.G0',
+
         interp=['', '', ''],
                    '3c391_ctm_mosaic_10s_spw0.K0'])
+
         gaintable=[kcross_mbd,dtab_J0259,xtab],
 +
        spw='0~7',  
 +
        calwt=[False, False, False],
 +
        applymode='calflagstrict',  
 +
        antenna='*&*',
 +
        spwmap=[[0,0,0,0,0,0,0,0],[],[]],
 +
        parang=True)
 +
 
 
</source>
 
</source>
  
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.
+
* ''gaintable'' : We provide a Python list of the calibration tables to be applied. This list must contain the cross-hand delays (kcross), the leakage calibration (dtab) (derived from J0259+0747), and the R-L phase corrections (xtab).
* ''solint='inf ', combine='scan' '': This observation contains multiple scans on the bandpass calibrator, J1331+3030. Because these are continuum observations, it is probably acceptable to combine all the scans and compute one bandpass correction per antenna, which is achieved by the combination of '''solint='inf ' ''and ''combine='scan' ''.  The value ''inf'' means ''infinite'', which means to combine solutions for all times, but to respect scan boundaries. ''combine='scan' '' additionally averages over all scans. Had ''combine=' ' '' then there would have been a bandpass correction derived for each scan (which might be desirable for very high dynamic range spectral line observations).
+
* ''calwt=[False] '': At the time of this writing, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them can produce nonsensical results. Experience has shown that calibrating the weights will lead to problems, especially in the self-calibration steps. You can specify ''calwt'' on a per-table basis, here is set all to ''False''.
* ''bandtype='B' '': The bandpass solution will be derived on a channel-by-channel basis.  There is an alternate option of parameter ''bandtype='BPOLY' '' that will fit an n<sup>th</sup> order polynomial to the bandpass.
+
* ''parang '': If polarization calibration has been performed, set parameter ''parang=True''.
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', '3c391_ctm_mosaic_10s_spw0.G0', '3c391_ctm_mosaic_10s_spw0.K0'] '': Apply antenna positions, phase solutions, and delays before computing bandpass.
 
  
Once again, one can use {{plotms}} to display the bandpass solutions.  Note that in the inputs below, the amplitudes are being displayed as a function of frequency channelThe parameter ''subplot=221'' is used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first two commands below show the amplitude solutions (one per each polarization) and the last two show the phase solutions (one per each polarization).  Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.
+
We should now have fully-calibrated visibilities in the CORRECTED_DATA column of the measurement set, and it is worthwhile pausing to inspect them to ensure that the calibration did what we expected it toWe make some standard plots (see Figures 10A-10F):
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030',  
+
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',
        xaxis='chan',yaxis='amp',coloraxis='corr',
+
      timerange='',antenna='',avgtime='60',
        iteraxis='antenna',gridrows=2,gridcols=2)
+
      xaxis='frequency',yaxis='amp',ydatacolumn='corrected',
 +
      coloraxis='corr',
 +
      plotfile='plotms_3c48-fld0-corrected-amp.png')
 +
 
 +
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',
 +
      timerange='',antenna='',avgtime='60',
 +
      xaxis='frequency',yaxis='phase',ydatacolumn='corrected',
 +
      plotrange=[-1,-1,-180,180],coloraxis='corr',
 +
      plotfile='plotms_3c48-fld0-corrected-phase.png')
 +
 
 +
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='',
 +
      timerange='',antenna='',avgtime='60',
 +
      xaxis='frequency',yaxis='amp',ydatacolumn='corrected',
 +
      plotfile='plotms_J2355-fld1-corrected-amp.png')
 +
 
 +
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='RR,LL',
 +
      timerange='',antenna='',avgtime='60',
 +
      xaxis='frequency',yaxis='phase',ydatacolumn='corrected',
 +
      plotrange=[-1,-1,-180,180],coloraxis='corr',
 +
      plotfile='plotms_J2355-fld1-corrected-phase.png')
 +
 
 +
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',
 +
      timerange='',antenna='',avgtime='60',
 +
      xaxis='frequency',yaxis='amp',ydatacolumn='corrected',
 +
      plotfile='plotms_J0259-fld2-corrected-amp.png')
  
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030',  
+
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',
        xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180],  
+
      timerange='',antenna='',avgtime='60',
        iteraxis='antenna',gridrows=2,gridcols=2)
+
      xaxis='frequency',yaxis='phase',ydatacolumn='corrected',
 +
      plotrange=[-1,-1,-180,180],coloraxis='corr',avgbaseline=True,
 +
      plotfile='plotms_J0259-fld2-corrected-phase.png')
 
</source>
 
</source>
As expected, the bandpass phases are relatively flat (see Figure 8B), with the slopes (Figure 3C) removed by the delay calibration. Residual phase excursions are on the order of a few degrees.
+
For 3C48 (figures 10A, 10B) we see the polarized signal in the cross-hands; there is some sign of bad data remaining in 3C48. Also, the RL phase plots of J0259+4950 (figure 10F) indicate that the Xf solutions, thus polarization angles, in the lowest two spectral windows are problematic. You can also estimate from the RL,LR amplitudes in J2355+4950 (figure 10E) what the level of residual instrumental polarization, which we expect to be around <0.5%. A more accurate evaluation of residual instrumental polarization fraction can be made imaging the secondary D-term calibrator per spectral window and calculating its residual polarization.  
  
 
{|
 
{|
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]
+
| [[Image:plotms_3c48-fld0-corrected-amp_5.4.1.png|thumb|Figure 10A amp vs channel for 3C48 RR,RL,LR,LL]]
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]
+
| [[Image:plotms_3c48-fld0-corrected-phase_5.4.1.png|thumb|Figure 10B: phase vs channel for 3C48 RR,RL,LR,LL]]
 +
| [[Image:plotms_J2355-fld1-corrected-amp_5.4.1.png|thumb|Figure 10C: amp vs channel for J2355+4950 RR,LL,RL,LR]]
 +
| [[Image:plotms_J2355-fld1-corrected-phase_5.4.1.png|thumb|Figure 10D: phase vs channel for J2355+4950 RR,LL]]
 +
| [[Image:plotms_J0259-fld1-corrected-amp_5.4.1.png|thumb|Figure 10E: amp vs channel for J0259+4950 RR,LL,RL,LR]]
 +
| [[Image:plotms_J0259-fld1-corrected-phase_5.4.1.png|thumb|Figure 10F: phase vs channel for J0259+4950 RR,LL with baseline averaging]]
 
|}
 
|}
  
=== Gain Calibration ===
 
  
The next step is to derive corrections for the complex antenna gains, <math>g_i</math> and <math>\theta_i</math>. As discussed above, the absolute magnitude of the gain amplitudes (<math>g_i</math>) are determined by reference to a standard flux density calibrator.  In order to determine the appropriate complex gains for the target source, and to minimize differences through the atmosphere (neutral and/or ionized) between the lines of sight to the phase calibrator and the target source, you want to observe a so-called phase calibrator that is much closer to the target. If we establish the relative gain amplitudes and phases for different antennas using the phase calibrator, we can later determine the absolute flux density scale by comparing the gain amplitudes, <math>g_i</math>, derived for 3C 286 with those derived for the phase calibrator.  This will eventually be done using the task {{fluxscale}}.  Since there is no such thing as absolute phase, we determine a zero phase by selecting a reference antenna for which the gain phase is defined to be zero.
+
Inspecting the data at this stage may well show up previously-unnoticed bad data. Plotting the '''corrected''' amplitude against UV distance or against time is a good way to find such issues. If you find bad data, you can remove them via interactive flagging in {{plotms}} or via manual flagging in {{flagdata}} once you have identified the offending antennas/baselines/channels/times. When you are happy that all data (particularly on your target source) look good, you may proceed. However, especially for the target, we will return to additional flagging at a later stage.  
  
In principle, one could determine the complex antenna gains for all sources with a single invocation of {{gaincal}}; for clarity here, two separate invocations will be used.
+
Now that the calibration has been applied to the target data, we split off the science targets to create a new, calibrated measurement set containing the target field. This is not strictly necessary if you want to save disk space.  
  
In the first step, we derive the appropriate complex gains <math>g_i</math> and <math>\theta_i</math> for the flux density calibrator 3C 286.
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',
+
split(vis='TDRW0001_calibrated.ms',outputvis='3C75.ms',
        field='J1331+3030',spw='0:5~58',
+
      datacolumn='corrected',field='3')
        solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                  '3c391_ctm_mosaic_10s_spw0.K0',
 
                  '3c391_ctm_mosaic_10s_spw0.B0'],
 
        interp=['linear','linear','nearest'])
 
 
</source>
 
</source>
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': Produce a new calibration table containing these gain solutions.  In order to make the bookkeeping easier, a '1' is appended to the file name to distinguish it from the earlier set of gain solutions, which are effectively being thrown away.
 
* ''spw='0:5~58' '': From the inspection of the bandpass, one can determine the range of edge channels that are affected by the bandpass filter rolloff.  Because the amplitude is dropping rapidly in these channels, one does not want to include them in the solution.
 
* ''gaintype='G', calmode='ap', solnorm=False'': Solve for the complex antenna gains for 3C 286.  The objective is to relate the measured data values to the (assumed known) flux density of 3C 286, thus the solution is both amplitude and phase ('ap') and the solutions should not be normalized to unity amplitude.
 
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.
 
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', '3c391_ctm_mosaic_10s_spw0.K0', '3c391_ctm_mosaic_10s_spw0.B0'] '': Use the antenna position corrections, delays, and bandpass solutions determined earlier before solving for the gain amplitudes.
 
* ''interp=['linear','linear','nearest']'': the temporal interpolation to use for each gaintable.  When there are multiple bandpass solutions, it can be especially important to use 'nearest' for the bandpass table, as linear would allow extrapolation beyond the sampled times.  (As there is only one bandpass solution for this Guide, specifying 'nearest' is not strictly necessary as 'linear' and 'nearest' result in the same behavior in the case of a single time solution.  We include the specification for demonstration purposes.)
 
  
In the second step, the appropriate complex gains for a direction on the sky close to the target source will be determined from the phase calibrator J1822-0938We also determine the complex gains for the polarization calibrator source J0319+4130. These will be solved separately, but in practice could be solved together as there are no gaintables that are time dependent at this point (and thus would risk having cross-source interpolation issues), nor are we doing different solution intervals per source.
+
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science target.
 +
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using {{applycal}}.
 +
* ''field '': We wish to target field into a measurement set for imaging and joint deconvolution.
 +
 
 +
Prior to imaging, it is a good idea to run the {{statwt}} task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement setRunning {{statwt}} will remove the effects of relative noise scatter that may have been introduced from flagging uneven bits in the visibility data between the channels and times. We will run this task here on the newly calibrated and split data set before moving on to imaging.
 +
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',
+
statwt(vis='3C75.ms',datacolumn='data')
        field='J1822-0938',
+
</source>
        spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',
+
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
+
= Imaging =
                  '3c391_ctm_mosaic_10s_spw0.K0',
+
 
                  '3c391_ctm_mosaic_10s_spw0.B0'],
+
Now that we have split off the target data into a separate measurement set with all the calibration applied, it's time to make an image. Recall that the visibility data and the sky brightness distribution (a.k.a. image) are Fourier transform pairs.
        append=True)
+
 
 +
<math>
 +
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv
 +
</math>
 +
 
 +
The <math>u</math> and <math>v</math> coordinates are the baselines measured in units of the observing wavelength, while the <math>l</math> and <math>m</math> coordinates are the direction cosines on the sky.  For generality, the sky coordinates are written in terms of direction cosines; but for most VLA (and ALMA) observations they can be related simply to the right ascension (<math>l</math>) and declination (<math>m</math>). Also recall that this equation is valid only if the <math>w</math> coordinate of the baselines can be neglected; this assumption is almost always true at high frequencies and smaller VLA configurations. The <math>w</math> coordinate cannot be neglected at lower frequencies and larger configurations (e.g., 0.33 GHz, A-configuration observations). This expression also neglects other factors, such as the shape of the primary beam. For more information on imaging, see the [https://casa.nrao.edu/casadocs/latest/synthesis-imaging Synthesis Imaging] section of the CASA documentation.
 +
 
 +
[[Image:plotms_3c75-uvwave_4.5.1.png|thumb|Figure 11: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C75 at 3000 MHz]]
 +
CASA has a task {{tclean}} which both Fourier transforms the data and deconvolves the resulting image. For the purposes of this tutorial, we will make a mosaic clean image in Stokes I only; polarimetric imaging will be addressed in an upcoming new CASAguide. We will use a multi-scale cleaning algorithm because the supernova remnant contains both diffuse, extended structure on large spatial scales and finer filamentary structure on smaller scales. This approach will do a better job of modeling the image than the classic clean delta function. For broader examples of many {{tclean}} options, please see the [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Imaging_VLA_Data_in_CASA Topical Guide for Imaging VLA Data].
  
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',
+
== Multi-scale Clean ==
        field='J0319+4130',
 
        spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                  '3c391_ctm_mosaic_10s_spw0.K0',
 
                  '3c391_ctm_mosaic_10s_spw0.B0'],
 
        append=True)
 
</source>
 
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True '': In all previous invocations of {{gaincal}}, append has been set to False.  Here, the gain solutions from the phase calibrators are going to be appended to the existing set from 3C 286.  In following steps, all of these gain solutions will then be used together to derive a set of complex gains that are applied to the science data for the target source.
 
  
If one checks the gain phase solutions using {{plotms}}, one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). 
+
It is important to have an idea of what values to use for the image pixel (cell) size and the overall size of the image. Setting the appropriate pixel size for imaging depends upon basic optics aspects of interferometry. Using {{plotms}} to look at the newly-calibrated, target-only data set:
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',
+
plotms(vis='3C75.ms',xaxis='uvwave',yaxis='amp',
       gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',
+
       ydatacolumn='data', field='0',avgtime='30',correlation='RR',
       plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')
+
       plotfile='plotms_3c75-uvwave.png',avgspw=False,overwrite=True)
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',
 
      gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',
 
      plotfile='plotms_3c391-G1-amp.png')
 
 
</source>
 
</source>
 +
You should obtain a plot similar to Figure 11 with the (calibrated) visibility amplitude as a function of <math>u</math>-<math>v</math> distance. You also see some outliers there which are primarily from residual amplitude errors of ea05, which had a warm receiver which we can isolate to particular time periods. We will be addressing this after the initial imaging. The maximum baseline is about 12,000 wavelengths, i.e., an angular scale of 17 arcseconds (<math>\lambda/D=1/12000</math>). The most effective cleaning occurs with 3&ndash;5 pixels across the synthesized beam. For example, a cell size of 3.4 arcseconds will give just about 5 pixels per beam. 
  
{|
+
The binary black hole system is known to have a maximum extend of at least 8-9 arcminutes, corresponding to about 147 pixels for the chosen cell size. Thus, we need to choose an image size that covers most of the extent of the source. To be safe from bright, far out, sources we should at least cover the primary beam. Although CASA has the feature that its Fourier transform engine (FFTW) does ''not'' require a strict power of 2 for the number of linear pixels in a given image axis, it is somewhat more efficient if the number of pixels on a side is a composite number divisible by ''any pair'' of 2 and 3 and/or 5. Because {{tclean}} internally applies a padding of 1.2 (=3x2/5), choose 480 which is 2<sup>5</sup> &times; 3 &times; 5 (so 480 &times; 1.2 = 576 = 2<sup>6</sup> &times; 3<sup>2</sup>). We therefore set ''imsize=[480,480]'' and the source will fit comfortable within that image.
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.4.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]
 
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.4.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]
 
|}
 
 
 
This is also a good time to check that our chosen reference antenna (''ea21'') has good phase stability (i.e., the phase difference between the right and left polarizations is stable with time). This is a prerequisite for accurate polarization calibration.  To do this, we plot the complex polarization ratio by selecting ''correlation=' / ' '':
 
  
 +
In this tutorial, we will run {{tclean}} interactively so that we can set and modify the mask:
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',
+
tclean(vis='3C75.ms',
        correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])
+
      field="3C75",
 +
      spw="",timerange="",
 +
      uvrange="",antenna="",scan="",observation="",intent="",
 +
      datacolumn="data",
 +
      imagename="3C75_initial",
 +
      imsize=480,
 +
      cell="3.4arcsec",
 +
      phasecenter="",
 +
      stokes="IQUV",
 +
      projection="SIN",
 +
      specmode="mfs",
 +
      reffreq="3.0GHz",
 +
      nchan=-1,
 +
      start="",
 +
      width="",
 +
      outframe="LSRK",
 +
      veltype="radio",
 +
      restfreq=[],
 +
      interpolation="linear",
 +
      gridder="standard",
 +
      mosweight=True,
 +
      cfcache="",
 +
      computepastep=360.0,
 +
      rotatepastep=360.0,
 +
      pblimit=0.0001,
 +
      normtype="flatnoise",
 +
      deconvolver="mtmfs",
 +
      scales=[0, 6, 18],
 +
      nterms=2,
 +
      smallscalebias=0.6,
 +
      restoration=True,
 +
      restoringbeam=[],
 +
      pbcor=False,
 +
      outlierfile="",
 +
      weighting="briggs",
 +
      robust=0.5,
 +
      npixels=0,
 +
      uvtaper=[],
 +
      niter=20000,
 +
      gain=0.1,
 +
      threshold=0.0,
 +
      nsigma=0.0,
 +
      cycleniter=1000,
 +
      cyclefactor=1.0,
 +
      restart=True,
 +
      savemodel="modelcolumn",
 +
      calcres=True,
 +
      calcpsf=True,
 +
      parallel=False,
 +
      interactive=True)
 
</source>
 
</source>
  
As can be seen in Figure 10, there is a bit of drift (a few degrees here and there), but no phase jumps. This means that ea21 is, indeed, a good choice for reference antenna.
+
Task {{tclean}} is powerful with many inputs and a certain amount of experimentation likely is required.
 +
[[Image:3c75-tclean-interactive-start_CASA5.4.1.png|thumb|Figure 12: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]
 +
* ''vis='3C75.ms' '': this split MS contains the target field only.
 +
* ''imagename='3C75_initial' '': our output image cube will all start with this, e.g., 3C75_initial.image
 +
* ''specmode='mfs' '': Use multi-frequency synthesis imaging. The fractional bandwidth of these data is non-zero (1000 MHz at a central frequency of 3.0 GHz). Recall that the <math>u</math> and <math>v</math> coordinates are defined as the baseline coordinates, measured in wavelengths. Thus, slight changes in the frequency from channel to channel result in slight changes in <math>u</math> and <math>v</math>. There is a concomitant improvement in <math>u</math>-<math>v</math> coverage if the visibility data from the multiple spectral channels are gridded separately onto the <math>u</math>-<math>v</math> plane, as opposed to treating all spectral channels as having the same frequency.
 +
* ''niter=20000,gain=0.1,threshold='0.0mJy' '': Recall that the gain is the amount by which a clean component is subtracted during the cleaning process. Parameters ''niter'' and ''threshold'' are (coupled) means of determining when to stop the cleaning process, with ''niter'' specifying to find and subtract that many clean components while ''threshold'' specifies a minimum flux density threshold a clean component can have before {{tclean}} stops (also see ''interactive'' below). Imaging is an iterative process, and to set the threshold and number of iterations, it is usually wise to clean interactively in the first instance, stopping when spurious emission from sidelobes (arising from gain errors) dominates the residual emission in the field. Here, we have set the threshold level to zero and let the {{tclean}} task define an appropriate threshold. The number of iterations should then be set high enough to reach the threshold found by tclean.
 +
* ''gridder='standard' '': The standard tclean gridder is sufficient for our purposes, since we are not combining multiple pointings from a mosaic or try to perform widefield imaging in an extended configuration.
 +
* ''interactive=True '': Very often, particularly when one is exploring how a source appears for the first time, it can be valuable to interact with the cleaning process. If True, ''interactive'' causes a {{viewer}} window to appear. One can then set clean regions, restricting where {{tclean}} searches for clean components, as well as monitor the cleaning process. A standard procedure is to set a large value for ''niter'', and stop the cleaning when it visually appears to be approaching the noise level. This procedure also allows one to change the cleaning region, in cases when low-level intensity becomes visible as the cleaning process proceeds. 
 +
* ''imsize=480,cell='3.4arcsec' '': See the discussion above regarding the setting of the image size and cell size. If only one value is specified, the same value is used in both directions.
 +
* ''stokes='IQUV' '': An image cube will be made containing total intensity I, and Stokes Q, U, and V.
 +
* ''deconvolver='multiscale', scales=[0, 6, 18], smallscalebias=0.9 '':  The settings for ''multiscale'' are in units of pixels, with 0 pixels equivalent to the traditional delta-function clean.  The scales here are chosen to provide delta functions and then two logarithmically scaled sizes to fit to the data. The first scale (6 pixels) is chosen to be comparable to the size of the synthesized beam. The ''smallscalebias'' attempts to balance the weight given to larger scales, which often have more flux density, and the smaller scales, which often are brighter. Considerable experimentation is likely to be necessary; one of the authors of this document found that it was useful to clean several rounds with this setting, change to ''multiscale=[]'' and remove much of the smaller scale structure, then return to this setting.
 +
* ''weighting='briggs',robust=0.5 '': 3C75 has diffuse, extended emission that is, at least partially, resolved out by the interferometer even though we are in the most compact VLA configuration. A naturally-weighted image would show large-scale patchiness in the noise. In order to suppress this effect, Briggs weighting is used (intermediate between natural and uniform weighting), with a default robust factor of 0.5 (which corresponds to something between natural and uniform weighting).
 +
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).
 +
* ''savemodel='modelcolumn' '': We recommend here the use of a physical MODEL_DATA scratch column. This will save some time, as it can be faster in the case of complicated gridding to read data from disk instead of doing all of the computations on-the-fly. However, this has the unfortunate side effect of increasing the size of the MS on disk.
  
 +
[[Image:3c75-tclean-multiscale-500iters_CASA5.4.1.png|thumb|Figure 13: After the first approximately 500 iterations of multi-scale mfs clean]]
  
{|
+
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region.  When {{tclean}} runs in interactive mode, a {{viewer}} window will pop up as shown in Figure 12. First, you'll want to navigate to the green box and select "All Polarizations" rather than use the default "This Polarization"; this way the cleaning we are about to do will apply to all of the polarizations rather than just the one we are currently viewing. To get a more detailed view of the central regions containing the emission, zoom in by first left clicking on the zoom button (leftmost button in third row) and tracing out a rectangle with the left mouse button and double-clicking inside the zoom box you just made. Play with the color scale to bring out the emission better by holding down the middle mouse button and moving it around. To create a clean box (a region within which components may be found), hold down the right mouse button and trace out a rectangle around the source, then double-click inside that rectangle to set it as a box. Note that the clean box must turn white for it to be registered; if the box is not white, it has not been set. Alternatively, you can trace out a more custom shape to better enclose the irregular outline of the supernova remnant. To do this, right-click on the closed polygonal icon then trace out a shape by right-clicking where you want the corners of that shape. Once you have come full circle, the shape will be traced out in green, with small squares at the corners. Double-click inside this region and the green outline will turn white. You have now set the clean region. If you have made a mistake with your clean box, click on the Erase button, trace out a rectangle around your erroneous region, and double-click inside that rectangle. You can also set multiple clean regions.
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.4.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]
 
|}
 
  
=== Polarization Calibration ===
+
At any stage in the cleaning, you can adjust the number of iterations that {{tclean}} will do before returning to the GUI. This is set to 1000 (see the iterations field in mid-upper left of panel), values from 500 to 1000 later on seem to work. Note that this will override the ''niter'' that was set when you started {{tclean}}. {{tclean}} will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).
  
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''
+
[[Image:3c75-tclean-residuals_CASA5.4.1.png|thumb|Figure 14: Interactive residuals after about 13000 iterations of multi-scale mfs clean]]
 +
When you are happy with the clean regions, press the green circular arrow button on the far right to continue deconvolution. After completing a cycle, a revised image will come up. As the brightest points are removed from the image (cleaned off), fainter emission may show up. You can adjust the clean boxes each cycle, to enclose all real emission. After many cycles, when only noise is left, you can hit the red-and-white stop-sign icon to stop cleaning. Figure 13 shows the interactive viewer panel later in the process, after cleaning about 500 iterations. We have used the polygon tool to add to the clean region, drawing around emission that shows up in the residual image outside of the original clean region. After about 13000 iterations (Figure 14) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting {{tclean}} with different ''multiscale=[...]'' choices can help also. You see that there is a significant amount of residual structure, these are most likely due to calibration errors which we will try to correct for in the next section during self-calibration.
  
Having set the complex gains, we need to do the polarization calibrationPolarization calibration is done in two steps. First, we solve for the instrumental polarization (the frequency-dependent leakage terms ('D-terms')), using either an unpolarized source (we use 3C 84 here) or a source which has sufficiently good parallactic angle coverage.  Second, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C 286 here). For information on polarization calibrators suitable for VLA observations, see the [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/pol VLA Observing Guide on Polarimetry].  
+
Task {{tclean}} will make several output files, all named with the prefix given as ''imagename''These include:
 +
* ''.image'': final restored image(s) with the clean components convolved with a restoring beam and added to the remaining residuals at the end of the imaging process, one for each Taylor Term (.tt0 and .tt1)
 +
* ''.pb.tt0'': effective response of the telescope (the primary beam)
 +
* ''.mask'': areas where {{tclean}} has been allowed to search for emission
 +
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set, one for each Taylor Term (.tt0 and .tt1)
 +
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process, one for each Taylor Term (.tt0, .tt1, .tt2)
 +
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply, one for each Taylor Term (.tt0, .tt1)
 +
* ''.sumwt'': a single pixel image containing sum of weights per plane, one for each Taylor Term (.tt0, .tt1, .tt2)
  
Before solving for the calibration solutions, we first use {{setjy}} to set the polarization model for our polarized position-angle calibrator. The initial run of {{setjy}} above only set the total intensity of our flux calibrator source, 3C 286This source is known to have a fairly stable fractional polarization (measured to be 11.2% in C-band around the time of the observations), and a polarization position angle of 33 degrees (at most frequencies). We will use the calibration solutions that we derived earlier (for the delays, bandpass, and gains (for Stokes I)) in combination with the polarization model to derive polarization solutions.
+
{|
 +
|[[Image:3c75-viewer-multiscale-initial_I_CASA5.4.1.png|thumb|Figure 15A: Viewer panel of final restored Stokes I image (using HotMetal1 colormap and Scaling Power Cycles = -0.5)]]
 +
  |[[Image:3c75-viewer-multiscale-initial_Q_CASA5.4.1.png|thumb|Figure 15B: Viewer panel of final restored Stokes Q image (using HotMetal1 colormap and Scaling Power Cycles = -0.5)]]
 +
|[[Image:3c75-viewer-multiscale-initial_U_CASA5.4.1.png|thumb|Figure 15C: Viewer panel of final restored Stokes U image (using HotMetal1 colormap and Scaling Power Cycles = -0.5)]]
 +
|[[Image:3c75-viewer-multiscale-initial_V_CASA5.4.1.png|thumb|Figure 15D: Viewer panel of final restored Stokes V image (using HotMetal1 colormap and Scaling Power Cycles = -0.5)]]
 +
|}
  
The {{setjy}} task will calculate the values of Stokes Q and U (in the reference channel) for user inputs of the reference frequency, Stokes I, polarization fraction, and polarization angle.  Examining our casa-<timestamp>.log file to find the output from the previous call to setjy, we find that the total intensity was set to 7.6686 Jy in channel 0 of spw 0 at 4536 MHz.  We use these values for the Stokes I and reference frequency in the new call to setjy.  We can account for a frequency variation in the Stokes I value by manually setting a spectral index.  This is done by noting that the logger output from {{setjy}} reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.
+
After the imaging and deconvolution process has finished, you can use the {{viewer}} to look at your image.
We use the Python interpreter to compute a spectral index:
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)
+
viewer('3C75_initial.image.tt0')
 
</source>
 
</source>
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)
+
You can adjust the color scale and zoom in to a selected region by assigning mouse buttons to the icons immediately above the image (hover over the icons to get a description of what they do). Also, using the wrench panel to change Display Options will be helpful here. Here we selected the Hot Metal 1 colormap and set the Scaling Power Cycles to -1 to better emphasize the faint emission and compare to the noise (Figures 15A - D). You can also use the Animators slider for Stokes to switch between the four different Stokes parameter images that were computed.  
  
It is also possible to capture a frequency variation in Q, U, and alpha terms by providing coefficients of polynomial expansion for polarization index, polarization angle, and spectral index as a function of frequency. The calibrator used for this guide, 3C 286, has very little variation in Q and U with frequency, and a constant spectral index in C band.  Therefore, for our purposes it is sufficient to use only the first Taylor term of the expansion(For the example below, if we had calculated other coefficients in the polynomial expansion, we would provide them as input via ''polindex=[c0,c1,...]'', etc.  See the {{setjy}} documentation for further details on this topic.)
+
The {{tclean}} task naturally operates in a flat noise image, i.e., an image where the effective weighting across the field of view is set so that the noise is constant. This is so that the clean threshold has a uniform meaning for the stopping criterion and that the image fed into the minor cycles has uniform noise levels. This means, however, that the image does not take into account the primary beam fall-off in the edges. We could have set parameter ''pbcor=True'' in {{tclean}}, but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean imageTherefore, we use {{impbcor}} to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:
 
 
To generate the polarization model, the call to setjy looks like the following:
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
i0=7.6686 # Stokes I value for spw 0 ch 0
+
impbcor(imagename='3C75_initial.image.tt0',pbimage='3C75_initial.pb.tt0',
c0=0.112 # Fractional polarization=11.2%
+
        outfile='3C75_initial.pbcorimage')
d0=33*pi/180 # polarization angle of 33 degrees converted to radians
 
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',
 
      spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',
 
      polindex=[c0,0], polangle=[d0,0],
 
      scalebychan=True, usescratch=False)
 
 
</source>
 
</source>
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.
 
* ''standard='manual' '': the user will supply the flux density, spectral index, and polarization parameters rather than giving a model (currently the CASA models do not include polarization).
 
* ''fluxdensity=[i0,0,0,0]' '': you may provide values of Q and U rather than having setjy calculate them.  However, if you set Q and U as input using the fluxdensity parameter, then any values given in polindex or polangle will be ignored.
 
* ''spix=[alpha,0]' '': set the spectral index using the value above. This will apply to all non-zero Spokes parameters. In this example, we only use the first coefficient of the Taylor expansion, setting the second parameter to 0 for demonstration purposes (''spix=[alpha,0]' '' would have the same effect).
 
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.
 
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.
 
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.
 
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.
 
* ''usescratch=False'': DO NOT create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space)
 
The Stokes V flux has been set to zero, corresponding to no circular polarization.
 
  
Again, setjy returns a Python dictionary (CASA record) that reports the Stokes I, Q, U and V terms. This is reported to the CASA command line window:
+
You can open this in the {{viewer}} and see that it has indeed raised the noise (and signal) at the edges of the image.
<pre>
+
 
{'0': {'0': {'fluxd': array([ 7.6686    ,  0.34933927,  0.78462885,  0.        ])},
+
== Self-Calibration ==
  'fieldName': 'J1331+3030'},
 
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}
 
</pre>
 
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.
 
  
If desired, you could determine the values of the first Taylor terms for Q and U with the following simple calculations, which provide a nice verification that {{setjy}} has performed the calculation correctly:
+
Before we get started with self-calibration, it might be good to check whether we need to perform some additional flagging on the target data. Since we have established an image model in the previous section, we can use it to look at the residuals by dividing out the model. We can make a similar plot to Figure 11 above, however, we will divide the image model that was created. Since we performed full-polarization imaging, we can also do the same to the cross-hand data RL,LR. Figures 16A & B shows example plots. You should also have a look at time plotted against amplitude and frequency against amplitude to see if there are any obvious times of interference.
<source lang="python">
 
# In CASA
 
i0=7.6686 # Stokes I value for spw 0 ch 0
 
p0=0.112*i0 # Fractional polarization=11.2%
 
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)
 
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)
 
</source>
 
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from {{setjy}}, above.
 
  
We can see the results in the model column in {{plotms}} (Figure 11A) showing the model source spectrum:
 
<source lang="python">
 
# In CASA
 
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',
 
      timerange='08:02:00~08:17:00',antenna='ea01&ea02',
 
      xaxis='channel',yaxis='amp',ydatacolumn='model',
 
      plotfile='plotms_3c391-model-amp-RR.png')
 
</source>
 
We can see this translates to the spectrum in QU (Figure 11B):
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',
+
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',
       timerange='08:02:00~08:17:00',antenna='ea01&ea02',
+
       ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RR',
      xaxis='channel',yaxis='amp',ydatacolumn='model',
+
       plotfile='plotms_3c75-uvdist_resid_RR.png',avgspw=False,overwrite=True)
       plotfile='plotms_3c391-model-amp-RL.png')
 
</source>
 
  
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization
+
# If you made a mistake above and didn't clean the polarization as well, then this plot will be empty.
angle) as desired (Figure 11C):
+
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',
<source lang="python">
+
       ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RL',
# In CASA
+
       plotfile='plotms_3c75-uvdist_resid_RL.png',avgspw=False,overwrite=True)
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',
 
       timerange='08:02:00~08:17:00',antenna='ea01&ea02',
 
      xaxis='channel',yaxis='phase',ydatacolumn='model',
 
       plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')
 
 
</source>
 
</source>
<!-- *as of r24160, this crashes on MacOS X* -->
 
  
{|  
+
{|
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]
+
| [[Image:plotms_3c75_uvdist_resid_RR_CASA5.4.1.png|thumb|Figure 16A: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 at 3000 MHz and RR correlations.]]
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]
+
| [[Image:plotms_3c75_uvdist_resid_RL_CASA5.4.1.png|thumb|Figure 16B: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 at 3000 MHz and RL correlations.]]
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]
 
 
|}
 
|}
  
==== Solving for the Cross-Hand delays ====
+
Since we are seeing a significant amount of weak residual interference, we will take a few steps to reduce these. There seem to be spikes at scan boundaries, we will use the mode ''quack'' to remove the first unflagged integrations from the beginning and end of each target scan.
 
 
Just as we did for the parallel-hand (RR,LL) delays before bandpass calibration, we solve for the cross-hand (RL, LR) delays due to the residual delay difference between the R and L on the reference antenna (''ea21'') used for the original delay calibration. In our case, we simply use 3C286, which has a strong polarized signal in the RL, LR correlations.
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',
+
 
        field='J1331+3030', spw='0:5~58',
+
# quack
        gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',
+
cmd = ["mode='quack' quackmode='beg' quackincrement=True quackinterval=5.0",
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
+
      "mode='quack' quackmode='endb' quackincrement=False quackinterval=5.0"]
                  '3c391_ctm_mosaic_10s_spw0.K0',
+
flagdata(vis='3C75.ms',mode='list',inpfile=cmd,flagbackup=False)
                  '3c391_ctm_mosaic_10s_spw0.B0',
+
# tfcrop
                  '3c391_ctm_mosaic_10s_spw0.G1'],
+
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RR,LL',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')
        gainfield=['','','','J1331+3030'],
+
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RL,LR',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')
        parang=True)
+
# rflag
 +
flagdata(vis='3C75.ms',mode='rflag',correlation='RR,LL',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')
 +
flagdata(vis='3C75.ms',mode='rflag',correlation='RL,LR',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')
 +
# extend flags
 +
flagdata(vis='3C75.ms',mode='extend',flagbackup=False)
 
</source>
 
</source>
  
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]
+
This should have gotten rid of the worst remaining outliers, but will leave some residual weak RFI on certain baseline lengths. Since we are not trying to win any records on high dynamic range imaging this additional flagging should suffice for this dataset.
We can plot these (see Figure 12):
+
 
<source lang="python">
+
In addition to residual RFI, even after calibration using the amplitude calibrator and the phase calibrator, there are likely to be residual phase and/or amplitude errors in the data. Self-calibration uses an existing model, often constructed from imaging the data itself, provided that sufficient visibility data have been obtained. This is essentially always the case with data: the system of equations is wildly over-constrained for the number of unknowns.
# In CASA
 
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')
 
</source>
 
As expected there is a single value for R versus L (with L delay set to zero) across all antennas. The solution is reported in the logger, and is 7.15037 nsec.
 
  
Note that if we did not solve for this delay, it would be absorbed into the phases per channel of the following Df and Xf solutions.  This would not cause us problems, as we are not solving for the Q+iU polarization of our D-term calibrator (we are using unpolarized 3C84 for that) but if we were (e.g., using our gain calibrator J1822-0938 with parameter ''poltype='Df+QU' '') then this step would be essential.
+
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as
  
==== Solving for the Leakage Terms ====
+
<math>
 +
V'_{ij} = G_i G^*_j V_{ij}
 +
</math>
  
The task {{polcal}} is used for polarization calibrationIn this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarizationTask {{polcal}} uses the Stokes I, Q, and U values in the model data (Q and U being zero for our unpolarized calibrator) to derive the leakage solutions. The function call is:
+
where <math>G_i</math> is the complex gain for the <math>i^{\mathrm{th}}</math> antenna and <math>V_{ij}</math> is the true visibilityFor an array of <math>N</math> antennas, at any given instant, there are <math>N(N-1)/2</math> visibility data, but only <math>N</math> gain factorsFor an array with a reasonable number of antennas, <math>N</math> >~ 8, solutions to this set of coupled equations converge quickly.
  
<source lang="python">
+
There is a small amount of discussion in the old CASA Reference Manual on
# In CASA
+
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), but we have lectures on [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-stsci/cde_selfcal.pdf Self-calibration] given at NRAO community days. In self-calibrating data, it is useful to keep in mind the structure of a Measurement Set. There are three columns of interest for an MS: the DATA column, the MODEL column, and the CORRECTED_DATA column. In normal usage, as part of the initial split, the CORRECTED_DATA column is set equal to the DATA column. The self-calibration procedure is then:
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',
 
      field='J0319+4130',spw='0:5~58',
 
      refant='ea21',poltype='Df',solint='inf',combine='scan',
 
      gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                  '3c391_ctm_mosaic_10s_spw0.K0',
 
                  '3c391_ctm_mosaic_10s_spw0.B0',
 
                  '3c391_ctm_mosaic_10s_spw0.G1',
 
                  '3c391_ctm_mosaic_10s_spw0.Kcross'],
 
      gainfield=['','','','J0319+4130',''])
 
</source>
 
  
* ''caltable='3c391_ctm_mosaic_10s_spw0.D1' '': {{polcal}} will create a new calibration table containing the leakage solutions, which we specify with the ''caltable'' parameter.
+
* Produce an image ({{tclean}}) using the CORRECTED_DATA column.
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.
+
* Derive a series of gain corrections ({{gaincal}}) by comparing the DATA columns and the Fourier transform of the image, which is stored in the MODEL column. These corrections are stored in an external table.
* ''spw='0:5~58' '': In this example, the edge channels are not used in finding the solution.  Because the bandpass is one of the calibration tables being applied (in ''gaintable''), this restriction is not necessary.  However, if one restricts the spectral window here, it '''must''' also be restricted in the remainder of the calibration steps, particularly {{applycal}}, otherwise the final data set  will contain frequency channels for which the leakage terms have  not been calibrated.
+
** Optionally, we can also derive a bandpass correction&mdash;which is also referred to as bandpass self calibration&mdash;to correct for global amplitude errors.
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.
+
* Apply these corrections ({{applycal}}) to the DATA column to form a new CORRECTED_DATA column ''overwriting'' the previous contents of CORRECTED_DATA.
* ''solint='inf ', combine='scan' '': One solution over the entire run
 
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', '3c391_ctm_mosaic_10s_spw0.K0', '3c391_ctm_mosaic_10s_spw0.B0', '3c391_ctm_mosaic_10s_spw0.G1', '3c391_ctm_mosaic_10s_spw0.Kcross']'': All of the previous corrections (antenna positions, K-delay, bandpass, Kcross-delay, and complex gain) are to be applied
 
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J0319+4130','&nbsp;'] '': The gain caltable that is being applied on the fly, '''3c391_ctm_mosaic_10s_spw0.G1''', contains the solutions for multiple sources.  Only the solutions from J0319+4130 should be applied to itself in the process of finding the polarization leakage terms.
 
  
After polcal has finished running, you are strongly advised to examine the solutions with {{plotms}}, to ensure that everything looks good.
+
The following example begins with the standard data set, 3C75.ms (resulting from the steps above). We have previously generated an IQUV multiscale image cube. We discard it for this step and generate a new Stokes I image, which we will use to generate a series of gain corrections that will be stored in 3C75.ScG0. With this solution, we then perform bandpass self-calibration and apply the derived phase and amplitude corrections to the data to form a set of self-calibrated data and a new image is then formed (3C75_selfcal.image). For the purpose of self-calibration, note that in the clean before the self-cal, it is important that we only use the Stokes I model so that any cleaned polarization do not affect the gaincal. We first use {{delmod}} on the MS to get rid of the previous polarized model and then run tclean to generate the Stokes I image. In principle, it is possible to use the previous image cube and extract the Stokes I model using the CASA toolkit and have {{tclean}} fill the model column appropriately. However, for simplicity we just re-image with {{tclean}} and selecting only Stokes I.
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]
 
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]
 
 
<source lang="python">
 
<source lang="python">
# In CASA
+
#In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp',
+
delmod('3C75.ms')
      iteraxis='antenna',coloraxis='corr')
 
  
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase',  
+
tclean(vis='3C75.ms',
       iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])
+
      field="3C75",
 +
      spw="",timerange="",
 +
       uvrange="",antenna="",scan="",observation="",intent="",
 +
      datacolumn="data",
 +
      imagename="3C75_initial_I",
 +
      imsize=480,
 +
      cell="3.4arcsec",
 +
      phasecenter="",
 +
      stokes="I",
 +
      projection="SIN",
 +
      specmode="mfs",
 +
      reffreq="3.0GHz",
 +
      nchan=-1,
 +
      start="",
 +
      width="",
 +
      outframe="LSRK",
 +
      veltype="radio",
 +
      restfreq=[],
 +
      interpolation="linear",
 +
      gridder="standard",
 +
      mosweight=True,
 +
      cfcache="",
 +
      computepastep=360.0,
 +
      rotatepastep=360.0,
 +
      pblimit=0.0001,
 +
      normtype="flatnoise",
 +
      deconvolver="mtmfs",
 +
      scales=[0, 6, 18],
 +
      nterms=2,
 +
      smallscalebias=0.6,
 +
      restoration=True,
 +
      restoringbeam=[],
 +
      pbcor=False,
 +
      outlierfile="",
 +
      weighting="briggs",
 +
      robust=0.5,
 +
      npixels=0,
 +
      uvtaper=[],
 +
      niter=20000,
 +
      gain=0.1,
 +
      threshold=0.0,
 +
      nsigma=0.0,
 +
      cycleniter=1000,
 +
      cyclefactor=1.0,
 +
      restart=True,
 +
      savemodel="modelcolumn",
 +
      calcres=True,
 +
      calcpsf=True,
 +
      parallel=False,
 +
      interactive=True)
 
</source>
 
</source>
This will produce plots similar to Figures 13 & 14.  As ever, you can cycle through the antennas by clicking the Next button. You should see leakages of between 5--15% in most cases. We can also display these in a single plot versus antenna index:
+
This {{tclean}} call will only fill the model column with the Stokes I model and ignore the polarized structure. You should not clean very deeply at this point. You want to be sure to capture as much of the source total flux density as possible, but not include low-level questionable features or sub-structure (ripples) that might be due to calibration or clean artifacts.  
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]
+
 
 +
After you are happy with the image:
 
<source lang="python">
 
<source lang="python">
 +
#In CASA
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')
+
gaincal(vis='3C75.ms', caltable='3C75.ScG0', field='', solint='inf', refant='ea10',
</source>
+
          spw='',minsnr=3.0, gaintype='G', parang=True, calmode='p')
Note that there are no solutions for antenna ea04 (see Figure 15); a bit of sleuthing will turn up that ea04 was missing for the scans on 3C84.
+
 
 +
bandpass(vis='3C75.ms', caltable='3C75.ScB0', field='', solint='inf', refant='ea10', minsnr=3.0, spw='',
 +
                parang = True, gaintable=['3C75.ScG0'],
 +
                interp=[])
  
If we want to rescue ea04, which otherwise seems OK, then we turn to our gain calibrator. If we plot data for field 1 versus ParAngle in {{plotms}} then we see that it has sufficient range (>60 deg) in parallactic angle so should be useable as a calibrator with unknown polarization.  We can make a new set of solutions:
+
applycal(vis='3C75.ms', gaintable=['3C75.ScG0','3C75.ScB0'], spw='', applymode='calflagstrict')
<source lang="python">
 
# In CASA
 
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',
 
      field='J1822-0938',spw='0:5~58',
 
      refant='ea21',poltype='Df+QU',solint='inf',combine='scan',
 
      gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                  '3c391_ctm_mosaic_10s_spw0.K0',
 
                  '3c391_ctm_mosaic_10s_spw0.B0',
 
                  '3c391_ctm_mosaic_10s_spw0.G1',
 
                  '3c391_ctm_mosaic_10s_spw0.Kcross'],
 
      gainfield=['','','','J1822-0938',''])
 
 
</source>
 
</source>
 +
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities which will now be used by {{tclean}}. The
 +
{{gaincal}} step will report a number of solutions with insufficient SNR. By default, with parameter ''applymode='calflag','' data with no good solutions will be flagged by {{applycal}}; in this case you will see it report the flagged fraction increasing to about 45%. This may or may not be a good thing. You can control the action of {{applycal}} in this regard by changing the value of parameter ''applymode''. The setting of ''applymode='calflagstrict' ''will be more stringent about flagging things without valid calibration, while ''applymode='calonly'  ''will calibrate those with solutions while passing through data without unchanged. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.
  
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.
+
Having applied these gain and bandpass solutions, we will once again image the target measurement set which we now expect to have better gain solutions and consequently a better image. We do this by invoking the {{tclean}} command once again.  
* ''poltype='Df+QU' '': Solve for the leakages using a calibrator with unknown polarization but with good parallactic angle coverage, and simultaneously for the source polarization (averaged over frequency).
 
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.
 
  
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]
 
We now plot this as we did before:
 
 
<source lang="python">
 
<source lang="python">
# In CASA
+
#In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')
+
tclean(vis='3C75.ms',
 +
      field="3C75",
 +
      spw="",timerange="",
 +
      uvrange="",antenna="",scan="",observation="",intent="",
 +
      datacolumn="corrected",
 +
      imagename="3C75_selfcal_1",
 +
      imsize=480,
 +
      cell="3.4arcsec",
 +
      phasecenter="",
 +
      stokes="I",
 +
      projection="SIN",
 +
      specmode="mfs",
 +
      reffreq="3.0GHz",
 +
      nchan=-1,
 +
      start="",
 +
      width="",
 +
      outframe="LSRK",
 +
      veltype="radio",
 +
      restfreq=[],
 +
      interpolation="linear",
 +
      gridder="standard",
 +
      mosweight=True,
 +
      cfcache="",
 +
      computepastep=360.0,
 +
      rotatepastep=360.0,
 +
      pblimit=0.0001,
 +
      normtype="flatnoise",
 +
      deconvolver="mtmfs",
 +
      scales=[0, 6, 18],
 +
      nterms=2,
 +
      smallscalebias=0.6,
 +
      restoration=True,
 +
      restoringbeam=[],
 +
      pbcor=False,
 +
      outlierfile="",
 +
      weighting="briggs",
 +
      robust=0.5,
 +
      npixels=0,
 +
      uvtaper=[],
 +
      niter=20000,
 +
      gain=0.1,
 +
      threshold=0.0,
 +
      nsigma=0.0,
 +
      cycleniter=1000,
 +
      cyclefactor=1.0,
 +
      restart=True,
 +
      savemodel="modelcolumn",
 +
      calcres=True,
 +
      calcpsf=True,
 +
      parallel=False,
 +
      interactive=True)
 
</source>
 
</source>
Comparison of this plot (see Figure 16) with that for the D1 caltable shows that we get nearly identical results, but now ea04 (index 3) is present!  That should give us some confidence in our leakage calibration as well.
 
  
==== Solving for the R-L polarization angle ====
+
Commonly, this self-cal procedure is applied multiple times. In Figures 17A & B you see a comparison of the Stokes I image before self-calibration and after two self-calibration steps.  
 
+
{|
Having calibrated the instrumental polarization, the total polarization is now correct, but the R-L phase still needs to be calibrated in order to obtain an accurate polarization position angle.  We use the same task, {{polcal}}, but this time set parameter ''poltype='Xf' '', which specifies a frequency-dependent (''f'') position angle (''X'') calibration, using the source J1331+3030 (a.k.a. 3C 286), whose position angle is known, having set this earlier using {{setjy}}. Note that we must correct for the leakages before determining the R-L phase, which we do by adding the calibration table made in the previous step ('''3c391_ctm_mosaic_10s_spw0.D2''') to the gain tables that are applied on-the-fly. Note that we are using the second D table we made as it included ea04:
+
| [[Image:3c75_initial_I_CASA5.4.1.png|thumb|Figure 17A: Stokes I image before self-calibration.]]
 +
| [[Image:3c75_2selfcal_I_CASA5.4.1.png|thumb|Figure 17B: Stokes I image after two rounds of self-calibration.]]
 +
|}
  
<source lang="python">
+
The number of iterations is determined by a combination of the data quality, the number of antennas in the array, the structure of the source, the extent to which the original self-calibration assumptions are valid, and the user's patience. With reference to the original self-calibration equation above, if the observed visibility data cannot be modeled well by this equation, no amount of self-calibration will help. A not-uncommon limitation for moderately high dynamic range imaging is that there may be ''baseline-based'' factors that modify the true visibility. If the corruptions to the true visibility cannot be modeled as antenna-based, as they are above, self-calibration won't help.
# In CASA
 
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',
 
      field='J1331+3030',combine='scan',
 
      refant='ea21',poltype='Xf',solint='inf',
 
      gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                  '3c391_ctm_mosaic_10s_spw0.K0',
 
                  '3c391_ctm_mosaic_10s_spw0.B0',
 
                  '3c391_ctm_mosaic_10s_spw0.G1',
 
                  '3c391_ctm_mosaic_10s_spw0.Kcross',
 
                  '3c391_ctm_mosaic_10s_spw0.D2'],
 
      gainfield=['','','','J1331+3030','',''])
 
</source>
 
  
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]
+
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, change something and try againHaving said that, here are several general comments or guidelines:
Note that, strictly speaking, there is no need to specify a reference antenna for poltype='Xf' (for circularly polarized receivers only) because the X solutions adjust the cross-hand phases for each antenna to match the given polarization angle of the modelHowever, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.
 
  
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using {{plotms}} (see Figure 17):
+
* Bookkeeping is important! Suppose one conducts 9 iterations of self-calibration. Will it be possible to remember one month later (or maybe even one week later!) which set of gain corrections and images are which? In the example above, the descriptor'' 'selfcal1' ''is attached to various files to help keep straight which is what. Successive iterations of self-cal could then be'' 'selfcal2' '','' 'selfcal3' '', etc.
<source lang="python">
 
# In CASA
 
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')
 
</source>
 
Because the Xf term captures the residual R-L phase on the reference antenna over the array, there is one value for all antennas. Also, as we took out the RL delays using the Kcross solution, these Xf variations only span about 6 degress across the spectral window.
 
  
At this point, you have all the necessary polarization calibration tables.
+
* Care is required in the setting of ''imagename''. If one has an image that already exists, CASA will continue cleaning it (if it can), which is almost certainly not what one wants during self-calibration. Rather, use a unique ''imagename'' for each pass of self-calibration.
  
=== Scaling the Amplitude Gains ===
+
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.
  
While we know the flux density of our primary calibrator (J1331+3030<math>\equiv</math>3C 286), the model assumed for the secondary calibrator (J1822-0938) was a point source of 1 Jy located at the phase center. While the secondary calibrator was chosen to be a point source (at least, over some limited range of ''uv''-distance; see [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist the VLA calibrator manual] for any ''u''-''v'' restrictions on your calibrator of choice at the observing frequency), its absolute flux density is unknown.  Being point-like, secondary calibrators typically vary on timescales of months to years, in some cases by up to 50--100%.  
+
* Be careful when making images and setting clean regions or masks; self-calibration assumes that the model is perfect. If one cleans a noise bump, self-calibration will quite happily try to adjust the gains so that the CORRECTED_DATA describe a source at the location of the noise bump. It is far better to exclude some feature of a source or a weak source from initial cleaning and conduct another round of self-calibration than to create an artificial source. If a real source is excluded from initial cleaning, it will continue to be present in subsequent iterations of self-calibration; if it's not a real source, one probably isn't interested in it anyway.
  
We use the primary (flux) calibrator to determine the system response to a source of known flux density and assume that the mean gain amplitudes for the primary calibrator are the same as those for the secondary calibrator. This allows us to find the true flux density of the secondary calibrator. To do this, we use the task {{fluxscale}}, which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.
+
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in {{gaincal}}). As discussed in the [http://adsabs.harvard.edu/abs/1989ASPC....6..287P High Dynamic Range Imaging] lecture, a phase error of 20 deg is as bad as an amplitude error of 10%.
  
<source lang="python">
+
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in {{gaincal}}) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in {{gaincal}}). Depending upon the frequency and configuration and fidelity of the model image, it can be quite reasonable to start with ''solint='30s' ''or'' solint='60s' ''and/or ''minsnr=3 (''or even lower). One might also want to consider specifying a uvrange, if, for example, the field has structure on large scales (small <math>u</math>-<math>v</math>) that is not well represented by the current image.
# In CASA
 
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',
 
                    caltable='3c391_ctm_mosaic_10s_spw0.G1',
 
                    fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1',
 
                    reference=['J1331+3030'],
 
                    transfer=['J1822-0938,J0319+4130'],
 
                    incremental=False)
 
</source>
 
* ''myscale = fluxscale(...) '': {{fluxscale}} returns a dictionary of results, which we capture in the variable '''myscale'''
 
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide {{fluxscale}} with the calibration table containing the amplitude gain solutions derived earlier.
 
* ''fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1' '': We specify the name of the new output table to be written, which will contain the properly-scaled amplitude gains.
 
* ''reference='J1331+3030' '': We specify the source with the known flux density.
 
* ''transfer=['J1822-0938,J0319+4130']'': We specify the sources whose amplitude gains are to be rescaled.
 
* ''incremental=False'': Make a new output fluxtable replacing caltable with rescaled transfer gains. If parameter ''incremental=True'' then the new table would be used in addition to caltable in subsequent applications.
 
  
Task {{fluxscale}} will print to the CASA logger the derived flux densities of all calibrator sources specified with the ''transfer'' parameter. These are also captured in the return variable from the task.  You should examine the output to ensure that it looks sensible. If the data set has more than one spectral window, depending upon where they are spaced and the spectrum of the source, it is possible to find quite different flux densities and spectral indexes for the secondary calibrators.  Example output would be
+
* The task {{applycal}} will flag data with no good calibration solutions. During the initial self-calibration steps, this flagging may be excessive. If so, one can restore the flags to the state right before running applycal by using the task '''[https://casa.nrao.edu/casadocs/latest/data-examination-and-editing/managing-flag-versions-flagmanager flagmanager]'''.
<pre style="background-color: #fffacd;">
 
CASA <99>: myscale['1']
 
  Out[99]:
 
{'0': {'fluxd': array([ 2.29600096,  0.        ,  0.        ,  0.        ]),
 
  'fluxdErr': array([ 0.00692024,  0.       ,  0.        ,  0.        ]),
 
  'numSol': array([ 46.,  0.,  0.,  0.])},
 
'fieldName': 'J1822-0938',
 
'fitFluxd': 0.0,
 
'fitFluxdErr': 0.0,
 
'fitRefFreq': 0.0,
 
'spidx': array([ 0.,  0.,  0.]),
 
'spidxerr': array([ 0.,  0.,  0.])}
 
  
CASA <100>: myscale['9']
+
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in {{plotms}}. The options in Axes tab allows one to select which column is to be plotted. If the MODEL agrees well with the CORRECTED_DATA, one can use shorter solint and/or higher minsnr values.
  Out[100]:
 
{'0': {'fluxd': array([ 13.66809981,  0.        ,  0.        ,  0.        ]),
 
  'fluxdErr': array([ 0.03883741,  0.        ,  0.        ,  0.        ]),
 
  'numSol': array([ 44.,  0.,  0.,  0.])},
 
'fieldName': 'J0319+4130',
 
'fitFluxd': 0.0,
 
'fitFluxdErr': 0.0,
 
'fitRefFreq': 0.0,
 
'spidx': array([ 0.,  0.,  0.]),
 
'spidxerr': array([ 0.,  0.,  0.])}
 
  
 +
* You should consider examining the solutions from {{gaincal}} by using {{plotcal}} in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not.  (However, because the phases are often plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)
  
</pre>
+
== Final Polarization Images ==
The indices above ('1' and '9') refer to the field number. You can also find the flux density values in the CASA logger:
 
<pre style="background-color: #fffacd;">
 
...
 
Found reference field(s): J1331+3030
 
Found transfer field(s): J1822-0938 J0319+4130
 
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)
 
Flux density for J0319+4130 in SpW=0 (freq=4.599e+09 Hz) is: 13.6681 +/- 0.0388374 (SNR = 351.931, N = 44)
 
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1
 
...
 
</pre>
 
  
Again, the VLA Calibrator Manual may be used to check whether the derived flux densities look sensible. Wildly different flux densities or flux densities with very high error bars should be treated with suspicion; in such cases you will have to figure out whether something has gone wrong.
+
At this point, satisfied with the results of self-calibration, it might be a good idea to recalculate the visibility weights since some additional flagging was performed. After this, we get right to full-polarization imaging. We also suspect that there is a bright source outside of the masked field causing some imaging artefacts due to not being cleaned. We thus set the parameter ''pbmask'' value to 0.0 in order to disable masking of areas beyond the primary beam.
  
We plot the rescaled amplitudes from this table:
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',
+
statwt(vis='3C75.ms', minsamp=8, datacolumn='corrected', flagbackup=True)
       correlation='R',coloraxis='baseline')
+
 
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',
+
tclean(vis='3C75.ms',
       correlation='L',coloraxis='baseline')
+
       field="3C75",
 +
      spw="",timerange="",
 +
      uvrange="",antenna="",scan="",observation="",intent="",
 +
      datacolumn="corrected",
 +
      imagename="3C75_final",
 +
      imsize=1024,
 +
      cell="3.4arcsec",
 +
      phasecenter="",
 +
      stokes="IQUV",
 +
      projection="SIN",
 +
      specmode="mfs",
 +
      reffreq="3.0GHz",
 +
      nchan=-1,
 +
      start="",
 +
      width="",
 +
      outframe="LSRK",
 +
      veltype="radio",
 +
      restfreq=[],
 +
      interpolation="linear",
 +
      gridder="standard",
 +
      mosweight=True,
 +
      cfcache="",
 +
      computepastep=360.0,
 +
      rotatepastep=360.0,
 +
      pblimit=-0.0001,
 +
      pbmask=0.0,
 +
      normtype="flatnoise",
 +
      deconvolver="mtmfs",
 +
      scales=[0, 6, 18],
 +
      nterms=2,
 +
      smallscalebias=0.6,
 +
      restoration=True,
 +
      restoringbeam=[],
 +
      pbcor=False,
 +
      outlierfile="",
 +
      weighting="briggs",
 +
      robust=0.5,
 +
      npixels=0,
 +
      uvtaper=[],
 +
      niter=20000,
 +
      gain=0.1,
 +
      threshold=0.0,
 +
      nsigma=0.0,
 +
      cycleniter=1000,
 +
      cyclefactor=1.0,
 +
      restart=True,
 +
      savemodel="modelcolumn",
 +
      calcres=True,
 +
      calcpsf=True,
 +
       parallel=False,
 +
      interactive=True)
 
</source>
 
</source>
You can see in Figures 18A and 18B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.
 
  
{|  
+
The final restored Stokes I,Q,U, and V images are shown in Figures 18A&ndash;D. Note that there is a star like pattern in the residuals which are artefacts most likely due to the multi-scale multi-term multi-frequency synthesis. You can try on your own to improve upon the shown images by re-imaging and choosing a different set of multi-scale parameters that better match the scales found in the extended structure of 3C 75. Another issue to point out is looking at the Stokes V image. We do not expect a significant amount of Stokes V emission from this object, the emission you are seeing in Stokes V is most likely an effect of incorrectly solving for polarization leakages in the primary beam. In the above calibration we have only addressed leakage between the two polarization referring to the phase center. The extended beam itself, however, shows leakage which manifests itself spatially. Thus the extended polarized emission we see in the Stokes Q and U images is not corrected for beam polarization during imaging. This, in turn, contains errors leading to polarization and de-polarization effects and causes changes to the polarization angle which effect increases the further away once gets from the beam center. In addition, the two polarization beams do not sit ontop of each other but are slightly offset, introducing a polarization squint. For correct and accurate polarization imaging, these two effects have to be taken into account. Imaging algorithms to address beam polarization are currently under development and will be discussed in this guide when they become available to the general user. 
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.4.0.png|200px|thumb|left|Figure 18A: post-fluxscale amp solutions, R pol]]
+
 
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.4.0.png|200px|thumb|center|Figure 18B: post-fluxscale amp solutions, L pol]]
+
{|
 +
| [[Image:3c75_final_I_CASA5.4.1.png|thumb|Figure 18A: Viewer panel of final restored Stokes I image.]]
 +
| [[Image:3c75_final_Q_CASA5.4.1.png|thumb|Figure 18B: Viewer panel of final restored Stokes Q image.]]
 +
| [[Image:3c75_final_U_CASA5.4.1.png|thumb|Figure 18C: Viewer panel of final restored Stokes U image.]]
 +
| [[Image:3c75_final_V_CASA5.4.1.png|thumb|Figure 18D: Viewer panel of final restored Stokes V image.]]
 
|}
 
|}
  
== Applying the Calibration ==
+
=== Spectral & Polarization Maps ===
 
 
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task {{applycal}}.  The measurement set  DATA column contains the original data. To apply the calibration we have derived, we specify the appropriate calibration tables, which are then applied to the DATA column, with the results being written in the CORRECTED_DATA column. If the dataset does not already have a CORRECTED_DATA scratch column, then one will be created in the first {{applycal}} run.
 
  
First, we apply the calibration to each individual calibrator, using the gain solutions derived on that calibrator alone to compute the CORRECTED_DATA. To do this, we iterate over the different calibrators, in each case specifying the source to be calibrated (using the ''field'' parameter).  The relevant function calls are given below, although as explained presently, the calls to {{applycal}} will differ slightly if you skipped the Polarization Calibration steps above.
+
If you want to obtain a reasonable map of the in-band spectral index, like the one shown in Fig. 19A, we can compute it with the task {{widebandpbcor}}.
 +
<source lang="python">
 +
widebandpbcor(vis='3C75.ms',imagename='3C75_final',nterms=2,action='calcalpha', threshold = '0.5mJy/beam')
 +
</source>
  
 +
For further study of polarization properties, you might want to convert the Stokes images into something more useful for scientific analysis. We will use the CASA to calculate polarization intensity (sqrt(Q^2 + U^2)/I) and polarization angle (0.5 arctan2 (U/Q)) maps from the final Stokes I,Q,U images. You can then look at those with the {{viewer}}. For example, Figure 19B shows the polarization intensity image. Since we haven't applied any mask the polarization angle image will also contain values for low S/N or noise values. 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',
 
        field='J1331+3030',
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                    '3c391_ctm_mosaic_10s_spw0.fluxscale1',
 
                    '3c391_ctm_mosaic_10s_spw0.K0',
 
                    '3c391_ctm_mosaic_10s_spw0.B0',
 
                    '3c391_ctm_mosaic_10s_spw0.Kcross',
 
                    '3c391_ctm_mosaic_10s_spw0.D2',
 
                    '3c391_ctm_mosaic_10s_spw0.X1'],
 
        gainfield=['','J1331+3030','','','','',''],
 
        interp=['','nearest','','','','',''],
 
        calwt=[False],
 
        parang=True)
 
 
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',
 
        field='J0319+4130',
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                    '3c391_ctm_mosaic_10s_spw0.fluxscale1',
 
                    '3c391_ctm_mosaic_10s_spw0.K0',
 
                    '3c391_ctm_mosaic_10s_spw0.B0',
 
                    '3c391_ctm_mosaic_10s_spw0.Kcross',
 
                    '3c391_ctm_mosaic_10s_spw0.D2',
 
                    '3c391_ctm_mosaic_10s_spw0.X1'],
 
        gainfield=['','J0319+4130','','','','',''],
 
        interp=['','nearest','','','','',''],
 
        calwt=[False],
 
        parang=True)
 
  
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',
+
# Obtain image for the polarization intensity
        field='J1822-0938',
+
immath(outfile='3C75_final.poli',mode='poli',imagename=['3C75_final.image.tt0'],sigma='0.0Jy/beam')
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
+
# Obtain image for the polarization angle
                    '3c391_ctm_mosaic_10s_spw0.fluxscale1',
+
immath(outfile='3C75_final.pola',mode='pola',imagename=['3C75_final.image.tt0'],sigma='0.0Jy/beam')
                    '3c391_ctm_mosaic_10s_spw0.K0',
 
                    '3c391_ctm_mosaic_10s_spw0.B0',
 
                    '3c391_ctm_mosaic_10s_spw0.Kcross',  
 
                    '3c391_ctm_mosaic_10s_spw0.D2',
 
                    '3c391_ctm_mosaic_10s_spw0.X1'],
 
        gainfield=['','J1822-0938','','','','',''],  
 
        interp=['','nearest','','','','',''],
 
        calwt=[False],
 
        parang=True)
 
 
</source>
 
</source>
  
* ''gaintable'' : We provide a Python list of the calibration tables to be applied. This list must contain the antenna position corrections (.antpos), the properly-scaled gain calibration for the amplitudes and phases (.fluxscale1) which were just made using {{fluxscale}}, the parallel-hand delays (.K0), the bandpass solutions (.B0), the cross-hand delays (.Kcross), the leakage calibration (.D2 (derived by our second solution)), and the R-L phase corrections (.X1).
+
{|
* ''gainfield, interp'' : To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), then for each calibrator source, we need to specify the particular subset of gain solutions to be applied. This requires use of the ''gainfield'' and ''interp'' parameters; these are both Python lists, and for the list item corresponding to the calibration table made by {{fluxscale}}, we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.
+
| [[Image:3c75_final_spix_CASA5.4.1.png|thumb|Figure 19A: Computed spectral index map.]]
* ''calwt=[False] '': At the time of writing, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. You can specify ''calwt'' on a per-table basis, here is set all to ''False''.
+
| [[Image:3c75_final_Ptot_CASA5.4.1.png|thumb|Figure 19B: Computed polarization intensity image.]]
* ''parang '': If polarization calibration has been performed, set parameter ''parang=True''. If the polarization calibration steps in the section above were skipped, the .Kcross, .D2 and .X1 tables will not exist.  In this case, you should leave out these tables from the ''gaintable'' list, and the corresponding sets of elements in the ''gainfield'' list each time you run {{applycal}} above; and set parameter ''parang=False''.
+
| [[Image:3c75_final_PAng_CASA5.4.2.png|thumb|Figure 19C: Computed polarized angles as vectors ontop of the Stokes I raster image plane.]]
 
+
|}
Finally, we apply the calibration to the target fields in the mosaic, linearly interpolating the gain solutions from the secondary calibrator, J1822-0938.  In this case however, we want to apply the amplitude and phase gains derived from the secondary calibrator, J1822-0938, since that is close to the target source on the sky and we assume that the gains applicable to the target source are very similar to those derived in the direction of the secondary calibrator.  Of course, this is not strictly true, since the gains on J1822-0938 were derived at a different time and in a different position on the sky from the target.  However, assuming that the calibrator was sufficiently close to the target, and the weather was sufficiently well-behaved, then this is a reasonable approximation and should get us a sufficiently good calibration that we can later use self-calibration to correct for the small inaccuracies thus introduced.
 
  
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.
+
If you want to visualize the polarization vectors ontop of the Stokes I image, we need to add a mask for the low noise values.  
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',
+
!cp -rif '3C75_final.poli' polimg
        field='2~8',
 
        gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',
 
                    '3c391_ctm_mosaic_10s_spw0.fluxscale1',
 
                    '3c391_ctm_mosaic_10s_spw0.K0',
 
                    '3c391_ctm_mosaic_10s_spw0.B0',
 
                    '3c391_ctm_mosaic_10s_spw0.Kcross',
 
                    '3c391_ctm_mosaic_10s_spw0.D2',
 
                    '3c391_ctm_mosaic_10s_spw0.X1'],
 
        gainfield=['','J1822-0938','','','','',''],
 
        interp=['','linear','','','','',''],
 
        calwt=[False],
 
        parang=True)
 
</source>
 
 
 
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''.
 
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.
 
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.
 
  
 +
imsubimage(imagename='3C75_final.image.tt0',outfile='3C75_final.Q.image',stokes='Q')
 +
imsubimage(imagename='3C75_final.image.tt0',outfile='3C75_final.U.image',stokes='U')
  
We should now have fully-calibrated visibilities in the CORRECTED_DATA column of the measurement set, and it is worthwhile pausing to inspect them to ensure that the calibration did what we expected it to. We make some standard plots (see Figures 19A through 19D):
+
subimPI='polimg'
<source lang="python">
+
ia.open(subimPI)
# In CASA
+
ia.calcmask(mask=subimPI+'>1e-4',name='mymask')
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='',
+
ia.done()
      timerange='08:02:00~08:17:00',antenna='',avgtime='60',
 
      xaxis='channel',yaxis='amp',ydatacolumn='corrected',
 
      coloraxis='corr',
 
      plotfile='plotms_3c391-fld0-corrected-amp.png')
 
  
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='',
+
ia.open('3C75_final.Q.image')
      timerange='08:02:00~08:17:00',antenna='',avgtime='60',
+
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])
      xaxis='channel',yaxis='phase',ydatacolumn='corrected',
+
ia.maskhandler('set','polithreshmask')
      plotrange=[-1,-1,-180,180],coloraxis='corr',
+
ia.done()
      plotfile='plotms_3c391-fld0-corrected-phase.png')
 
  
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',
+
ia.open('3C75_final.U.image')
      timerange='',antenna='',avgtime='60',
+
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])
      xaxis='channel',yaxis='amp',ydatacolumn='corrected',
+
ia.maskhandler('set','polithreshmask')
      plotfile='plotms_3c391-fld1-corrected-amp.png')
+
ia.done()
  
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',
+
immath(imagename=['3C75_final.Q.image', '3C75_final.U.image'], mode='pola', outfile='3C75_final.pola.masked')
      timerange='',antenna='',avgtime='60',
 
      xaxis='channel',yaxis='phase',ydatacolumn='corrected',
 
      plotrange=[-1,-1,-180,180],coloraxis='corr',
 
      plotfile='plotms_3c391-fld1-corrected-phase.png')
 
 
</source>
 
</source>
For 3C286 (leftmost plots) we see the polarized signal in the cross-hands. There is no sign of bad data remaining.
+
These steps take the polarized intensity image calculated above (Figure 19B) and create a mask using a polarization fraction threshold of 1e-4 (0.01% linear polarization fraction). This mask is then applied to the Q and U images from the image cube that was generated above. Then a new polarization angle image is calculated from the Q & U image planes, applying the mask based on polarization fraction. Finally, we can load the Stokes I as raster image into the CASA {{viewer}} and add the polarization angle as vectors. Figure 19C shows the resulting image. One can clearly see that the linear polarization angle follows perpendicular to the extended structure. This indicates that the magnetic field lines are oriented along the extended structure, perpendicular to the linear polarization angles.
 
 
{|
 
| [[Image:plotms_3c391-fld0-corrected-amp_4.6.png|thumb|Figure 19A: amp vs channel for 3C286 RR,RL,LR,LL]]
 
| [[Image:plotms_3c391-fld0-corrected-phase_5.0.png|thumb|Figure 19B: phase vs channel for 3C286 RR,RL,LR,LL]]
 
| [[Image:plotms_3c391-fld1-corrected-amp_5.0.png|thumb|Figure 19C: amp vs channel for J1822-0938 RR,LL]]
 
| [[Image:plotms_3c391-fld1-corrected-phase_5.0.png|thumb|Figure 19D: phase vs channel for J1822-0938 RR,LL]]
 
|}
 
  
Inspecting the data at this stage may well show up previously-unnoticed bad data.  Plotting the '''corrected''' amplitude against UV distance or against time is a good way to find such issues.  If you find bad data, you can remove them via interactive flagging in {{plotms}} or via manual flagging in {{flagdata}} once you have identified the offending antennas/baselines/channels/times.  When you are happy that all data (particularly on your target source) look good, you may proceed.
+
=== Rotation Measures ===
  
Now that the calibration has been applied to the target data we can split off the science targets, creating a new, calibrated measurement set containing all the target fields.
+
The plane of polarization of light is rotated by the magnetic fields present in the intervening plasma. The total rotation
 +
to the plane of polarization of light between the source and the user is called Faraday Rotation. Prior to the wide bandwidth
 +
capabilities, these rotation measures were computed by fitting a line to the polarization position angle as a function of the
 +
square of the wavelength of measurement. The slope of the resulting fit was deemed to be the RM of the source while
 +
the intercept would give the true polarization position angle of the source. With the wide bandwidths, it is now possible to
 +
determine the rotation measure of the source using the naive fitting approach by making images per spectral window in IQUV
 +
and fitting the data (polarization position angle vs lambda^2) with a line.  
  
 +
To produce an image cube with 8 channels, each image is using 128 MHz of bandwidth, we call {{tclean}} with the following parameters. Here we take advantage of the imaging mask we generated for the final image above, so we don't need to do an interactive clean.
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',
+
tclean(vis='3C75.ms',
      datacolumn='corrected',field='2~8')
+
      field="3C75",
 +
      spw="",timerange="",
 +
      uvrange="",antenna="",scan="",observation="",intent="",
 +
      datacolumn="corrected",
 +
      imagename="3C75_chan8",
 +
      imsize=1024,
 +
      cell="3.4arcsec",
 +
      phasecenter="",
 +
      stokes="IQUV",
 +
      projection="SIN",
 +
      specmode="cube",
 +
      reffreq="",
 +
      nchan=-1,
 +
      start="",
 +
      width=64,
 +
      outframe="LSRK",
 +
      veltype="radio",
 +
      restfreq=[],
 +
      interpolation="linear",
 +
      gridder="standard",
 +
      mosweight=True,
 +
      cfcache="",
 +
      computepastep=360.0,
 +
      rotatepastep=360.0,
 +
      pblimit=-0.0001,
 +
      pbmask=0.0,
 +
      mask='3C75_final.mask',
 +
      normtype="flatnoise",
 +
      deconvolver="multiscale",
 +
      scales=[0, 6, 18],
 +
      nterms=1,
 +
      smallscalebias=0.6,
 +
      restoration=True,
 +
      restoringbeam=[],
 +
      pbcor=False,
 +
      outlierfile="",
 +
      weighting="briggs",
 +
      robust=0.5,
 +
      npixels=0,
 +
      uvtaper=[],
 +
      niter=20000,
 +
      gain=0.1,
 +
      threshold=0.0,
 +
      nsigma=0.0,
 +
      cycleniter=1000,
 +
      cyclefactor=1.0,
 +
      restart=True,
 +
      savemodel="none",
 +
      calcres=True,
 +
      calcpsf=True,
 +
      parallel=False,
 +
      interactive=False)
 
</source>
 
</source>
  
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.
+
Now we use the CASA toolkit to access data for four pixels in the image cube to visualize and fit the rotation measure. The script is also available here: [[File:linregfit.py]].
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using {{applycal}}.
 
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.
 
 
 
Prior to imaging, it is a good idea to run the '''[https://casa.nrao.edu/casadocs/latest/global-task-list/task_statwt/about statwt]''' task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set.  Running '''[https://casa.nrao.edu/casadocs/latest/global-task-list/task_statwt/about statwt]''' will remove the effects of relative noise scatter that may have been introduced from flagging uneven bits in the visibility data between the channels and times. We will run this task here on the newly calibrated and split-out data set before moving on to imaging.
 
 
 
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')
+
import matplotlib.pyplot as plt
</source>
+
ia.open('3C75_chan8.image')
  
= Imaging =  
+
tt = ia.getchunk()
 +
nu = np.linspace(2.551e9,3.319e9,num=8)
 +
c = 2.99792458e8
  
Now that we have split off the target data into a separate measurement set with all the calibration applied, it's time to make an image.  Recall that the visibility data and the sky brightness distribution (a.k.a. image) are Fourier transform pairs.
+
Q1 = tt[488,531,1,:8]
 +
U1 = tt[488,531,2,:8]
 +
Q2 = tt[494,511,1,:8]
 +
U2 = tt[494,511,2,:8]
 +
Q3 = tt[529,551,1,:8]
 +
U3 = tt[529,551,2,:8]
 +
Q4 = tt[525,534,1,:8]
 +
U4 = tt[525,534,2,:8]
  
<math>
+
chi1 = 0.5*np.arctan2(U1,Q1)
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv
+
chi2 = 0.5*np.arctan2(U2,Q2)
</math>
+
chi3 = 0.5*np.arctan2(U3,Q3)
 +
chi4 = 0.5*np.arctan2(U4,Q4)
  
The <math>u</math> and <math>v</math> coordinates are the baselines measured in units of the observing wavelength, while the <math>l</math> and <math>m</math> coordinates are the direction cosines on the sky. For generality, the sky coordinates are written in terms of direction cosines, but for most VLA (and ALMA) observations they can be related simply to the right ascension (<math>l</math>) and declination (<math>m</math>).  Also recall that this equation is valid only if the <math>w</math> coordinate of the baselines can be neglected. This assumption is almost always true at high frequencies and smaller VLA configurations (such as the 4.6 GHz D-configuration observations here). The <math>w</math> coordinate cannot be neglected at lower frequencies and larger configurations (e.g., 0.33 GHz, A-configuration observations).  This expression also neglects other factors, such as the shape of the primary beam.  For more information on imaging, see the [https://casa.nrao.edu/casadocs/latest/synthesis-imaging Synthesis Imaging] section of the CASA documentation.
+
#locate the values that are nan and delete these indices from nu
 +
indx1=np.argwhere(chi1==0)
 +
indx2=np.argwhere(chi2==0)
 +
indx3=np.argwhere(chi3==0)
 +
indx4=np.argwhere(chi4==0)
  
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 21: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]
+
nu1=np.delete(nu,indx1)
CASA has a task {{tclean}} which both Fourier transforms the data and deconvolves the resulting image.  For the purposes of this tutorial, we will make a mosaic clean image in Stokes I only; polarimetric imaging will be addressed in an upcoming new CASAguide.  We will use a multi-scale cleaning algorithm because the supernova remnant contains both diffuse, extended structure on large spatial scales and finer filamentary structure on smaller scales.  This approach will do a better job of modeling the image than the classic clean delta function.  For broader examples of many {{tclean}} options, please see the [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Imaging_VLA_Data_in_CASA Topical Guide for Imaging VLA Data].
+
lam1 = c/nu1
 +
lamsq1 = lam1*lam1
  
== Multi-scale Mosaic Clean ==
+
nu2=np.delete(nu,indx2)
 +
lam2 = c/nu2
 +
lamsq2 = lam2*lam2
  
It is important to have an idea of what values to use for the image pixel (cell) size and the overall size of the image. Setting the appropriate pixel size for imaging depends upon basic optics aspects of interferometry.  Using {{plotms}} to look at the newly-calibrated, target-only data set:
+
nu3=np.delete(nu,indx3)
<source lang="python">
+
lam3 = c/nu3
# In CASA
+
lamsq3 = lam3*lam3
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',
 
      ydatacolumn='data', field='0',avgtime='30',correlation='RR',
 
      plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)
 
</source>
 
You should obtain a plot similar to Figure 21 with the (calibrated) visibility amplitude as a function of <math>u</math>-<math>v</math> distance.
 
The maximum baseline is about 16,000 wavelengths, i.e., an angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>).  The most effective cleaning occurs with 3-5 pixels across the synthesized beam.  For example, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. 
 
  
The supernova remnant itself is known to have a diameter of order 9 arcminutes, corresponding to about 216 pixels for the chosen cell size.  The mosaic was set up with 7 fields, 1 centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam.  For the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), you do not have to fit the mosaic inside the inner quarter of the total image in order to prevent image artifacts arising from aliasing, we just want to have a bit of padding around the outside. Although CASA has the feature that its Fourier transform engine (FFTW) does ''not'' require a strict power of 2 for the number of linear pixels in a given image axis, it is somewhat more efficient if the number of pixels on a side is a composite number divisible by ''any pair'' of 2 and 3 and/or 5.  Because {{tclean}} internally applies a padding of 1.2 (=3x2/5) choose 480, which is 2<sup>5</sup> &times; 3 &times; 5 (so 480 &times; 1.2 = 576 = 2<sup>6</sup> &times; 3<sup>2</sup>).  We therefore set ''imsize=[480,480]'' and our mosaic fits comfortably inside the image.
+
nu4=np.delete(nu,indx4)
 +
lam4 = c/nu4
 +
lamsq4 = lam4*lam4
  
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:
+
#drop the zero values
<source lang="python">
+
chi1=np.delete(chi1,indx1)
# In CASA
+
chi2=np.delete(chi2,indx2)
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',
+
chi3=np.delete(chi3,indx3)
      field='',spw='',
+
chi4=np.delete(chi4,indx4)
      specmode='mfs',
 
      niter=20000,
 
      gain=0.1, threshold='1.0mJy',
 
      gridder='mosaic',
 
      deconvolver='multiscale',
 
      scales=[0, 6, 18, 54], smallscalebias=0.9,
 
      interactive=True,
 
      imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],
 
      stokes='I',
 
      weighting='briggs',robust=0.5,
 
      pbcor=False,
 
      savemodel='modelcolumn')
 
</source>
 
  
Task {{tclean}} is powerful with many inputs and a certain amount of experimentation likely is required.
+
fit1 = np.polyfit(lamsq1,chi1,1)
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 22: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]
+
fit_fn1 = np.poly1d(fit1)
* ''vis='3c391_ctm_mosaic_spw0.ms' '': this split MS contains our 7-pt mosaic fields, now indexed as 0-6. Field 0 is the central field of the mosaic (you can use {{listobs}} to verify this).
+
slope1 = fit1[0]
* ''imagename='3c391_ctm_spw0_I' '': our output images will all start with this, e.g., 3c391_ctm_spw0_I.image
+
intercept1 = fit1[1]
* ''specmode='mfs' '': Use multi-frequency synthesis imaging. The fractional bandwidth of these data is non-zero (128 MHz at a central frequency of 4.6 GHz).  Recall that the <math>u</math> and <math>v</math> coordinates are defined as the baseline coordinates, measured in wavelengths.  Thus, slight changes in the frequency from channel to channel result in slight changes in <math>u</math> and <math>v</math>.  There is a concomitant improvement in <math>u</math>-<math>v</math> coverage if the visibility data from the multiple spectral channels are gridded separately onto the <math>u</math>-<math>v</math> plane, as opposed to treating all spectral channels as having the same frequency.
+
fit2 = np.polyfit(lamsq2,chi2,1)
* ''niter=20000,gain=0.1,threshold='1.0mJy' '': Recall that the gain is the amount by which a clean component is subtracted during the cleaning process.  Parameters ''niter'' and ''threshold'' are (coupled) means of determining when to stop the cleaning process, with ''niter'' specifying to find and subtract that many clean components while ''threshold'' specifies a minimum flux density threshold a clean component can have before {{tclean}} stops.  See also ''interactive'' below.  Imaging is an iterative process, and to set the threshold and number of iterations, it is usually wise to clean interactively in the first instance, stopping when spurious emission from sidelobes (arising from gain errors) dominates the residual emission in the field.  Here, we have used our experience in interactive mode to set a threshold level based on the rms noise in the resulting image.  The number of iterations should then be set high enough to reach this threshold.
+
fit_fn2 = np.poly1d(fit2)
* ''gridder='mosaic' '': The data consist of a 7-pointing mosaic, since the supernova remnant fills almost the full primary beam at 4.6 GHz.  A mosaic combines the data from all of the fields, with imaging and deconvolution being done jointly on all 7 fields.  A mosaic both helps compensate for the shape of the primary beam and reduces the amount of large (angular) scale structure that is resolved out by the interferometer.
+
slope2 = fit2[0]
* ''interactive=True '': Very often, particularly when one is exploring how a source appears for the first time, it can be valuable to interact with the cleaning process.  If True, ''interactive'' causes a '''[https://casa.nrao.edu/casadocs/latest/global-task-list/task_viewer/about viewer]''' window to appear.  One can then set clean regions, restricting where {{tclean}} searches for clean components, as well as monitor the cleaning process.  A standard procedure is to set a large value for ''niter'', and stop the cleaning when it visually appears to be approaching the noise level.  This procedure also allows one to change the cleaning region, in cases when low-level intensity becomes visible as the cleaning process proceeds. 
+
intercept2 = fit2[1]
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one value is specified, the same value is used in both directions.
+
fit3 = np.polyfit(lamsq3,chi3,1)
* ''stokes='I' '': A single image will be made for total intensity I.
+
fit_fn3 = np.poly1d(fit3)
* ''deconvolver='multiscale', scales=[0, 6, 18, 54], smallscalebias=0.9 '':  The settings for ''multiscale'' are in units of pixels, with 0 pixels equivalent to the traditional delta-function clean.  The scales here are chosen to provide delta functions and then three logarithmically scaled sizes to fit to the data.  The first scale (6 pixels) is chosen to be comparable to the size of the synthesized beam.  The ''smallscalebias'' attempts to balance the weight given to larger scales, which often have more flux density, and the smaller scales, which often are brighter.  Considerable experimentation is likely to be necessary; one of the authors of this document found that it was useful to clean several rounds with this setting, change to ''multiscale=[]'' and remove much of the smaller scale structure, then return to this setting.
+
slope3 = fit3[0]
* ''weighting='briggs',robust=0.5 '': 3C391 has diffuse, extended emission that is (at least partially) resolved out by the interferometer owing to a lack of short spacings.  A naturally-weighted image would show large-scale patchiness in the noise.  In order to suppress this effect, Briggs weighting is used (intermediate between natural and uniform weighting), with a default robust factor of 0.5 (which corresponds to something between natural and uniform weighting).
+
intercept3 = fit3[1]
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).* ''savemodel='modelcolumn' '': We recommend here the use of a physical MODEL_DATA scratch column for complicated gridders such as 'mosaic' (unlike the calibration steps, above).  This will save some time, as it can be faster in the case of complicated gridding to read data from disk instead of doing all of the computations on-the-fly. However, this has the unfortunate side effect of increasing the size of the ms on disk.
+
fit4 = np.polyfit(lamsq4,chi4,1)
 +
fit_fn4 = np.poly1d(fit4)
 +
slope4 = fit4[0]
 +
intercept4 = fit4[1]
  
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 23: After the first 500 iterations of multi-scale clean]]
+
plt.figure(1)
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When {{tclean}} runs in interactive mode, a '''[https://casa.nrao.edu/casadocs/latest/global-task-list/task_viewer/about viewer]''' window will pop up as shown in Figure 22. To get a more detailed view of the central regions containing the emission, zoom in by first left clicking on the zoom button (leftmost button in third row) and tracing out a rectangle with the left mouse button and double-clicking inside the zoom box you just made.  Play with the color scale to bring out the emission better, by holding down the middle mouse button and moving it around.  To create a clean box (a region within which components may be found), hold down the right mouse button and trace out a rectangle around the source, then double-click inside that rectangle to set it as a box.  Note that the clean box must turn white for it to be registered; if the box is not white, it has not been set!  Alternatively, you can trace out a more custom shape to better enclose the irregular outline of the supernova remnant.  To do that, right-click on the closed polygonal icon.  Then trace out a shape by right-clicking where you want the corners of that shape.  Once you have come full circle, the shape will be traced out in green, with small squares at the corners. Double-click inside this region and the green outline will turn white. You have now set the clean region. If you have made a mistake with your clean box, click on the Erase button, trace out a rectangle around your erroneous region, and double-click inside that rectangle.  You can also set multiple clean regions.
+
plt.title('Overall Title')
 +
plt.subplot(221)
 +
plt.title('Point 1: (488,531)')
 +
plt.xlabel(r'$\lambda^{2}$')
 +
plt.ylabel(r'$\chi1$')
 +
plt.scatter(lamsq1,chi1,color='r')
 +
plt.plot(lamsq1,fit_fn1(lamsq1),'r--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope1,intercept1))
 +
plt.legend(loc=2)
  
At any stage in the cleaning, you can adjust the number of iterations that {{tclean}} will do before returning to the GUI. By default this is set to 100 (see the iterations field in mid-upper left of panel). You probably want to set this to a high number for this mosaic due to the complicated structure, values from 1000 to 5000 later on seem to work. Note that this will override the ''niter'' that was set when you started the clean task. {{tclean}} will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).
+
plt.subplot(222)
 +
plt.title('Point 2: (494,511)')
 +
plt.xlabel(r'$\lambda^{2}$')
 +
plt.ylabel(r'$\chi2$')
 +
plt.scatter(lamsq2,chi2,color='b')
 +
plt.plot(lamsq2,fit_fn2(lamsq2),'b--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope2,intercept2))
 +
plt.legend(loc=1)
  
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 24: Interactive residuals after about 14000 iterations of multi-scale clean]]
+
plt.subplot(223)
When you are happy with the clean regions, press the green circular arrow button on the far right to continue deconvolution. After completing a cycle, a revised image will come up. As the brightest points are removed from the image (cleaned off), fainter emission may show up.  You can adjust the clean boxes each cycle, to enclose all real emission. After many cycles, when only noise is left, you can hit the red-and-white stop-sign icon to stop cleaning. Figure 23 shows the interactive viewer panel later in the process, after cleaning 500 iterations. We have used the polygon tool to add to the clean region, drawing around emission that shows up in the residual image outside of the original clean region. After about 14000 iterations (Figure 24) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting {{tclean}} with different ''multiscale=[...]'' choices can help also.
+
plt.title('Point 3: (529,551)')
 +
plt.xlabel(r'$\lambda^{2}$')
 +
plt.ylabel(r'$\chi3$')
 +
plt.scatter(lamsq3,chi3,color='g')
 +
plt.plot(lamsq3,fit_fn3(lamsq3),'g--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope3,intercept3))
 +
plt.legend(loc=3)
  
Task {{tclean}} will make several output files, all named with the prefix given as ''imagename''. These include:
+
plt.subplot(224)
* ''.image'': final restored image, with the clean components convolved with a restoring beam and added to the remaining residuals at the end of the imaging process
+
plt.title('Point 4: (525,534)')
* ''.pb'': effective response of the telescope (the primary beam)
+
plt.xlabel(r'$\lambda^{2}$')
* ''.mask'': areas where {{tclean}} has been allowed to search for emission
+
plt.ylabel(r'$\chi4$')
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set
+
plt.scatter(lamsq4,chi4,color='m')
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process
+
plt.plot(lamsq4,fit_fn4(lamsq4),'m--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope4,intercept4))
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply
+
plt.legend(loc=1)
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)
+
plt.tight_layout()
* ''.sumwt'': a single pixel image containing sum of weights per plane
 
  
[[Image:3c391-viewer-multiscale-final_CASA5.4.0.jpeg|thumb|Figure 25: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]
+
ia.close()
 +
</source>
  
After the imaging and deconvolution process has finished, you can use the '''[https://casa.nrao.edu/casadocs/latest/image-cube-visualization/viewer-basics viewer]''' to look at your image.
+
The resulting plots are shown in Figure 20A. There exists a CASA task ''rmfit'' which does this basic
<source lang="python">
+
fitting for you while taking into account the n \pi ambiguity (refer to [http://adsabs.harvard.edu/full/1986A%26A...156..234L] for more info).
 +
The fits using ''rmfit'' for our case of 3C75 by making images per spectral window is shown in Figure 20B. In this case, we set the maximum acceptable position angle error to 20 degrees. If larger, then no rotation measures are calculated.
 +
 +
<source lang='python'>
 
# In CASA
 
# In CASA
viewer('3c391_ctm_spw0_multiscale.image')
+
rmfit('3C75_chan8.image',rm='3C75_chan8_rm.image',rmerr='3C75_chan8_rm.image.err',maxpaerr=0.35)
</source>
+
</source>  
You can adjust the color scale and zoom in to a selected region by assigning mouse buttons to the icons immediately above the image (hover over the icons to get a description of what they do). Also, using the wrench panel to change Display Options will be helpful here. We chose the Hot Metal 1 colormap and set the Scaling Power Cycles to -1 to better emphasize the faint emission and compare to the noise (Figure 25).
+
 
 +
{|
 +
| [[Image:3C75_linred_att1.png|thumb|Figure 20A: Rotation measures extracted for 4 pixels from an 8 channel image cube of 3C75.]]
 +
| [[Image:3C75_rmfit_8chan.png|thumb|Figure 20B: RMFIT rotation measure image generated from 8 channel image cube.]]
 +
|}
 +
 
 +
The ''rmfit'' task has many more options; for example, you are able to provide a foreground rotation measure to subtract. For more information have a look at [https://casa.nrao.edu/casadocs/casa-5.4.0/global-task-list/task_rmfit/about].
 +
Now we can compare the rotation measures extracted for the 4 pixels from the 8 channel image cube with the values derived in the ''rmfit'' for the same pixels. In most cases the values are more or less comparable.
 +
 
 +
{| class="wikitable"
 +
|-
 +
! Point
 +
! RM Lin. Fit.
 +
! RM RMFIT
 +
|-
 +
| 1
 +
| 22.86
 +
| 22.54
 +
|-
 +
| 2
 +
| -49.74
 +
| -52.78
 +
|-
 +
| 3
 +
| -9.28
 +
| -12.40
 +
|-
 +
| 4
 +
| -31.11
 +
| -40.10
 +
|}
 +
 
 +
As our source is rather bright, we can derive an IQUV image not just per spectral window but rather per channel. To achieve this you can change the above
 +
{{tclean}} parameter width from 64 to 1. Note when imaging each channel, the edge channels are flagged which results in the PSF being blank for [C0:P0] [C0:P1] [C0:P2] [C0:P3] [C1:P0] and the first few images also being blank. Also, don't forget to change the imagename parameter when re-running {{tclean}}. Following the same steps as for the 8 channel image cube, we obtain the results shown in Figure 21 where again the polarization position angle
 +
as a function of lambda square is shown together with the ''rmfit'' image. We can clearly see that the source exhibits complex structure beyond a simple linear fit (like the one we performed earlier).
 +
This suggests that deriving a single RM would be an oversimplification. We should ideally perform RM Synthesis (https://arxiv.org/pdf/astro-ph/0507349.pdf).
 +
At this point in time CASA does not have an RM synthesis task.
  
The {{tclean}} task naturally operates in a flat noise image, i.e., an image where the effective weighting across the mosaic field of view is set so that the noise is constant.  This is so that the clean threshold has a uniform meaning for the stopping criterion and that the image fed into the minor cycles has uniform noise levels.  However, this means that the image does not take into account the primary beam fall-off in the edges and interstices of the mosaic.  We could have set parameter ''pbcor=True'' in {{tclean}}, but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image.  Therefore, we use {{impbcor}} to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:
 
<source lang="python">
 
# In CASA
 
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',
 
        outfile='3c391_ctm_spw0_multiscale.pbcorimage')
 
</source>
 
  
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.
+
{|
 +
| [[Image:3C75_channelcube_linereg1.png|thumb|Figure 21A: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75.]]
 +
| [[Image:3C75_rmfit_512chan.png|thumb|Figure 21B: RMFIT rotation measure image generated from 512 channel image cube.]]
 +
|}
  
== Image Analysis ==
+
<!-- == Image Analysis ==
  
 
The three most basic analyses are to determine the peak brightness, the flux density, and the image noise level.  These are useful measures of how well the imaging efforts are in approaching the thermal noise limit or in reproducing what is already known about a source.  Additional discussion of image analysis and manipulation, including the combination of multiple images, mathematical operations on images, and much more can be found in the [https://casa.nrao.edu/casadocs/latest/image-analysis Image Analysis] section of the CASA documentation.
 
The three most basic analyses are to determine the peak brightness, the flux density, and the image noise level.  These are useful measures of how well the imaging efforts are in approaching the thermal noise limit or in reproducing what is already known about a source.  Additional discussion of image analysis and manipulation, including the combination of multiple images, mathematical operations on images, and much more can be found in the [https://casa.nrao.edu/casadocs/latest/image-analysis Image Analysis] section of the CASA documentation.
Line 1,282: Line 1,566:
 
The most straightforward statistic is the peak brightness, which is determined by {{imstat}}.
 
The most straightforward statistic is the peak brightness, which is determined by {{imstat}}.
 
<source lang="python">
 
<source lang="python">
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')
+
mystat = imstat(imagename='3C75_initial.image.tt0')
 
</source>
 
</source>
 
This task returns a Python dictionary which we capture in the variable ''mystat''.
 
This task returns a Python dictionary which we capture in the variable ''mystat''.
Line 1,292: Line 1,576:
 
   Out[4]:  
 
   Out[4]:  
 
{'blc': array([0, 0, 0, 0], dtype=int32),
 
{'blc': array([0, 0, 0, 0], dtype=int32),
  'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',
+
  'blcf': '02:58:37.309, +05.47.28.628, I, 3e+09Hz',
'flux': array([ 9.78121725]),
+
  'max': array([ 0.14971776]),
  'max': array([ 0.15670438]),
+
  'maxpos': array([257, 279,  0,  0], dtype=int32),
  'maxpos': array([288, 256,  0,  0], dtype=int32),
+
  'maxposf': '02:57:38.755, +06.03.17.399, I, 3e+09Hz',
  'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',
+
  'mean': array([ 0.00016331]),
  'mean': array([ 0.00387879]),
+
  'medabsdevmed': array([ 1.74164962e-05]),
  'medabsdevmed': array([ 0.00120803]),
+
  'median': array([ 8.04986788e-09]),
  'median': array([ 0.00038406]),
+
  'min': array([-0.01785131]),
  'min': array([-0.00684072]),
+
  'minpos': array([258, 2781,  0], dtype=int32),
  'minpos': array([237, 4140,  0], dtype=int32),
+
  'minposf': '02:57:38.527, +06.03.13.999, Q, 3e+09Hz',
  'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',
+
  'npts': array([ 921600.]),
  'npts': array([ 116013.]),
+
  'q1': array([ -1.69758441e-05]),
  'q1': array([-0.00064426]),
+
  'q3': array([ 1.78917744e-05]),
  'q3': array([ 0.00203547]),
+
  'quartile': array([ 3.48676185e-05]),
  'quartile': array([ 0.00267972]),
+
  'rms': array([ 0.0031646]),
  'rms': array([ 0.01261286]),
+
  'sigma': array([ 0.00316039]),
  'sigma': array([ 0.01200169]),
+
  'sum': array([ 150.50313612]),
  'sum': array([ 449.99001048]),
+
  'sumsq': array([ 9.22954767]),
  'sumsq': array([ 18.45584197]),
+
  'trc': array([479, 479,  3,  0], dtype=int32),
  'trc': array([479, 479,  0,  0], dtype=int32),
+
  'trcf': '02:56:48.133, +06.14.37.233, V, 3e+09Hz'}
  'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}
+
 
  
 
CASA <5>: mystat['max'][0]
 
CASA <5>: mystat['max'][0]
   Out[5]: 0.156704381108284
+
   Out[5]: 0.14971776306629181
 
</pre>
 
</pre>
and so the peak flux density is 0.157 Jy/beam.
+
and so the peak flux density is 0.150 Jy/beam.
  
[[Image:3c391-viewer-final-polygon_CASA5.4.0.jpeg|thumb|right|Figure 26: viewer polygon region drawing for on-source statistics]]
 
[[Image:3c391-viewer-polygon-forrms_CASA5.4.0.jpeg|thumb|right|Figure 27: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]
 
 
The other two statistics require slightly more care.  The flux density of a source is determined by integrating its brightness or intensity over some solid angle, i.e.,  
 
The other two statistics require slightly more care.  The flux density of a source is determined by integrating its brightness or intensity over some solid angle, i.e.,  
  
Line 1,329: Line 1,611:
 
where <math>I</math> is the intensity (measured in units of Jy/beam), <math>\Omega</math> is the solid angle of the source (e.g., number of synthesized beams), and <math>S</math> is the flux density (measured in units of Jy).  In general, if the noise is well-behaved in the image, when averaged over a reasonable solid angle, the noise contribution should approach 0 Jy.  If that is the case, then the flux density of the source is also reported by {{imstat}}.  However, there are many cases for which a noise contribution of 0 Jy may not be a safe assumption.  If the source is in a complicated region (e.g., a star formation region, the Galactic center, near the edge of a galaxy), a better estimate of the source's flux density will be obtained by limiting carefully the solid angle over which the integration is performed.
 
where <math>I</math> is the intensity (measured in units of Jy/beam), <math>\Omega</math> is the solid angle of the source (e.g., number of synthesized beams), and <math>S</math> is the flux density (measured in units of Jy).  In general, if the noise is well-behaved in the image, when averaged over a reasonable solid angle, the noise contribution should approach 0 Jy.  If that is the case, then the flux density of the source is also reported by {{imstat}}.  However, there are many cases for which a noise contribution of 0 Jy may not be a safe assumption.  If the source is in a complicated region (e.g., a star formation region, the Galactic center, near the edge of a galaxy), a better estimate of the source's flux density will be obtained by limiting carefully the solid angle over which the integration is performed.
  
Open '''[https://casa.nrao.edu/casadocs/latest/image-cube-visualization/viewer-basics viewer]''' and use it to display the corrected image (Figure 26).  For this analysis, it is better to use the version of the viewer that is run from the OS command line rather than the CASA command line.  You can open this from inside CASA using '!':
+
Open '''[https://casa.nrao.edu/casadocs/latest/image-cube-visualization/viewer-basics viewer]''' and use it to display the corrected image (Figure 18).  For this analysis, it is better to use the version of the viewer that is run from the OS command line rather than the CASA command line.  You can open this from inside CASA using '!':
 
<source lang="python">
 
<source lang="python">
 
# In CASA
 
# In CASA
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &
+
!casaviewer '3C75_final.image.tt0' &
 
</source>
 
</source>
One can choose the function assigned to each mouse button; after zooming into the desired view, assign polygon region to a desired mouse button (e.g., left button) by selecting the polygon tool [[File:Polygon_btn.png]] to create the polygonal region as shown in Figure 26 with the desired mouse button.  
+
One can choose the function assigned to each mouse button; after zooming into the desired view, assign polygon region to a desired mouse button (e.g., left button) by selecting the polygon tool [[File:Polygon_btn.png]] to create the polygonal region with the desired mouse button.  
  
Using the mouse button just assigned to polygon region, outline the supernova remnant. You start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then you double-click to connect and close the region.  When your mouse is inside the region, a bounding box will appear with the vertices shown as draggable solid squares.  If you want to adjust the vertices you can do so.
+
Using the mouse button just assigned to polygon region, outline the extended structures of 3C75. You start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then you double-click to connect and close the region.  When your mouse is inside the region, a bounding box will appear with the vertices shown as draggable solid squares.  If you want to adjust the vertices you can do so.
  
 
If you find you don't like your region you can dismiss it with with ESC key or using the remove region "X" button in lower right of the panel.  You can also employ the region panel to save a region you have created for later use.
 
If you find you don't like your region you can dismiss it with with ESC key or using the remove region "X" button in lower right of the panel.  You can also employ the region panel to save a region you have created for later use.
Line 1,342: Line 1,624:
 
Double click inside of that region (using the same mouse button used to make the region), and the statistics will be reported. This will include the flux density value within the region selected.
 
Double click inside of that region (using the same mouse button used to make the region), and the statistics will be reported. This will include the flux density value within the region selected.
 
<pre style="background-color: #E0FFFF;">
 
<pre style="background-color: #E0FFFF;">
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
+
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----                                                                                                                                                                                                                                                                          
(3c391_ctm_spw0_multiscale.pbcorimage)
+
(3C75_final.image.tt0)                                                                                                                                                                                                                                                                                                                                        
         Stokes      Velocity          Frame        Doppler      Frequency  
+
         Stokes      Velocity          Frame        Doppler      Frequency                                                                                                                                                                                                                                                                                    
             I         0km/s          LSRK          RADIO   4.59835e+09  
+
             I   -104.873km/s          LSRK          RADIO         3e+09                                                                                                                                                                                                                                                                                    
BrightnessUnit       BeamArea           Npts            Sum   FluxDensity
+
BrightnessUnit          Npts            Sum           Mean            Rms                                                                                                                                                                                                                                                                                   
      Jy/beam        46.0055          18836   4.318515e+02  9.386948e+00
+
                        2659  1.243414e+02   4.676248e-02  5.722227e-02                                                                                                                                                                                                                                                                                   
          Mean            Rms       Std dev        Minimum        Maximum  
+
       Std dev        Minimum        Maximum   region count                                                                                                                                                                                                                                                                                                   
  2.292692e-02   3.106691e-02  2.096504e-02  -1.934644e-03  1.567044e-01  
+
   3.298586e-02  -1.063592e-03  1.484267e-01              1                                                                                                                                                                                                                                                                                                  
  region count
+
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----  
             1  
 
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 
 
</pre>
 
</pre>
In our example we find a total Flux density of 9.4 Jy. Note that the numbers you get may be slightly different depending on how deeply you cleaned.
+
In our example we find a total Flux density of 124 Jy. Note that the numbers you get may be slightly different depending on how deeply you cleaned. Also, this number is not the correct total flux density, to obtain the correct flux density you have to apply the primary beam correction similar to what we did above and repeat this analysis.
  
By contrast, for the rms noise level, one can load the original (un-pbcor) image:
+
By contrast, for the rms noise level ''exclude'' the source's emission to the extent possible as shown in Figure 27, as the source's emission will bias the estimated noise level high.  Likewise, one should avoid the clean bowl around the source emission. One can repeat the procedure above, defining a polygonal region, then double clicking inside it to determine the statistics. For example, from the region selection shown to the right for off-source statistics:
<source lang="python">
 
# In CASA
 
!casaviewer '3c391_ctm_spw0_multiscale.image' &
 
</source>
 
and to ''exclude'' the source's emission to the extent possible as shown in Figure 27, as the source's emission will bias the estimated noise level high.  Likewise, one should avoid the clean bowl around the source emission. One can repeat the procedure above, defining a polygonal region, then double clicking inside it to determine the statistics. For example, from the region selection shown to the right for off-source statistics:
 
 
<pre style="background-color: #E0FFFF;">
 
<pre style="background-color: #E0FFFF;">
 +
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----                                                                                                                                                                                                                                                                         
 +
(3C75_final.image.tt0)                                                                                                                                                                                                                                                                                                                                       
 +
        Stokes      Velocity          Frame        Doppler      Frequency                                                                                                                                                                                                                                                                                   
 +
            I  -104.873km/s          LSRK          RADIO          3e+09
 +
BrightnessUnit          Npts            Sum          Mean            Rms
 +
                        1216  -3.509342e-02  -2.885972e-05  6.186932e-05
 +
      Std dev        Minimum        Maximum  region count
 +
  5.474847e-05  -1.558577e-04  1.394379e-04              1
 
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
(3c391_ctm_spw0_multiscale.image)
+
 
        Stokes      Velocity          Frame        Doppler      Frequency
 
            I          0km/s          LSRK          RADIO    4.59835e+09
 
BrightnessUnit      BeamArea          Npts            Sum    FluxDensity
 
      Jy/beam        46.0055          23833  -1.520854e+00  -3.305808e-02
 
          Mean            Rms        Std dev        Minimum        Maximum
 
-6.381295e-05  5.174784e-04  5.135396e-04  -2.055434e-03  1.800399e-03
 
  region count
 
            1
 
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
 
  
 
</pre>
 
</pre>
Thus the Stokes I rms is 0.5 mJy. It will be useful later on to have the flat-noise and pb-corrected images available separately along with the statistics.
+
Thus the Stokes I rms is 0.06 mJy/beam. It will be useful later on to have the flat-noise and pb-corrected images available separately along with the statistics.
 
 
<!--
 
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.
 
( Spectral Index Imaging )
 
 
 
The spectral index, defined as the slope of the radio spectrum between two different frequencies, <math>\log(S_{\nu_1}/S_{\nu_2})/\log(\nu_1/\nu_2)</math>, is a useful analytical tool that can convey information about the emission mechanism, the optical depth of the source or the underlying energy distribution of synchrotron-radiating electrons.
 
 
 
Having used {{immath}} to manipulate the polarization images, the reader should now have some familiarity with performing mathematical operations within CASA.  Task {{immath}} also has a special mode for calculating the spectral index, ''mode='spix' ''.  The two input images at different frequencies should be provided using the parameter ''imagename'' (which is a Python list).  With this information, it is left as an exercise for the reader to create a spectral index map.
 
 
 
The two input images could be the two different spectral windows from the 3C391 continuum data set (see below).  If the higher-frequency spectral window (spw1) has not yet been reduced, then two images made with different channel ranges from the lower spectral window, spw0, should suffice.  In this latter case, the extreme upper and lower channels are suggested, to provide a sufficient lever arm in frequency to measure a believable spectral index.
 
-->
 
 
 
== Self-Calibration ==
 
 
 
Even after the initial calibration using the amplitude calibrator and the phase calibrator, there are likely to be residual phase and/or amplitude errors in the data.  Self-calibration is the process of using an existing model, often constructed from imaging the data itself, provided that sufficient visibility data have been obtained. This is essentially always the case with data: the system of equations is wildly over-constrained for the number of unknowns. 
 
 
 
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as
 
 
 
<math>
 
V'_{ij} = G_i G^*_j V_{ij}
 
</math>
 
 
 
where <math>G_i</math> is the complex gain for the <math>i^{\mathrm{th}}</math> antenna and <math>V_{ij}</math> is the true visibility.  For an array of <math>N</math> antennas, at any given instant, there are <math>N(N-1)/2</math> visibility data, but only <math>N</math> gain factors.  For an array with a reasonable number of antennas, <math>N</math> >~ 8, solutions to this set of coupled equations converge quickly.
 
 
 
There is a small amount of discussion in the old CASA Reference Manual on
 
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), but we have lectures on [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-stsci/cde_selfcal.pdf Self-calibration] given at NRAO community days. In self-calibrating data, it is useful to keep in mind the structure of a Measurement Set: there are three columns of interest for an MS: the DATA column, the MODEL column, and the CORRECTED_DATA column.  In normal usage, as part of the initial split, the CORRECTED_DATA column is set equal to the DATA column.  The self-calibration procedure is then:
 
  
* Produce an image ({{tclean}}) using the CORRECTED_DATA column.
+
The spectral index, defined as the slope of the radio spectrum between two different frequencies, <math>\log(S_{\nu_1}/S_{\nu_2})/\log(\nu_1/\nu_2)</math>, is a useful analytical tool that can convey information about the emission mechanism, the optical depth of the source or the underlying energy distribution of synchrotron-radiating electrons.  
* Derive a series of gain corrections ({{gaincal}}) by comparing the DATA columns and the Fourier transform of the image, which is stored in the MODEL column.  These corrections are stored in an external table.
 
* Apply these corrections ({{applycal}}) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.
 
  
The following example begins with the standard data set, 3c391_ctm_mosaic_spw0.ms (resulting from the steps above). From this we will make an I-only multiscale image (3c391_ctm_spw0_I.image) -- and in particular the model (3c391_ctm_spw0_I.model) -- to generate a series of gain corrections that will be stored in 3C391_ctm_mosaic_spw0.selfcal1. These gain corrections are then applied to the data to form a set of self-calibrated data, and a new image is then formed (3c391_ctm_spw0_IQUV_selfcal1.image).  Note that in the clean before the self-cal, it is important that we only image Stokes I so that any cleaned polarization does not affect the gaincal.  We first use '''delmod''' on the MS to get rid of the previous polarized model.
+
Similar analysis can be performed on the polarization and spectral index maps, this will be left to the inclined user. -->
<source lang="python">
 
#In CASA
 
delmod('3c391_ctm_mosaic_spw0.ms')
 
 
 
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',
 
      field='',spw='',
 
      specmode='mfs',
 
      niter=500,
 
      gain=0.1,threshold='1mJy',
 
      gridder='mosaic',
 
      deconvolver='multiscale',
 
      scales=[0, 6, 18, 54],smallscalebias=0.9,
 
      interactive=True,
 
      imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],
 
      stokes='I',
 
      weighting='briggs',robust=0.5,
 
      savemodel='modelcolumn')
 
</source>
 
You should not clean very deeply. You want to be sure to capture as much of the source total flux density as possible, but not include low-level questionable features or sub-structure (ripples) that might be due to calibration or clean artifacts.
 
 
 
After you are happy with the image:
 
<source lang="python">
 
#In CASA
 
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',
 
        field='',spw='',selectdata=False,
 
        solint='30s',refant='ea21',minblperant=4,minsnr=3,
 
        gaintype='G',calmode='p',append=False)
 
 
 
applycal(vis='3c391_ctm_mosaic_spw0.ms',
 
        field='',spw='',selectdata=False,
 
        gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],
 
        calwt=[False],applymode='calflag')
 
</source>
 
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by {{tclean}}. The
 
{{gaincal}} step will report a number of solutions with insufficient SNR. By default, with parameter ''applymode='calflag', '' data with no good solutions will be flagged by {{applycal}}; in this case you will see it report the flagged fraction increasing to about 45%. This may or may not be a good thing. You can control the action of {{applycal}} in this regard by changing the value of parameter ''applymode''.  The setting ''applymode='calflagstrict' ''will be even more stringent about flagging things without valid calibration, while ''applymode='calonly'  ''will calibrate those with solutions while passing through data without unchanged. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.
 
 
 
{| style="background:#98FB98"
 
|-
 
| '''Questions for the Advanced Student:'''
 
* Does allowing applycal to flag the data give better images?
 
* Or, does using ''applymode='calonly' ''give improved results?
 
|-
 
|}
 
 
 
If you planned on doing multiple iterations of self-cal, you would do another I-only image (e.g., ''3c391_ctm_spw0_ms_I_selfcal1'') as that is what is needed for the next step. If you want to just go ahead and see what this selfcal has done, do a deep clean:
 
<source lang="python">
 
#In CASA
 
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',
 
      field='',spw='',
 
      specmode='mfs',
 
      niter=20000,
 
      gain=0.1,threshold='1mJy',
 
      gridder='mosaic',
 
      deconvolver='multiscale',
 
      scales=[0, 6, 18, 54],smallscalebias=0.9,
 
      interactive=True,
 
      imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],
 
      stokes='I',
 
      weighting='briggs',robust=0.5,
 
      savemodel='modelcolumn')
 
</source>
 
 
 
{| style="background:#98FB98"
 
|-
 
| '''Questions for the Advanced Student:'''
 
* Is this better than the original multiscale image? By how much?
 
* Can you make a difference image (between the original and selfcal1 images) using {{immath}}?
 
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?
 
|-
 
|}
 
 
 
Commonly, this self-cal procedure is applied multiple times.
 
The number of iterations is determined by a combination of the data quality and number of antennas in the array, the structure of the source, the extent to which the original self-calibration assumptions are valid, and the user's patience.  With reference to the original self-calibration equation above, if the observed visibility data cannot be modeled well by this equation, no amount of self-calibration will help.  A not-uncommon limitation for moderately high dynamic range imaging is that there may be ''baseline-based'' factors that modify the true visibility.  If the corruptions to the true visibility cannot be modeled as antenna-based, as they are above, self-calibration won't help.
 
 
 
Self-calibration requires experimentation.  Do not be afraid to dump an image, or even a set of gain corrections,
 
change something and try again.  Having said that, here are several general comments or guidelines:
 
 
 
* Bookkeeping is important!  Suppose one conducts 9 iterations of self-calibration.  Will it be possible to remember one month later (or maybe even one week later!) which set of gain corrections and images are which?  In the example above, the descriptor'' 'selfcal1' ''is attached to various files to help keep straight which is what.  Successive iterations of self-cal could then be'' 'selfcal2' '','' 'selfcal3' '', etc.
 
 
 
* Care is required in the setting of ''imagename''.  If one has an image that already exists, CASA will continue cleaning it (if it can), which is almost certainly not what one wants during self-calibration.  Rather one wants a unique ''imagename'' for each pass of self-calibration.
 
 
 
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved.  An improvement of 10% is quite acceptable.
 
 
 
* Be careful when making images and setting clean regions or masks.  Self-calibration assumes that the model is perfect.  If one cleans a noise bump, self-calibration will quite happily try to adjust the gains so that the CORRECTED_DATA describe a source at the location of the noise bump.  It is far better to exclude some feature of a source or a weak source from initial cleaning and conduct another round of self-calibration than to create an artificial source.  If a real source is excluded from initial cleaning, it will continue to be present in subsequent iterations of self-calibration; if it's not a real source, one probably isn't interested in it anyway.
 
 
 
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in {{gaincal}}).  As discussed in the [http://adsabs.harvard.edu/abs/1989ASPC....6..287P High Dynamic Range Imaging] lecture, a phase error of 20 deg is as bad as an amplitude error of 10%.
 
 
 
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in {{gaincal}}) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in {{gaincal}}).  Depending upon the frequency and configuration and fidelity of the model image, it can be quite reasonable to start with ''solint='30s' ''or'' solint='60s' ''and/or ''minsnr=3 (''or even lower).  One might also want to consider specifying a uvrange, if, for example, the field has structure on large scales (small <math>u</math>-<math>v</math>) that is not well represented by the current image.
 
 
 
* The task {{applycal}} will flag data with no good calibration solutions. During the initial self-calibration steps, this flagging may be excessive. If so, one can restore the flags to the state right before running applycal by using the task '''[https://casa.nrao.edu/casadocs/latest/data-examination-and-editing/managing-flag-versions-flagmanager flagmanager]'''.
 
 
 
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in {{plotms}}.  The options in Axes tab allows one to select which column is to be plotted.  If the MODEL agrees well with the CORRECTED_DATA, one can use shorter solint and/or higher minsnr values.
 
 
 
* You should consider examining the solutions from {{gaincal}} by using {{plotcal}} in order to assure that the corrections are sensible.  Smoothly varying phases are good, jumps are usually not.  (However, because the phases are often plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)
 
 
 
* In the case of a mosaic, such as here, one should also verify that the solutions are of equal quality for all of the fields.
 
 
 
= On Your Own: 3C391 second frequency and G93.3+6.9 =
 
 
 
Now that you have run through spw 0 of 3C391, you are ready to strike off on your own with other datasets.  We have provided two options here, described below.  The first option is simplest as it is the same object using a different spectral window; for a more rewarding challenge try the L-band dataset on G93.3+6.9.
 
 
 
You can find the data in the [http://casa.nrao.edu/Data/EVLA/3C391/AdvancedEVLAcont.tgz CASA repository].  Both datasets -- 3C391 spw 1 (at 7.5 GHz) and Supernova Remnant G93.3+6.9 at L-band -- are contained in this tarball. To keep their sizes small, these MSs do not have the scratch columns pre-made, so you can do an initial {{clearcal}} to force the creation of the scratch columns or wait until your first calibration task does it for you.
 
 
 
1. 3C391 spw 1 (at 7.5 GHz)
 
 
 
This is the second spectral window split off from the 3C391 dataset.  You can process this as you did the first time, but beware of RFI in this band.  You will have to avoid it through channel ranges and/or edit it out.  Once you have processed this data, you can
 
<!-- and imaged it, you can combine those images in {{immath}} to make a spectral index image (see above) or (AEK: removed spectral index imaging as not working with mosaic gridder as of CASA 5.4)
 
-->
 
combine the two calibrated MSs in {{tclean}} to make a deeper MFS image (this might be tricky).
 
 
 
2. Supernova Remnant G93.3+6.9 at L-band
 
 
 
This is data taken at L-band of an entirely different Supernova Remnant, centered near 1400 MHz.  You should be able to process this data in a very similar manner to the C-band data on 3C391.  Note that we are not telling you what you will see in the image ahead of time.  Here are some data reduction hints to help you along:
 
 
 
* There is strong RFI in this spectral window of the original 2 spw dataset.  You will need to find it (e.g., using {{plotms}}) and avoid it in imaging.  You can also flag those channels using {{flagdata}}, but this is not necessary.  Note that there is a single baseline that shows very strong interference, see if you can find it.  You can flag it using the baseline syntax in {{flagdata}} (e.g., parameter ''antenna='ea0x&ea0y' '').
 
 
 
* We have not edited out bad or dead antennas for you (unlike in 3C391).  You will need to find these using {{plotms}} and then {{flagdata}} them.  One helpful {{plotms}} trick is to set parameter ''antenna='ea01' ''and pick a few channels (like'' spw='0:30~33' '') and a single scan (e.g., ''scan='2~3' '') and plot the amp versus Antenna2 on the X-axis.  You should see the bad antennas (the low ones).  As a check set'' antenna='ea02' ''and repeat.  Is it the same?
 
 
 
* In spite of RFI, the antenna-based calibration is remarkably resilient to moderate-to-low RFI contamination (which tends to be baseline-based).  So rather than flagging channels with RFI, you might try going ahead with calibration and seeing if the solutions make sense.  We were able to calibrate this data without flagging channels (only getting the bad baseline noted above).
 
 
 
* There is no observation of a flux or polarization angle calibrator like J1331+3030.  You need to use {{setjy}} to set the Stokes I flux of the gain calibrator.  We use the approximate flux density of 5.8 Jy for J2038+5119.
 
 
 
* When it comes time to calibrate the polarization leakage, we are in good shape since J2038+5119 was observed through a range of parallactic angle (use {{plotms}} to plot versus ParAngle).  Use parameter'' poltype='Df+QU' ''to solve for leakage and the unknown polarization of this source.  We do not know the true polarization angle of this source, so before doing parameter'' poltype='Xf ' '',use {{setjy}} to set the Q flux to 5.8Jy * fractional pol (determined in leakage polcal run). 
 
<!--
 
This will at least align the polarization when you image it. AEK: removed polarization imaging for the CASA 5.4 guide.
 
-->
 
 
 
* The L-band field of view is much larger than at C-band.  From the [http://go.nrao.edu/vla-oss VLA Observational Status Summary (OSS)] the resolution should be around 46" in D-config.  Use a cellsize of 15" or smaller.  What is the primary beam of the VLA at 1.4MHz?  How big should you make your image? 
 
 
 
* As you clean you will see faint sources all over the field; welcome to L-band imaging.  This supernova remnant has lots of structure - try both standard and multi-scale clean.
 
  
 
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].
 
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].
{{Checked 5.4.0}}  
+
{{Checked 5.4.2}}  
 
[[Main Page | &#8629; '''CASAguides''']]
 
[[Main Page | &#8629; '''CASAguides''']]
 +
 +
<!--Edited by Trent Seelig, Data Analyst 2019-11-13-->

Latest revision as of 18:34, 20 November 2019


This CASA Guide is for version 5.4.2-5 of CASA that includes the VLA pipeline and is also verified to work with 5.4.1-32, but not 5.4.0-70 that does not include a pipeline. If you are using a later version of CASA and this is the most recent available guide, then you should be able to use most, if not all, of this tutorial.

Overview

This CASA guide describes the calibration and imaging of a single-pointing continuum data set taken with the Karl G. Jansky Very Large Array (VLA) of the binary black hole system 3C 75 in Abell 400 cluster of galaxies. [1]. The data were taken as a demonstration for the VLA data reduction workshops under project code TDRW0001. To reduce the dataset size, the data was recorded with a single 1 GHz baseband centered at 3.0 GHz, resulting in 8x128 MHz wide spectral windows with 64 channels each. The observation was set up to allow for full polarization calibration.

How to Use This CASA Guide

Here are a number of possible ways to run CASA, described in more detail in Getting Started in CASA. In brief, there are at least three different ways to run CASA:

  • Interactively examining task inputs. In this mode, one types taskname to load the task, inp to examine the inputs, and go once those inputs have been set to your satisfaction. Allowed inputs are colored blue and bad inputs are colored red. The input parameters themselves are changed one by one, e.g., selectdata=True. Screenshots of the inputs to various tasks used in the data reduction are provided to illustrate which parameters need to be set. More detailed help can be obtained on any task by typing help taskname. Once a task is run, the set of inputs are stored and can be retrieved via tget taskname; subsequent runs will overwrite the previous tget file.
  • Pseudo-interactively via task function calls. In this case, all of the desired inputs to a task are provided at once on the CASA command line. This tutorial is made up of such calls, which were developed by looking at the inputs for each task and deciding what needed to be changed from default values. For task function calls, only parameters that you want to be different from their defaults need to be set.
  • Non-interactively via a script. A series of task function calls can be combined together into a script and run from within CASA via execfile('scriptname.py'). This and other CASA Tutorial Guides have been designed to be extracted into a script via the script extractor by using the method described at the Extracting_scripts_from_these_tutorials page. Should you decide to use the script generated by the script extractor for this CASA Guide, be aware that it will require some small amount of interaction related to the plotting, occasionally suggesting that you close the graphics window and hitting return in the terminal to proceed. It is, in fact, unnecessary to close the graphics windows (it is suggested that you do so purely to keep your desktop uncluttered).

If you are a relative novice or just new to CASA, it is strongly recommended to work through this tutorial by cutting and pasting the task function calls provided below after you have read all the associated explanations. Work at your own pace, look at the inputs to the tasks to see what other options exist, and read the help files. Later, when you are more comfortable, you might try to extract the script, modify it for your purposes, and begin to reduce other data.

Obtaining the Data

If starting from scratch, you can obtain the dataset from the NRAO archive and search for the Archive File ID: 'TDRW0001.sb35624494.eb35628826.58395.23719237269'. The uncalibrated visibilities have a size of 12.5 GB.

For those that want to skip the step of obtaining a continuum Stokes I calibrated measurement set, we have created a starting dataset on which the polarization calibration steps and final imaging can be performed: https://casa.nrao.edu/Data/EVLA/TDRW0001/TDRW0001_calibrated.ms.tgz (size: 10 GB). Recommended to use the command line tool wget to download. You will need to untar and unzip the file using the command: 'tar -xzvf TDRW0001_calibrated.ms.tgz'. Then you can skip ahead to the section 'The Observation'.

Pipeline Calibration of Parallel Hands (RR/LL)

If you start with the uncalibrated visibilities obtained from the archive, you will need to first perform a standard continuum calibration of the parallel-hand (RR/LL) cross-correlation visibilities. In this guide we use the standard VLA pipeline that is packaged with the CASA release. You can find more information on the latest release of the VLA pipeline here: https://science.nrao.edu/facilities/vla/data-processing/pipeline.

In this example, we will not run the pipeline in its standard way but tweak it to force a certain reference antenna. The pipeline typically tries to pick a reference antenna at the center of the array; however this dataset was observed in D array configuration with very short baselines. It was found to be better to use one of the outer antennas for reference, which provides more longer baselines and more stable phase solutions. To set the reference antenna, we specify the refantignore parameter in some of the pipeline tasks to exclude all but the reference antenna, and use a pipeline execution script ('casa_pipescript.py'). Take the script given below and paste it into a text file inside your working directory that also contains the dataset you downloaded from the NRAO archive and name it casa_pipescript.py.

# casa_pipescript.py

__rethrow_casa_exceptions = True
context = h_init()
context.set_state('ProjectSummary', 'proposal_code', 'VLA/null')
context.set_state('ProjectSummary', 'observatory', 'Karl G. Jansky Very Large Array')
context.set_state('ProjectSummary', 'telescope', 'EVLA')
context.set_state('ProjectSummary', 'piname', 'unknown')
context.set_state('ProjectSummary', 'proposal_title', 'unknown')
try:
    hifv_importdata(vis=['TDRW0001.sb35624494.eb35628826.58395.23719237269'], session=['session_1'], createmms='automatic', asis='Receiver CalAtmosphere', ocorr_mode='co', nocopy=False, overwrite=False)
    hifv_hanning(pipelinemode="automatic")
    hifv_flagdata(tbuff=0.0, flagbackup=False, scan=True, fracspw=0.05, intents='*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*, *UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*', clip=True, baseband=True, shadow=True, quack=True, edgespw=True, autocorr=True, hm_tbuff='1.5int', template=True, online=True)
    hifv_vlasetjy(fluxdensity=-1, scalebychan=True, spix=0, reffreq='1GHz')
    hifv_priorcals(tecmaps=False)
    hifv_testBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_flagbaddef(doflagundernspwlimit=True)
    hifv_checkflag(pipelinemode="automatic")
    hifv_semiFinalBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_checkflag(checkflagmode='semi')
    hifv_semiFinalBPdcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_solint(refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_fluxboot(refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_finalcals(weakbp=False, refantignore='ea01,ea02,ea03,ea04,ea05,ea06,ea07,ea08,ea09,ea11,ea12,ea13,ea14,ea15,ea16,ea17,ea18,ea19,ea20,ea21,ea22,ea23,ea24,ea26,ea28')
    hifv_applycals(flagdetailedsum=True, gainmap=False, flagbackup=True, flagsum=True)
    hifv_targetflag(intents='*CALIBRATE*,*TARGET*')
    hifv_statwt(pipelinemode="automatic")
    hifv_plotsummary(pipelinemode="automatic")
    hif_makeimlist(nchan=-1, calcsb=False, intent='PHASE,BANDPASS', robust=-999.0, per_eb=False, calmaxpix=300, specmode='cont', clearlist=True)
    hif_makeimages(tlimit=2.0, hm_minbeamfrac=-999.0, hm_dogrowprune=True, hm_negativethreshold=-999.0, calcsb=False, target_list={}, hm_noisethreshold=-999.0, hm_masking='none', hm_minpercentchange=-999.0, parallel='automatic', masklimit=4, hm_lownoisethreshold=-999.0, hm_growiterations=-999, cleancontranges=False, hm_sidelobethreshold=-999.0)
finally:
    h_save()

Now that we have the script, we can execute the pipeline. Type on the command line the following.

# On the command line, for your own installation of CASA 5.4.2-5
casa --pipeline --nogui -c casa_pipescript.py

# If using an NRAO computer, to select the right CASA version use instead
casa -r 5.4.2-5 --pipeline --nogui -c casa_pipescript.py

Now you can go and get a cup of coffee or lunch. This is going to take a while. On a beefy computer expect about two hours. Once the pipeline has successfully finished you will see some similar messages on the command line prompt.

2019-03-21 19:18:01 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.residual.tt0
2019-03-21 19:18:01 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.model.tt0
2019-03-21 19:18:02 INFO: Plotting pipeline-20190225T152914/html/oussid.s20_0.J0259+0747_ph.S_band.cont.I.iter1.mask

2019-03-21 19:18:06 INFO: Saving context to 'pipeline-20190321T171946.context'

In order to be able to continue calibration for polarization, i.e. the cross-hand correlations (RL/LR), on pre-calibrated visibilities, we need to perform some additional steps that remove the parallactic angle correction that was applied by the standard pipeline. To do so, start CASA and execute the following commands.

# In CASA
flagmanager(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',mode='restore',versionname='applycal_5')

applycal(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', 
	 antenna='*&*', 
	 gaintable=['TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_2.gc.tbl','TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_3.opac.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_4.rq.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_6.ants.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_2.finaldelay.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_4.finalBPcal.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_5.averagephasegain.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_7.finalampgaincal.tbl', 'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s14_8.finalphasegaincal.tbl'], 
	 gainfield=['', '', '', '', '', '', '', '', ''], interp=['', '', '', '', '', 'linear,linearflag', '', '', ''], 
	 spwmap=[[], [], [], [], [], [], [], [], []], 
	 calwt=[False, False, False, False, False, False, False, False, False], 
	 parang=False, 
	 applymode='calflagstrict', 
	 flagbackup=False)

flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', mode='rflag', correlation='ABS_LL,RR', intent='*CALIBRATE*', datacolumn='corrected', ntime='scan', combinescans=False, extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0, action='apply', flagbackup=False, savepars=True)
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', mode='rflag', correlation='ABS_LL,RR', intent='*TARGET*', datacolumn='corrected', ntime='scan', combinescans=False, extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0, action='apply', flagbackup=False, savepars=True)

statwt(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', minsamp=8, datacolumn='corrected', flagbackup=False)

split(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',outputvis='TDRW0001_calibrated.ms',datacolumn='corrected',spw='2~9')

This applies the flagging state before the final applycal stage of the pipeline, then reapplies the calibration to the corrected column with parang=False, thus disabling the parallactic angle corrections. After that, we rerun target field flagging, and recompute the weights based on the new flags that were applied and split out the corrected column for the target spectral windows. Essentially, we repeated what pipeline tasks hifv_applycals, hifv_targetflag, and hifv_statwt did, but disabling application of parallactic angle corrections. This is the measurement set we will be using in the following to demonstrate polarization calibration.

The Observation

Before starting the calibration process, we want to get some basic information about the data set. To examine the observing conditions during the observing run, and to find out any known problems with the data, download the observer log. Simply fill in the known observing date (in our case 2018-Oct-04) as both the Start and Stop date and click on the Show Logs button. The relevant log is labelled with the project code, TDRW0001, and can be downloaded as a PDF file. From this, we find the following:

Information from observing log:
Antennas in the D-array may be shadowed at low elevations.  If shadowing
occurs, sensitivity will be affected.

NOTE!: The VLA is still recovering from a long power outage, and these data may
have unusual artifacts, missing antennas or IFs, ect., in them. NRAO staff will 
examine the data closely after observing to determine if they meet the criteria for 
a successful observation.

Antenna ea05: S-band receiver cooling after work performed, currently 65/177K,
              thus we expect lower sensitivity from this antenna.
Antenna ea12: C-band receiver warm for cold head replacement.
Antennas ea10, ea12, ea22 do not have good baseline positions
Winds at 7-5 m/s, API RMS phase around 4 deg., 10-20% sky cover, cumuliform and stratiform clouds. 

Before beginning our data reduction, we should inspect the pipeline calibration weblog for any obvious issues. You can download the weblog from https://casa.nrao.edu/Data/EVLA/TDRW0001/weblog.tgz or directly access it at https://casa.nrao.edu/Data/EVLA/TDRW0001/pipeline-20190321T171946/html/.

Inside the weblog, you have access to the overview page and the listobs task output that provide some basic information about the data.

You will note that there are four sources observed. Here the various sources are introduced briefly, with more detail contained in the sections below in which they are used

  • 0137+331=3C48, which will serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, the spectral bandpass, and the polarization position angle;
  • J0259+0747, which will serve as a calibrator for the visibility phases and can be used to determine the instrumental polarization;
  • J2355+4950, which can serve as a secondary instrumental polarization calibrator or to check residual instrumental polarization, and;
  • 3C75, which is the science target.


================================================================================
           MeasurementSet Name:  /lustre/aoc/sciops/dmedlin/4fs/TDRW0001.sb35624494.eb35628826.58395.23719237269.ms      MS Version 2
================================================================================
   Observer: Dr. Emmanuel Momjian     Project: uid://evla/pdb/35621723  
Observation: EVLA
Data records: 5752188       Total elapsed time = 10270 seconds
   Observed from   04-Oct-2018/05:41:35.0   to   04-Oct-2018/08:32:45.0 (UTC)

   ObservationID = 0         ArrayID = 0
  Date        Timerange (UTC)          Scan  FldId FieldName             nRows     SpwIds   Average Interval(s)    ScanIntent
  04-Oct-2018/05:41:35.0 - 05:42:31.0     1      0 0137+331=3C48            39312  [0,1]  [1, 1] [SYSTEM_CONFIGURATION#UNSPECIFIED]
              05:42:32.0 - 05:47:30.0     2      0 0137+331=3C48           209196  [0,1]  [1, 1] [SYSTEM_CONFIGURATION#UNSPECIFIED]
              05:47:35.0 - 05:48:30.0     3      0 0137+331=3C48            30888  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]
              05:48:35.0 - 05:49:00.0     4      0 0137+331=3C48            14040  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]
              05:49:05.0 - 05:53:25.0     5      0 0137+331=3C48           146016  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_POL_ANGLE#UNSPECIFIED]
              05:53:30.0 - 05:57:55.0     6      1 J2355+4950              148824  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]
              05:58:00.0 - 06:03:55.0     7      2 J0259+0747              199368  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              06:04:00.0 - 06:18:55.0     8      3 3C75                    502632  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              06:19:00.0 - 06:20:10.0     9      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              06:20:15.0 - 06:35:05.0    10      3 3C75                    499824  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              06:35:10.0 - 06:36:20.0    11      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              06:36:25.0 - 06:51:20.0    12      3 3C75                    502632  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              06:51:25.0 - 06:52:30.0    13      2 J0259+0747               36504  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              06:52:35.0 - 07:07:30.0    14      3 3C75                    502632  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              07:07:35.0 - 07:08:45.0    15      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              07:08:50.0 - 07:23:40.0    16      3 3C75                    499824  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              07:23:45.0 - 07:26:25.0    17      2 J0259+0747               89856  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              07:26:30.0 - 07:41:25.0    18      3 3C75                    502632  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              07:41:30.0 - 07:42:40.0    19      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              07:42:45.0 - 07:57:35.0    20      3 3C75                    499824  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              07:57:40.0 - 07:58:50.0    21      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              07:58:55.0 - 08:13:50.0    22      3 3C75                    502632  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              08:13:55.0 - 08:15:05.0    23      2 J0259+0747               39312  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
              08:15:10.0 - 08:30:00.0    24      3 3C75                    499824  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]
              08:30:05.0 - 08:32:45.0    25      2 J0259+0747               89856  [2,3,4,5,6,7,8,9]  [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]
           (nRows = Total number of rows per scan) 
Fields: 4
  ID   Code Name                RA               Decl           Epoch   SrcId      nRows
  0    NONE 0137+331=3C48       01:37:41.299431 +33.09.35.13299 J2000   0         439452
  1    NONE J2355+4950          23:55:09.458169 +49.50.08.34001 J2000   1         148824
  2    NONE J0259+0747          02:59:27.076633 +07.47.39.64322 J2000   2         651456
  3    NONE 3C75                02:57:42.630000 +06.01.04.80000 J2000   3        4512456
Spectral Windows:  (10 unique spectral windows and 1 unique polarization setups)
  SpwID  Name          #Chans   Frame   Ch0(MHz)  ChanWid(kHz)  TotBW(kHz) CtrFreq(MHz) BBC Num  Corrs          
  0      EVLA_C#A0C0#0     64   TOPO    4832.000      2000.000    128000.0   4895.0000       12  RR  RL  LR  LL
  1      EVLA_C#B0D0#1     64   TOPO    4960.000      2000.000    128000.0   5023.0000       15  RR  RL  LR  LL
  2      EVLA_S#A0C0#2     64   TOPO    2488.000      2000.000    128000.0   2551.0000       12  RR  RL  LR  LL
  3      EVLA_S#A0C0#3     64   TOPO    2616.000      2000.000    128000.0   2679.0000       12  RR  RL  LR  LL
  4      EVLA_S#A0C0#4     64   TOPO    2744.000      2000.000    128000.0   2807.0000       12  RR  RL  LR  LL
  5      EVLA_S#A0C0#5     64   TOPO    2872.000      2000.000    128000.0   2935.0000       12  RR  RL  LR  LL
  6      EVLA_S#A0C0#6     64   TOPO    3000.000      2000.000    128000.0   3063.0000       12  RR  RL  LR  LL
  7      EVLA_S#A0C0#7     64   TOPO    3128.000      2000.000    128000.0   3191.0000       12  RR  RL  LR  LL
  8      EVLA_S#A0C0#8     64   TOPO    3256.000      2000.000    128000.0   3319.0000       12  RR  RL  LR  LL
  9      EVLA_S#A0C0#9     64   TOPO    3384.000      2000.000    128000.0   3447.0000       12  RR  RL  LR  LL
Sources: 34
  ID   Name                SpwId RestFreq(MHz)  SysVel(km/s) 
  0    0137+331=3C48       0     -              -            
  0    0137+331=3C48       1     -              -            
  0    0137+331=3C48       2     -              -            
  0    0137+331=3C48       3     -              -            
  0    0137+331=3C48       4     -              -            
  0    0137+331=3C48       5     -              -            
  0    0137+331=3C48       6     -              -            
  0    0137+331=3C48       7     -              -            
  0    0137+331=3C48       8     -              -            
  0    0137+331=3C48       9     -              -            
  1    J2355+4950          2     -              -            
  1    J2355+4950          3     -              -            
  1    J2355+4950          4     -              -            
  1    J2355+4950          5     -              -            
  1    J2355+4950          6     -              -            
  1    J2355+4950          7     -              -            
  1    J2355+4950          8     -              -            
  1    J2355+4950          9     -              -            
  2    J0259+0747          2     -              -            
  2    J0259+0747          3     -              -            
  2    J0259+0747          4     -              -            
  2    J0259+0747          5     -              -            
  2    J0259+0747          6     -              -            
  2    J0259+0747          7     -              -            
  2    J0259+0747          8     -              -            
  2    J0259+0747          9     -              -            
  3    3C75                2     -              -            
  3    3C75                3     -              -            
  3    3C75                4     -              -            
  3    3C75                5     -              -            
  3    3C75                6     -              -            
  3    3C75                7     -              -            
  3    3C75                8     -              -            
  3    3C75                9     -              -            
Antennas: 27:
  ID   Name  Station   Diam.    Long.         Lat.                Offset from array center (m)                ITRF Geocentric coordinates (m)        
                                                                     East         North     Elevation               x               y               z
  0    ea01  W06       25.0 m   -107.37.15.6  +33.53.56.4       -275.8278     -166.7360       -2.0595 -1601447.195400 -5041992.497600  3554739.694800
  1    ea02  W04       25.0 m   -107.37.10.8  +33.53.59.1       -152.8711      -83.7955       -2.4675 -1601315.900500 -5041985.306670  3554808.309400
  2    ea03  W07       25.0 m   -107.37.18.4  +33.53.54.8       -349.9804     -216.7527       -1.7877 -1601526.383100 -5041996.851000  3554698.331400
  3    ea04  N04       25.0 m   -107.37.06.5  +33.54.06.1        -42.6260      132.8521       -3.5428 -1601173.981600 -5041902.657800  3554987.528200
  4    ea05  E05       25.0 m   -107.36.58.4  +33.53.58.8        164.9709      -92.7908       -2.5361 -1601014.465100 -5042086.235700  3554800.804900
  5    ea06  N06       25.0 m   -107.37.06.9  +33.54.10.3        -54.0745      263.8800       -4.2325 -1601162.598500 -5041828.990800  3555095.895300
  6    ea07  E04       25.0 m   -107.37.00.8  +33.53.59.7        102.8035      -63.7671       -2.6299 -1601068.794800 -5042051.918100  3554824.842700
  7    ea08  E01       25.0 m   -107.37.05.7  +33.53.59.2        -23.8867      -81.1272       -2.5808 -1601192.486700 -5042022.840700  3554810.460900
  8    ea09  N05       25.0 m   -107.37.06.7  +33.54.08.0        -47.8569      192.6072       -3.8789 -1601168.794400 -5041869.042300  3555036.937000
  9    ea10  E08       25.0 m   -107.36.48.9  +33.53.55.1        407.8379     -206.0064       -3.2255 -1600801.917500 -5042219.370600  3554706.449200
  10   ea11  N07       25.0 m   -107.37.07.2  +33.54.12.9        -61.1072      344.2424       -4.6414 -1601155.630600 -5041783.816000  3555162.366400
  11   ea12  E07       25.0 m   -107.36.52.4  +33.53.56.5        318.0401     -164.1704       -2.6834 -1600880.582300 -5042170.386600  3554741.476400
  12   ea13  W02       25.0 m   -107.37.07.5  +33.54.00.9        -67.9810      -26.5266       -2.7142 -1601225.261900 -5041980.363990  3554855.705700
  13   ea14  E09       25.0 m   -107.36.45.1  +33.53.53.6        506.0539     -251.8836       -3.5735 -1600715.958300 -5042273.202200  3554668.175800
  14   ea15  N03       25.0 m   -107.37.06.3  +33.54.04.8        -39.1086       93.0234       -3.3585 -1601177.399560 -5041925.041300  3554954.573300
  15   ea16  E02       25.0 m   -107.37.04.4  +33.54.01.1          9.8042      -20.4562       -2.7822 -1601150.083300 -5042000.626900  3554860.706200
  16   ea17  N09       25.0 m   -107.37.07.8  +33.54.19.0        -77.4340      530.6515       -5.5829 -1601139.481300 -5041679.026500  3555316.554900
  17   ea18  W09       25.0 m   -107.37.25.2  +33.53.51.0       -521.9447     -332.7673       -1.2061 -1601710.016800 -5042006.914600  3554602.360000
  18   ea19  W05       25.0 m   -107.37.13.0  +33.53.57.8       -210.1007     -122.3814       -2.2582 -1601377.012800 -5041988.659800  3554776.399200
  19   ea20  N02       25.0 m   -107.37.06.2  +33.54.03.5        -35.6257       53.1906       -3.1311 -1601180.861780 -5041947.450400  3554921.638900
  20   ea21  N01       25.0 m   -107.37.06.0  +33.54.01.8        -30.8742       -1.4746       -2.8653 -1601185.628465 -5041978.158516  3554876.414800
  21   ea22  W03       25.0 m   -107.37.08.9  +33.54.00.1       -105.3218      -51.7280       -2.6013 -1601265.134100 -5041982.547450  3554834.851200
  22   ea23  E06       25.0 m   -107.36.55.6  +33.53.57.7        236.9085     -126.3395       -2.4685 -1600951.579800 -5042125.894100  3554772.996600
  23   ea24  W08       25.0 m   -107.37.21.6  +33.53.53.0       -432.1080     -272.1502       -1.5080 -1601614.082500 -5042001.654800  3554652.505900
  24   ea25  N08       25.0 m   -107.37.07.5  +33.54.15.8        -68.9105      433.1823       -5.0689 -1601147.943900 -5041733.832200  3555235.945600
  25   ea26  E03       25.0 m   -107.37.02.8  +33.54.00.5         50.6698      -39.4668       -2.7317 -1601114.356200 -5042023.141200  3554844.955400
  26   ea28  W01       25.0 m   -107.37.05.9  +33.54.00.5        -27.3603      -41.2944       -2.7520 -1601189.030040 -5042000.479400  3554843.427200

Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; 0 through 26 in this instance) do not correspond to the actual antenna names (ea01 through ea28; these numbers correspond to those painted on the side of the antennas). The antennas can be referenced using either convention; antenna='22' would correspond to ea23, whereas antenna='ea22' would correspond to ea22. Note that the antenna numbers in the observer log correspond to the actual antenna names, i.e., the 'ea??' numbers given in listobs.

Both to get a sense of the array, as well as identify the location of the antenna that was picked by the pipeline for parallel hand calibration, have a look at the antenna setup page. Generally, for calibration purposes, you would prefer to select an antenna that is close to the center of the array (and that is not listed in the operator's log as having had problems!). As noted above, in a compact configuration there is a benefit to choose an outer antenna to increase the bias toward longer baselines.

At this point it is also a good idea to check the quality of the pipeline calibration. Go to the task overview page and pay particular attention to hifv_finalcals and hifv_plotsummary. Try to see if you can recognize which reference antenna was picked. For more details on the pipeline output you can have a look at the VLA CASA Pipeline Guide. Going forward we assume that the pipeline calibration is good and we can use it as a starting point for further calibration steps focusing on polarization calibration and imaging.

Examining and Editing the Data

At this point we must start CASA. If you have not used CASA before, some helpful tips are available on the Getting Started in CASA page.

It is always a good idea to examine the data before jumping straight into calibration. From the observer's log there were no major issues noted, besides a potentially warm receiver on antenna ea05. Even though the pipeline did a good job of calibrating and flagging the data, it isn't perfect. From the pipeline weblog, looking at the final amplitude gain calibration vs time plots in hifv_finalcals, we can see that during the second half of the observation antennas ea03, ea12, and ea16 shows some gain instability; otherwise there are no issues identified at this point.

Start by inspecting these three particular antennas using the CASA task plotms, plot frequency against amplitude and frequency against time for the parallel hands, iterate over field or scan, and note if you find something at odds.

# In CASA
plotms(vis='TDRW0001_calibrated.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')
Figure 1: Overview of the observation: amplitude vs time, color-coded by field.
  • selectdata=True : One can choose to plot only selected subsets of the data.
  • correlation='RR,LL' : Plot only the left- and right-handed polarization products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.
  • averagedata=True: One can choose to average data points before plotting them.
  • avgchannel='64' : With this plot, we are mainly interested in the fields vs time. Averaging over all 64 channels in the spectral window makes the plotting faster.
  • coloraxis='field' : Color-code the plotting symbols by field name/number.

The default x- and y-axis parameters are 'time' and 'amp', so the above call to plotms produces an amplitude vs time plot of the data for a selected subset of the data (if desired) and with data averaging (if desired). Many other values have also been left to defaults, but it is possible to select them from within the plotms GUI.

Task plotms allows one to select and view the data in many ways. Figure 1 shows the result of running plotms with the field selection discussed above. You can quickly see that the first source observed, 3C48 (the primary flux density and polarization angle calibrator source), is the brightest source in this observation. The next brightest is the second source observed, J2355+4950, a CSO and the secondary instrumental polarization calibrator. The complex gain calibrator J0259+0747 (shown in orange) is around 1 Jy. The target scans on 3C75 are colored in green. The spread of amplitudes is primarily due to the presence of extended structure, thus every baseline sees a slightly different amplitude.

Across the top of the left panel of the GUI are a set of tabs labelled Plot, Flag, Tools, Annotate, and Options. By default, the Plot tab is visible. There are a number of tabs running down the side of the left hand panel: Data, Calibration, Axes, Page, Transform, Display, and Canvas; these allow you to make changes to the plotting selection without having to re-launch plotms. Even if it was started with xaxis=' ' (defaulting to 'time'), you can choose a different X-axis by selecting the Axes tab, then using the dropdown menu to switch (for example) to xaxis='Frequency' (to get something sensible when plotting with frequency, channel averaging must be turned off).

You should spend several minutes displaying the data in various formats. You can save the version of the plotms plot as a graphics file by using the menu bar in the plotms GUI to select the Export... option under the Export menu.

Another example of using plotms for a quick look at your data, select the Data tab and specify field 2 (the complex gain calibrator J0259+0747) to display data associated with the target, then select the Axes tab and change the X-axis to be UVdist (baseline length in meters). Remove the channel averaging (Data tab), and plot the data using the Plot button at the bottom of the plotms GUI. The important observation is that the amplitude distribution is relatively constant as a function of UV distance or baseline length (i.e., [math]\displaystyle{ \sqrt{u^2+v^2} }[/math] ) (see Figure 2A). A relatively constant visibility amplitude as a function of baseline length means that the source is very nearly a point source. (The Fourier transform of a point source, i.e. a delta function, is a constant function.) You can see occasional spikes in the calibrated amplitudes. This is most likely caused by radio frequency interference that correlates on certain baselines. We will get to those further in the guide.

By contrast, if you make a similar plot for field 3 (our target 3C 75), the result is a visibility function that falls rapidly with increasing baseline length. Figure 2B shows this example, including time averaging of '1e6' seconds (any large number that encompasses more than a full scan will do). Such a visibility function indicates a highly resolved source. The baseline length at which the visibility function falls to some fiducial value (e.g., 1/2 of its peak value) gives a rough estimate of the angular scale of the source (Angular scale [in radians] ~ 1/baseline [in wavelengths]). To plot baseline length in wavelengths rather than meters, select UVwave as the X-axis parameter.

A final example is shown in Figure 2C. In this example, we have elected to show phase as a function of (frequency) channel for a single baseline (antenna='ea01&ea21' ) on the bandpass calibrator, field 0. If you choose to iterate by baseline (e.g., antenna='ea01' and iteraxis='baseline' ), you can see similar phase-frequency variations on all baselines. They center around zero phase, since we are looking at the calibrated visibilities, you are seeing, however, a butterfly shaped pattern with phase noise higher toward the channel edges. This pattern is due to a small mismatch in the delay measurement timing (also known as 'delay clunking') which is an internally generated effect and is typically averaged out over time.

Figure 2A: plotms view of amp vs. uvdist of J0259+0747, a point source
Figure 2B: plotms view of amp vs. uvwave of 3C 75, a resolved source
Figure 2C: plotms view of phase vs. channel on one baselines, showing phase delay across the calibrated bandpass

You can find similar plots in the CASA pipeline weblog under the task hifv_plotsummary. At this stage the pipeline has taken care of most of the calibration; there might be some remaining issues, though, that were not caught by the pipeline.

Figure 3: datastream view of MS

One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01. This shows, assuming that ea01 is in the entire observation, when various antennas drop out (see Figure 3).

# In CASA
plotms(vis='TDRW0001_calibrated.ms',field='',correlation='RR,LL',
       timerange='',antenna='ea01',spw='0:31',
       xaxis='time',yaxis='antenna2',
       plotrange=[-1,-1,0,26],coloraxis='field')

From this display you can immediately that flagging performed by the pipeline is present. In the following we note on a couple issues that you might have found and will take care of those through additional flagging.

Issues that you might find:
 - ea12, scan 17: amplitude spike at the end of the scan.
 - Residual RFI

We can flag this time period, by invoking the casa task flagdata. It is also a good idea to save the original flags before performing any flagging by setting flagbackup=True.

# In CASA
flagdata(vis='TDRW0001_calibrated.ms', flagbackup=True, mode='manual', antenna='ea12',scan='17',timerange='07:25:57~07:26:18')

You can check the effect of this flagging by replotting Figure 2A. The spikes we saw before on some baselines should have disappeared. If you plot frequency against amplitude without averaging, however, you will still see some channels with interference that we will need to flag, especially on the instrumental polarization calibrators. Polarization calibration is very sensitive to interference, especially in the cross-hand correlations RL,LR. The pipeline does not (yet) do a good job at this, therefore we will need to cover some additional flagging steps in the next section.

Additional Flagging

At first, we try to get a good sense of additional flagging that might be needed by plotting frequency against amplitude for the RR,LL and RL,LR polarizations of our calibrators, fields 0 through 2. In particular we need to pay attention to RL,LR (see Figure 4A). We will perform additional flagging on the target field at a later stage.

# In CASA
# for parallel hands
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RR,LL')
# for cross-hands
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RL,LR')
Figure 4a: plotms view of calibrators freq vs. amp RL/LR before additional flagging
Figure 4b: plotms view of calibrators freq vs. amp RL/LR after rflag

Since we are dealing with point sources, we do not have to worry about overflagging of shorter baselines, so we can run flagdata with mode='rflag' over the calibrator fields and cross-hand correlations to remove any residual RFI. For completeness, we also use mode='tfcrop' to reduce the amount of residual RFI in the parallel hands. This is not strictly needed at this point, since the polarization calibration is based on the cross-hand correlations.

# In CASA

# for the parallel hands
flagdata(vis='TDRW0001_calibrated.ms',
	 mode='tfcrop',
	 field='0~2',
	 correlation='',
	 freqfit='line',
	 extendflags=False,
	 flagbackup=False)

# for the cross-hands
flagdata(vis='TDRW0001_calibrated.ms',
	 mode='rflag',
	 datacolumn='data',
	 field='0~2',
	 correlation='RL,LR',
	 extendflags=True,
	 flagbackup=False)

As you can see in Figure 4B, this additional flagging step took care of most of the obvious residual RFI. We are now ready to move on to calibrate the visibilities for linear polarization.

Polarization Calibration

Polarization calibration is done in three steps:

  • First, we determine the instrumental delay between the two polarization outputs;
  • Second, we solve for the instrumental polarization (the frequency-dependent leakage terms ('D-terms')), using either an unpolarized source or a source which has sufficiently good parallactic angle coverage;
  • Third, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C48 here).

For information on polarization calibrators suitable for VLA observations, see the VLA Observing Guide on Polarimetry. The CASA related documentation also provides helpful information on polarization calibration steps and the different options that are available.

Before solving for the calibration solutions, we first use setjy to set the polarization model for our polarized position-angle calibrator. The pipeline only set the total intensity of the flux density calibrator source 3C48, which did not include any polarization information. This source is known to have a fairly stable linear fractional polarization (measured to be 2% in S-band around the time of the observations), a polarization position angle of -100 degrees at 3 GHz, and a rotation measure of -68 rad/m^2. Note at higher frequencies, 3C48 has had an outburst in 2017 and thus is expected to show a significant degree of variability. Since we have applied the pipeline calibration and not corrected for parallactic angle, we can continue polarization calibration using a split measurement set.

The setjy task will calculate the values of Stokes Q and U (in the reference channel) for user inputs of the reference frequency, Stokes I, polarization fraction, polarization angle, and rotation measure. The setjy input parameters can be obtained from Perley & Butler (2017) for Stokes I information and Perley & Butler (2013) for polarization information. Other sources can also be consulted, such as archival observations of variable polarization calibrators available under the project code TPOL0003 or TCAL0009. It is possible to capture a frequency variation in Q, U, and alpha terms by providing coefficients of polynomial expansion for polarization fraction, polarization angle, and spectral index as a function of frequency. At this time, it is left to the user to derive these coefficients, which can be accomplished by fitting a polynomial to observed values of the polarization fraction (here also called polarization index), polarization angle, and flux density (for the case of spectral index). Updated values of the broad band polarimetric information for the four calibration sources 3C48, 3C138, 3C147, and 3C286 (Of these sources, 3C48, 3C138, and 3C147 have been noticed to be variable) can be found at (https://science.nrao.edu/facilities/vla/docs/manuals/oss/performance/fdscale) and at (https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/pol). These coefficients are then passed to the setjy task as lists along with the reference frequency and the Stokes I flux density.

The calibrator used for this guide, 3C48, has a rotation measure and thus changes its Q and U with frequency. Therefore, for our purposes, it is not sufficient to use only the first Taylor term of the expansion. For deriving the setjy input parameters you can consult the setjy CASA documentation. Currently setjy only supports unresolved polarized emission models assuming that the Stokes I,Q,U peak are co-located on the sky. This is not necessarily the case for more complicated objects or even for 3C48 in extended VLA configurations.

# In CASA

# Reference Frequency for fit values
reffreq = '3.0GHz'
# Stokes I flux density
I =        8.45650174 
# Spectral Index
alpha =    [-0.90366565, -0.14262821]
# Polarization Fraction
polfrac = [0.021429,0.0391826,0.00234878,-0.0230125]
# Polarization Angle
polangle = [1.4215,1.36672,-2.12678,3.48384,-2.71914]

setjy(vis='TDRW0001_calibrated.ms',
      field='0137+331=3C48',
      spw='',
      selectdata=False,
      timerange="",
      scan="",
      intent="",
      observation="",
      scalebychan=True,
      standard="manual",
      model="",
      modimage="",
      listmodels=False,
      fluxdensity=[I,0,0,0],
      spix=alpha,
      reffreq=reffreq,
      polindex=polfrac,
      polangle=polangle,
      rotmeas=0,
      fluxdict={},
      useephemdir=False,
      interpolation="nearest",
      usescratch=True,
      ismms=False,
)
  • field='0137+331=3C48' : if the flux density calibrator is not specified then all sources will be assumed to have the input model parameters.
  • standard='manual' : the user will supply the flux density, spectral index, and polarization parameters rather than giving a model (the CASA models currently do not include polarization).
  • fluxdensity=[I,0,0,0] : you may provide values of Q and U rather than having setjy calculate them.However, if you set Q and U as input using the fluxdensity parameter, then the first value given in polindex or polangle will be ignored.
  • spix=[-0.90366565, -0.14262821] : set the spectral index using the value above. This will apply to all non-zero Spokes parameters. In this example, we only use the first two coefficients of the Taylor expansion.
  • reffreq='3.0GHz' : The reference frequency for the input Stokes values.
  • polindex=[0.021429,0.0391826,0.00234878,-0.0230125 : The coefficients of polynomial expansion for the polarization index as a function of frequency.
  • polangle=[1.4215,1.36672,-2.12678,3.48384,-2.71914] : The coefficients of polynomial expansion for the polarization angle as a function of frequency.
  • scalebychan=True: This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.
  • usescratch=True: DO create/use the MODEL_DATA column explicitly. (usescratch=False saves disk space by not filling the model column)

The Stokes V flux has been set to zero, corresponding to no circular polarization.

setjy returns a Python dictionary (CASA record) that reports the Stokes I, Q, U and V terms. This is reported to the CASA command line window:

{'0': {'0': {'fluxd': array([ 9.99287353, -0.08937082,  0.11939692,  0.        ])},
  '1': {'fluxd': array([ 9.55959057, -0.11709484,  0.10568676,  0.        ])},
  '2': {'fluxd': array([ 9.16182831, -0.13997047,  0.08921149,  0.        ])},
  '3': {'fluxd': array([ 8.7953302 , -0.15846661,  0.07143732,  0.        ])},
  '4': {'fluxd': array([ 8.45650174, -0.1731959 ,  0.05330882,  0.        ])},
  '5': {'fluxd': array([ 8.14228548, -0.1847571 ,  0.03537654,  0.        ])},
  '6': {'fluxd': array([ 7.85006343, -0.193661  ,  0.01792025,  0.        ])},
  '7': {'fluxd': array([  7.57758019e+00,  -2.00307499e-01,   1.05166484e-03,
            0.00000000e+00])},
  'fieldName': '0137+331=3C48'},
 'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}

Alternatively, you may capture this dictionary in a return variable, if you call setjy as myset=setjy(...).

We can see the results in the model column in plotms (Figure 5A) showing the model source spectrum:

# In CASA
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RR',
       timerange='',antenna='ea01&ea02',
       xaxis='frequency',yaxis='amp',ydatacolumn='model')

We can see this translates to the spectrum in QU (Figure 5B):

# In CASA
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',
       timerange='',antenna='ea01&ea02',
       xaxis='frequency',yaxis='amp',ydatacolumn='model')

Finally, our R-L phase difference is constant at 66 degrees (twice the polarization angle) as desired (Figure 5C):

# In CASA
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',
       timerange='',antenna='ea01&ea02',
       xaxis='frequency',yaxis='phase',ydatacolumn='model')