https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Akapinsk&feedformat=atomCASA Guides - User contributions [en]2024-03-29T01:47:38ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=VLA_Polarization_pipe_Tutorial&diff=35293VLA Polarization pipe Tutorial2023-06-20T22:34:34Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
== Data Set ==<br />
<br />
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=3C75]. The observations were performed 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.<br />
<br />
Prior to the synthesis imaging workshop you should have received instructions to download the data for this tutorial. If you have not already, you will need to untar and unzip the file using the command: 'tar -xzvf TDRW0001_calibrated_CASA6.4.1.ms.tgz' and then give it the same name as the guide uses: 'mv TDRW0001_calibrated_CASA6.4.1.ms TDRW0001_calibrated.ms'. <br />
<br />
The first step of polarization calibration is to first obtain a decent Stokes I (RR and LL) calibration. This has already been done for you by running the raw data through the CASA 6.4.1 version of the VLA pipeline. One additional step was required which involved removing the parallactic angle correction that was applied by the standard pipeline. For those familiar with the VLA pipeline, we essentially repeated what pipeline tasks hifv_applycals, hifv_targetflag, and hifv_statwt did, but disabled the application of parallactic angle corrections.<br />
<br />
<br />
== The Observation ==<br />
<br />
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, we can take a look at the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log], but in order to get to our observation we'll need the date it was observed on. The CASA task to use to get that information, and other very useful information on the setup of the observation is: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html?highlight=listobs listobs].<br />
<br />
Once you've gotten the date of observation for this data set find its [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log] and note the two antennas that had issues during the observation.<br />
<br />
Before beginning our polarization calibration, we should inspect the pipeline calibration weblog for any obvious issues. You can download the weblog from ['https://casa.nrao.edu/Data/VLA/Polarization/SIW19pipeline-20230103T175723.tgz '] or view it through a browser [https://casa.nrao.edu/Data/VLA/Polarization/pipeline-20230103T175723/html/ here]. For those not familiar with viewing these weblogs, they are basically a little report that is meant to help judge how well the VLA pipeline did with its calibration. Feel free to explore it as you wish, but you'll likely find two of the more useful stages to look at are hifv_finalcals (plots of the final solution tables) and hifv_plotsummary (various plots of the calibrated data). For more details on the pipeline output you can have a look at the [https://casaguides.nrao.edu/index.php?title=VLA-S-CASA_Pipeline-CASA6.4.1 VLA CASA Pipeline Guide].<br />
<br />
You will likely note that there are four sources observed. Here the sources are introduced briefly, with more detail contained in the sections below in which they are used:<br />
* 0137+331=3C48, which will serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have precisely known flux density, the spectral bandpass, and the polarization position angle;<br />
* J0259+0747, which will serve as a calibrator for the visibility phases and can be used to determine the instrumental polarization;<br />
* J2355+4950, which can serve as a secondary instrumental polarization calibrator or to check residual instrumental polarization, and;<br />
* 3C75, which is the science target.<br />
<br />
Both to get a sense of the array, as well as identify the location of the reference antenna that we told the pipeline to choose for parallel hand calibration, have a look at the antenna setup page of the weblog. For calibration purposes, you would generally 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!). <br />
<br />
<br />
Can you tell which antenna we chose for our reference antenna?<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Answer</div><br />
<div class="mw-collapsible-content"><br />
The reference antenna by definition has its delays and phases set to zero. So by looking at those solution tables in the hifv_finalcals stage we can see that ea10 was our reference antenna.<br />
</div></div><br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration. 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. <br />
<br />
We will start by making a simple overview plot.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms', selectdata=True, correlation='RR', averagedata=True, avgchannel='64', coloraxis='field', plotfile='colorbyfield.jpeg')<br />
</source><br />
[[Image:Colorbyfield_CASA6.2.1.jpeg|200px|right|thumb|Figure 1: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR' '': Plot only the right-handed (left-handed omited only for speed) polarization products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
The default x- and y-axis parameters are 'time' and 'amp', so the above call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 been left to defaults, but it is possible to select them from within the plotms GUI. <br />
<br />
Based on what you've learned from the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html?highlight=listobs listobs] task you should be able to tell which sources are which in the plot.<br />
<br />
Another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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. <br />
<br />
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, we want to fully average each scan). Such a visibility function indicates a highly resolved source. To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter.<br />
<br />
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, and non-averaged data. 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, because we are looking at the calibrated visibilities; however, you are seeing 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. <br />
{|<br />
| [[File:Plotms-J0259+0747-Amp-vs-UVdist-CASA6.2.1.jpeg|200px|left|thumb|Figure 2A: plotms view of amp vs. uvdist of J0259+0747, a point source]]<br />
| [[File:Plotms-3C75-Amp-vs-UVwave-CASA6.2.1.jpeg|200px|center|thumb|Figure 2B: plotms view of amp vs. uvwave of 3C 75, a resolved source]]<br />
| [[File:Plotms-3C48-delays-ea01ea21_CASA6.2.1.jpeg|200px|right|thumb|Figure 2C: plotms view of phase vs. channel on one baselines, showing phase delay across the calibrated bandpass]]<br />
|}<br />
<br />
<br />
On Figure 1 you'll notice that the sources colored in black and green show much more spread in amplitude as compared to the others. Do you know the cause of this?<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Answer</div><br />
<div class="mw-collapsible-content"><br />
The black source is our flux density scale and bandpass calibrator, 3C48, and the green source is our target, 3C75. As we saw in Figure 2B, the spread in amplitude of 3C75 is primarily due to the presence of extended structure, that is to say, every baseline sees a slightly different amplitude. However if you make a similar plot of 3C48 you'll notice it is a point source. The spread on it is due to its spectral index (coloring by spectral window should make this stand out).<br />
</div></div><br />
<br />
<br />
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. In the following we note a couple issues that you might have found while inspecting data in this section. We will take care of those through additional flagging.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Issues that you might find:<br />
- ea12, scan 17: amplitude spike at the end of the scan (can be spotted already in Figure 1)<br />
- Residual RFI (see Figure 2A)<br />
</pre><br />
<br />
In the case of the amplitude spike, we can flag the affected time period by invoking the casa task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata]. It is a good idea to save the original flags before performing any flagging by setting '''flagbackup=True'''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TDRW0001_calibrated.ms', flagbackup=True, mode='manual', antenna='ea12',scan='17',timerange='07:25:57~07:26:18')<br />
</source><br />
<br />
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 a good job at this, but there are still some RFI left; we will perform some additional flagging steps in the next section. <br />
<br />
=== Additional Flagging ===<br />
<br />
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). You will notice some left over RFI on the bandpass calibrator in RR, LL. However, we also need to pay particular attention to RL, LR (see Figure 4A). Here we consider calibrators only; we will perform additional flagging on the target field at a later stage. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# for parallel hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RR,LL')<br />
# for cross-hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RL,LR')<br />
</source> <br />
<br />
{|<br />
| [[File:Plotms-preflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|left|thumb|Figure 4a: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency before additional flagging]]<br />
| [[File:Plotms-rflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|right|thumb|Figure 4b: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency after an additional run of rflag]]<br />
|}<br />
<br />
Since we are dealing with point sources, we do not have to worry about overflagging of shorter baselines, so we can run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# for the parallel hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='tfcrop',<br />
field='0~2',<br />
correlation='',<br />
freqfit='line',<br />
extendflags=False,<br />
flagbackup=False)<br />
<br />
# for the cross-hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='rflag',<br />
datacolumn='data',<br />
field='0~2',<br />
correlation='RL,LR',<br />
extendflags=True,<br />
flagbackup=False)<br />
</source> <br />
<br />
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.<br />
<br />
== Polarization Calibration ==<br />
<br />
<pre style="background-color: #fffacd;"><br />
Polarization calibration is done in three steps:<br />
<br />
* First, we determine the instrumental delay between the two polarization outputs;<br />
<br />
* 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;<br />
<br />
* Third, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C48 here). <br />
</pre><br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The pipeline only set the total intensity (Stokes I) 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 that 3C48 had an outburst in 2017 and is expected to show a significant degree of variability at higher frequencies in the first instance, progressively affecting lower frequencies as time passes since the event. <br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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. 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. In general, 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). These coefficients are then passed to the setjy task as lists along with the reference frequency and the Stokes I flux density.<br />
<br />
As an example on how to derive the polarization parameters for the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call, you can perform the following next steps or jump right to the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call below. <br />
<br />
=== Deriving the Polarization Properties of the Polarization Angle Calibrator ===<br />
<br />
First, we tabulate the frequency dependent Stokes I flux density, polarization fraction, and polarization angle in a textfile, which we will call 3C48.dat. The data is taken from [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/flux-density-scale-polarization-leakage-polarization-angle-tables] and the corresponding Stokes I value is calculated from the Perley & Butler (2017) scale. <br />
<br />
<pre><br />
# Frequency I P.F. P.A.<br />
# (GHz) (Jy) (rad)<br />
1.022 20.68 0.00293 0.07445<br />
1.465 15.62 0.00457 -0.60282<br />
1.865 12.88 0.00897 0.39760<br />
2.565 9.82 0.01548 -1.97046<br />
3.565 7.31 0.02911 -1.46542<br />
4.885 5.48 0.04286 -1.24875<br />
6.680 4.12 0.05356 -1.15533<br />
8.435 3.34 0.05430 -1.10638<br />
11.320 2.56 0.05727 -1.08602<br />
14.065 2.14 0.06097 -1.09597<br />
16.564 1.86 0.06296 -1.11891<br />
19.064 1.67 0.06492 -1.18266<br />
25.564 1.33 0.07153 -1.25369<br />
32.064 1.11 0.06442 -1.32430<br />
37.064 1.00 0.06686 -1.33697<br />
42.064 0.92 0.05552 -1.46381<br />
48.064 0.82 0.06773 -1.46412<br />
</pre><br />
<br />
Now to fit Stokes I, we execute in CASA the following commands. These could also be put into a text file and run from inside the CASA prompt using [https://casadocs.readthedocs.io/en/v6.4.1/api/casashell/execfile.html?highlight=execfile#casashell.execfile execfile].<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def S(f,S,alpha,beta):<br />
return S*(f/3.0)**(alpha+beta*np.log10(f/3.0))<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(S, data[0:6,0], data[0:6,1])<br />
print('I@3GHz', popt[0], ' Jy')<br />
print('alpha', popt[1])<br />
print('beta', popt[2])<br />
print( 'Covariance')<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,1], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), S(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Flux Density (Jy)')<br />
plt.show()<br />
<br />
</source><br />
<br />
This will generate a plot for visual inspection, as well as the following text output. <br />
<br />
<pre><br />
I@3GHz 8.555570817459328 Jy<br />
alpha -0.8863795595286049<br />
beta -0.14320026298724836<br />
Covariance<br />
[[1.30835675e-04 1.69587670e-05 2.05918186e-06]<br />
[1.69587670e-05 1.36709052e-05 2.62217377e-05]<br />
[2.05918186e-06 2.62217377e-05 6.27504685e-05]]<br />
</pre><br />
<br />
This provides the coefficients for Stokes I flux density at 3 GHz, the spectral index (alpha), and curvature (beta). It also provides the covariance matrix for the fit.<br />
<br />
We repeat the same for the polarization fraction.<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PF(f,a,b,c,d):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(PF, data[0:6,0], data[0:6,2])<br />
print("Polfrac Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,2], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), PF(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Fraction')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polfrac Polynomial: [ 0.02152856 0.03937167 0.003804 -0.01969663]<br />
Covariance<br />
[[ 2.52776017e-07 3.20765692e-07 -7.13270651e-07 -8.06571096e-07]<br />
[ 3.20765692e-07 4.07949498e-06 -5.46918397e-07 -1.05897559e-05]<br />
[-7.13270651e-07 -5.46918397e-07 3.26372075e-06 1.85490535e-06]<br />
[-8.06571096e-07 -1.05897559e-05 1.85490535e-06 3.07101526e-05]]<br />
</pre><br />
<br />
<source lang="python"><br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PA(f,a,b,c,d,e):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3+e**((f-3.0)/3.0)**4<br />
<br />
# Fit 2 - 9 GHz data points<br />
popt, pcov = curve_fit(PA, data[2:8,0], data[2:8,3])<br />
print("Polangle Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[2:8,0], data[2:8,3], 'ro', label='data')<br />
plt.plot(np.arange(1,9,0.1), PA(np.arange(1,9,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Angle (rad)')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polangle Polynomial: [-2.5929737 -2.03374017 5.20812942 -2.01696093 0.30491012]<br />
Covariance<br />
[[ 0.46219415 0.41124375 -1.26430855 0.50302926 -0.34715067]<br />
[ 0.41124375 6.58090631 9.88051382 -7.56477931 -17.11605473]<br />
[ -1.26430855 9.88051382 58.3052678 -35.16883692 -58.08218227]<br />
[ 0.50302926 -7.56477931 -35.16883692 21.77461974 37.45331953]<br />
[ -0.34715067 -17.11605473 -58.08218227 37.45331953 72.39830352]]<br />
</pre><br />
<br />
You'll notice that the fit for the polarization angle is much less smooth than the other fits. There appears to be something wrong with the first data point in our selection. Something special needs to happen to this point. There is a concept known as the <math>N\pi</math> ambiguity issue in polarimetry. You are encouraged to read more about this concept and see if you can figure out how to recover this data point.<br />
<br />
=== Setting the Polarization Calibrator Models ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Reference Frequency for fit values<br />
reffreq = '3.0GHz'<br />
# Stokes I flux density<br />
I = 8.55557<br />
# Spectral Index<br />
alpha = [-0.8864, -0.1432]<br />
# Polarization Fraction<br />
polfrac = [0.02152856, 0.03937167, 0.003804, -0.01969663]<br />
# Polarization Angle<br />
polangle = [-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514]<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='0137+331=3C48',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[I,0,0,0],<br />
spix=alpha,<br />
reffreq=reffreq,<br />
polindex=polfrac,<br />
polangle=polangle,<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
* ''field='0137+331=3C48' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''spix=alpha=[-0.8864, -0.1432] '': 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.<br />
* ''reffreq='3.0GHz' '': The reference frequency for the input Stokes values.<br />
* ''polindex=polfrac=[0.02152856, 0.03937167, 0.003804, -0.01969663] '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=polangle=[-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514] '': The coefficients of polynomial expansion for the polarization angle as a function of frequency (only acquirable with proper derotation).<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=True'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space by not filling the model column, however due to current bugs it is suggested to not use it)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<pre><br />
{'0': {'0': {'fluxd': array([10.07724056, 0.15082879, 0.01240901, 0. ])},<br />
'1': {'fluxd': array([9.64869223, 0.15381396, 0.04441096, 0. ])},<br />
'2': {'fluxd': array([9.25487752, 0.15053557, 0.07574993, 0. ])},<br />
'3': {'fluxd': array([8.89166708, 0.14187061, 0.10510616, 0. ])},<br />
'4': {'fluxd': array([8.55557 , 0.12889591, 0.13157306, 0. ])},<br />
'5': {'fluxd': array([8.24361379, 0.11273472, 0.15463414, 0. ])},<br />
'6': {'fluxd': array([7.95325066, 0.09444074, 0.17410041, 0. ])},<br />
'7': {'fluxd': array([7.68228356, 0.0749225 , 0.19002888, 0. ])},<br />
'fieldName': '0137+331=3C48'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 5A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RR',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 5B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
</source><br />
<br />
Finally, we plot our R-L phase differences, which should be twice the value of the polarization angle without other complications such as the <math>N\pi</math> ambiguity (Figure 5C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='model')<br />
</source><br />
<br />
{| <br />
| [[Image:Plotms-3C48-model-amp-RR-CASA6.4.1.png|200px|thumb|left|Figure 5A: Model RR amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-amp-RL-CASA6.4.1.png|200px|thumb|center|Figure 5B: Model RL amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-phs-RL-CASA6.4.1.png|200px|thumb|right|Figure 5C: Model RL phases of 3C48.]]<br />
|}<br />
<br />
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). The model values of the two D-term calibrators can be obtained from the pipeline weblog under the task hifv_fluxboot inside the [https://casa.nrao.edu/Data/VLA/Polarization/pipeline-20230103T175723/html/t2-4m.html?sidebar=sidebar_stage12&ms=all&subpage=t2-4m_details.html CASA log] associated with that task. Take this opportunity to try to find them. We've purposely removed the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] calls in the log so as to not spoil the fun. While not specific to polarization calibration, this exercise should reveal an important aspect of the VLA pipeline: It sets a correct Stokes I model of the secondary calibrators before the final calibration tables are produced (you may appreciate this difference more if you also participated in the Continuum Tutorial and remember how it handled the flux density scale calibration for the secondary calibrators). Your goal when looking over the log is to figure out where the pipeline is getting the inputs for [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] from. Once you've found the relevant lines in the log try to make up the setjy calls on your own. <br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">The casapy.log lines of interest and setjy calls</div><br />
<div class="mw-collapsible-content"><br />
<pre style="background-color: #fffacd;"><br />
2023-01-03 19:07:54 INFO fluxscale:::: Fitted spectrum for J2355+4950 with fitorder=2: Flux density = 1.76871 +/- 0.000646066 (freq=2.98457 GHz) spidx: a_1 (spectral index) =-0.599569 +/- 0.00275835 a_2=-0.196812 +/- 0.0670986 covariance matrix for the fit: covar(0,0)=8.14129e-08 covar(0,1)=-1.12826e-07 covar(0,2)=-2.46336e-05 covar(1,0)=-1.12826e-07 covar(1,1)=2.4614e-05 covar(1,2)=0.000242613 covar(2,0)=-2.46336e-05 covar(2,1)=0.000242613 covar(2,2)=0.0145649<br />
<br />
2023-01-03 19:07:55 INFO fluxscale:::: Fitted spectrum for J0259+0747 with fitorder=2: Flux density = 0.970568 +/- 0.000712514 (freq=2.98457 GHz) spidx: a_1 (spectral index) =0.169919 +/- 0.00510126 a_2=-0.143294 +/- 0.134104 covariance matrix for the fit: covar(0,0)=1.87159e-06 covar(0,1)=-2.56746e-06 covar(0,2)=-0.000583154 covar(1,0)=-2.56746e-06 covar(1,1)=0.000479139 covar(1,2)=-9.51772e-05 covar(2,0)=-0.000583154 covar(2,1)=-9.51772e-05 covar(2,2)=0.331122<br />
</pre><br />
<br />
This translates to the following [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] calls.<br />
<br />
<source lang="python"><br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J2355+4950',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[1.76871, 0, 0, 0],<br />
spix=[-0.599569, -0.196812],<br />
reffreq="2.98457GHz",<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J0259+0747',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[0.970568, 0, 0, 0],<br />
spix=[0.169919, -0.143294],<br />
reffreq='2.98457GHz',<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
</div></div><br />
<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
Just as the pipeline did for the parallel-hand (RR,LL) delays before bandpass calibration, we solve for the cross-hand (RL,LR) delays because of the residual delay difference between the R and L on the reference antenna used for the original delay calibration (''ea10'' in this tutorial). 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]. Since the release of CASA 6.1.2, 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 (here 8 spectral windows 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Solve using Multiband Delay<br />
kcross_mbd = "TDRW0001_calibrated.Kcross_mbd" <br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_mbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan,<?>",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
<br />
# Solve using Single Band Delay<br />
kcross_sbd = "TDRW0001_calibrated.Kcross_sbd"<br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_sbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
</source><br />
<br />
<br />
These commands essentially only differ with how the 'combine' parameter is defined. Based on the description above what should this parameter be in order to fit across the entire baseband?<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Answer</div><br />
<div class="mw-collapsible-content"><br />
The only real difference between the commands is that the first is using the entire baseband as input to create one solution and the second is using each spectral window to get individual solutions. In order to tell CASA to combine all of the spectral windows (and scans in this case) one simply has to use: combine='scan,spw'.<br />
</div></div><br />
<br />
<br />
[[Image:Plotms-3C48-Kcross-delay-CASA6.4.1.png|200px|thumb|right|Figure 6: Single band cross-hand delay solutions.]]<br />
We can plot the single band solutions (see Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=kcross_sbd,xaxis='frequency',yaxis='delay',antenna='ea10',coloraxis='corr')<br />
</source><br />
You can also look at the solutions reported in the logger.<br />
<br />
<pre style="background-color: #fffacd;"><br />
For multiband delay there is one solution:<br />
Multi-band cross-hand delay=3.68373 nsec<br />
<br />
For single band delay there are 8 solutions:<br />
Spw=0 Global cross-hand delay=5.58964 nsec<br />
Spw=1 Global cross-hand delay=1.49907 nsec<br />
Spw=2 Global cross-hand delay=-1.26208 nsec<br />
Spw=3 Global cross-hand delay=0.522402 nsec<br />
Spw=4 Global cross-hand delay=4.25883 nsec<br />
Spw=5 Global cross-hand delay=1.25194 nsec<br />
Spw=6 Global cross-hand delay=3.69895 nsec<br />
Spw=7 Global cross-hand delay=3.02677 nsec<br />
</pre><br />
<br />
Notice that the per spectral window solutions are very scattered. The mean delay is 2.32 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.68 ns.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 also our complex gain calibrator. <br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# J2355+4950 / Df<br />
dtab_J2355 = 'TDRW0001_calibrated.Df' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J2355,<br />
field='J2355+4950',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
<br />
# J0259+0747 / Df+QU<br />
dtab_J0259 = 'TDRW0001_calibrated.DfQU' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J0259,<br />
intent='CALIBRATE_POL_LEAKAGE#UNSPECIFIED',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df+QU',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
</source><br />
<br />
* ''caltable '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal] will create a new calibration table containing the leakage solutions, which we specify with the ''caltable'' parameter.<br />
* ''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.<br />
* ''spw='0~7' '': Select all spectral windows.<br />
* ''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.<br />
* ''solint='inf,2MHz', combine='scan' '': One solution over the entire run, per spectral channel of 2 MHz<br />
* ''gaintable=['kcross_mbd']'': The previous Kcross multiband delay is applied <br />
* ''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' '').<br />
<br />
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.<br />
<pre style="background-color: #fffacd;"><br />
Fractional polarization solution for J0259+0747 (spw = 0): : Q = 0.0259049, U = 0.0336301 (P = 0.0424505, X = 26.1967 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 1): : Q = 0.0139972, U = 0.0382244 (P = 0.0407066, X = 34.944 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 2): : Q = 0.0165052, U = 0.0384224 (P = 0.0418175, X = 33.3765 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 3): : Q = 0.0118274, U = 0.0422875 (P = 0.0439104, X = 37.1871 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 4): : Q = 0.00816816, U = 0.0404744 (P = 0.0412903, X = 39.2952 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 5): : Q = 0.00649365, U = 0.0412879 (P = 0.0417954, X = 40.5309 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 6): : Q = -0.00225595, U = 0.0429258 (P = 0.0429851, X = 46.5042 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 7): : Q = -0.00776873, U = 0.0474773 (P = 0.0481087, X = 49.6465 deg)<br />
</pre><br />
<br />
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 26 to 49 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' ''. <br />
<br />
After we run the two executions of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to ensure that everything looks good and to compare the results using two different calibrators and poltype methods.<br />
{|<br />
|[[Image:Plotms-J0259-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7a: J0259+0747 Df amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7b: J2355+4950 Df+QU amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J0259-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7c: J0259+0747 Df phase vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7d: J2355+4950 Df+QU phase vs. frequency for antenna ea01.]]<br />
|}<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J2355,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J0259,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
plotms(vis=dtab_J2355,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
</source><br />
This will produce plots similar to those shown in Figures 7A-D. You can cycle through the antennas by clicking the Next button within [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. You should see leakages of between 5&ndash;17% 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. <br />
<br />
We can also display these in a single plot versus antenna index (see Figure 8):<br />
[[Image:Plotms-J0259-DfQU-CASA6.4.1.png|thumb|Figure 8: Df+QU solutions for J0259+0747 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], but this time set parameter ''poltype='Xf', ''which specifies a frequency-dependent (''f'') position angle (''X'') calibration using the source 3C48, the position angle of which is known, having set this earlier with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
xtab = "TDRW0001_calibrated.Xf"<br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=xtab,<br />
spw='0~7',<br />
field='0137+331=3C48',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
poltype='Xf',<br />
refant = 'ea10',<br />
gaintable=[kcross_mbd,dtab_J0259],<br />
gainfield=['',''],<br />
spwmap=[[0,0,0,0,0,0,0,0],[]],<br />
append=False)<br />
</source><br />
<br />
[[Image:Plotms-3C48-Xf-CASA6.4.1.png|thumb|Figure 9: Xf solutions versus frequency.]]<br />
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 refant when performing polarization calibration.<br />
<br />
It is strongly suggested you check that the calibration worked properly by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 9):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=xtab,xaxis='frequency',yaxis='phase',coloraxis='spw')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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. <br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = 'TDRW0001_calibrated.ms',<br />
field='',<br />
gainfield=['', '', ''], <br />
flagbackup=True,<br />
interp=['', '', ''],<br />
gaintable=[kcross_mbd,dtab_J0259,xtab],<br />
spw='0~7', <br />
calwt=[False, False, False], <br />
applymode='calflagstrict', <br />
antenna='*&*', <br />
spwmap=[[0,0,0,0,0,0,0,0],[],[]], <br />
parang=True)<br />
<br />
</source><br />
<br />
* ''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; here derived from J0259+0747), and the R-L phase corrections (xtab).<br />
* ''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; 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''.<br />
* ''parang '': If polarization calibration has been performed, set parameter ''parang=True''.<br />
<br />
<br />
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 10A-F). Now that you've used [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] a few times try making the below plots on your own. The only bit of information you cannot derive from the figures themselves is that we have averaged them in time by 60 seconds.<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:1000px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Plotms Calls</div><br />
<div class="mw-collapsible-content"><br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='RR,LL',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J0259-fld2-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',avgbaseline=True,<br />
plotfile='Plotms-J0259-fld2-corrected-phase-CASA6.4.1.jpeg')<br />
</source><br />
</div></div><br />
<br />
<br />
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. <br />
<br />
{|<br />
| [[Image:Plotms-3C48-fld0-corrected-amp-CASA6.4.1.png|thumb|Figure 10A: amplitude vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-3C48-fld0-corrected-phase-CASA6.4.1.png|thumb|Figure 10B: phase vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-amp-CASA6.4.1.png|thumb|Figure 10C: amplitude vs channel for J2355+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-phase-CASA6.4.1.png|thumb|Figure 10D: phase vs channel for J2355+4950 RR,LL]]<br />
|}<br />
<br />
{|<br />
| [[Image:Plotms-J0259-fld2-corrected-amp-CASA6.4.1.png|thumb|Figure 10E: amplitude vs channel for J0259+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J0259-fld2-corrected-phase-CASA6.4.1.png|thumb|Figure 10F: phase vs channel for J0259+4950 RR,RL,LR,LL with baseline averaging]]<br />
|}<br />
<br />
<br />
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. <br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='TDRW0001_calibrated.ms',outputvis='3C75.ms',<br />
datacolumn='corrected',field='3')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science target.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to place the target field into a measurement set for imaging and joint deconvolution.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms',datacolumn='data',minsamp=8)<br />
</source><br />
<br />
= Imaging =<br />
<br />
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. 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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly calibrated, target-only data set:<br />
<br />
[[Image:plotms_3c75-uvwave-CASA6.4.1.png|thumb|Figure 11: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C75 at 3000 MHz]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvwave.jpeg',avgspw=False,overwrite=True)<br />
</source><br />
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 will also see some outliers there which are primarily from residual amplitude errors of ea05, that had a warm receiver which we can isolate to particular time periods. We will be addressing this after the initial imaging. <br />
<br />
<br />
Based on the UVwave plot can you determine approximately what the smallest angular scale of the image will be?<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Answer</div><br />
<div class="mw-collapsible-content"><br />
We can see in the plot that the maximum baseline is about 12,000 wavelengths. If we recall that the VLA works via diffraction then it follows that: <math>\theta\approx\lambda/D=1/12000 radians\approx17 arcsec</math>.<br />
Furthermore, the most effective cleaning occurs with 3&ndash;5 pixels across the synthesized beam. So for this data a cell size of 3.4 arcseconds will give just about 5 pixels per beam.<br />
</div></div><br />
<br />
<br />
The 3C75 binary black hole system is known to have a maximum extent of at least 8-9 arcminutes, corresponding to about 147 pixels for the chosen cell size. Therefore, we need to choose an image size that covers most of the extent of the source. We therefore set ''imsize=[480,480]'' and the source will fit comfortably within that image.<br />
<br />
In this tutorial, we will run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
[[Image:3C75-tclean-interactive-start-CASA6.2.1.png|thumb|Figure 12: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required. The below is an explanation of several of the parameters we've used.<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">tclean parameters</div><br />
<div class="mw-collapsible-content"><br />
* ''vis='3C75.ms' '': this split MS contains the target field only.<br />
* ''imagename='3C75_initial' '': our output image cubes will all start with this name root, e.g., 3C75_initial.image<br />
* ''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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] task define an appropriate threshold. The number of iterations should then be set high enough to reach the threshold found by tclean.<br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer] window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=480,cell='3.4arcsec' '': See the discussion above regarding setting the image size and cell size. If only one value is specified for the parameter, the same value is used in both directions (declination and right ascension).<br />
* ''stokes='IQUV' '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will output an image cube containing all: total intensity I, and Stokes Q, U, and V.<br />
* ''deconvolver='mtmfs', scales=[0, 6, 18], smallscalebias=0.9 '': The settings for ''scales'' 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
</div></div><br />
<br />
[[Image:3C75-tclean-interactive-300iters-CASA6.2.1.png|thumb|Figure 13: After the first approximately 300 iterations of multi-scale mfs clean]]<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, an [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.imview.html imview] 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. Similarly, select "All channels". 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 radio galaxy jets. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will do before returning to the GUI (''cycleniter''). 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 ''cycleniter'' value that you might had set before starting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3C75-tclean-interactive-residuals-CASA6.2.1.png|thumb|Figure 14: Interactive residuals after about 13000 iterations of multi-scale mfs clean]]<br />
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 cleaned mask region). As mentioned before, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also. You see that there is a significant amount of residual structure (the various spikes and streaks throughout the image), these are most likely due to calibration errors which we will try to correct for in the next section during self-calibration.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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)<br />
* ''.pb.tt0'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.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)<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
* ''.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)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
<br />
{|<br />
|[[Image:3c75-CARTA-multiscale-initialI-CASA6.4.1.png|thumb|Figure 15A: Viewer panel of final restored Stokes I image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialQ-CASA6.4.1.png|thumb|Figure 15B: Viewer panel of final restored Stokes Q image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialU-CASA6.4.1.png|thumb|Figure 15C: Viewer panel of final restored Stokes U image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialV-CASA6.4.1.png|thumb|Figure 15D: Viewer panel of final restored Stokes V image (using viridis colormap, linear scale, 99.9%)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use [https://cartavis.org/ CARTA] to look at your image.<br />
<br />
Take some time to play with the color scale to better emphasize the faint emission and to see the underlying noise patterns. For the figures above we selected the viridis color map, the linear scale function, and the 99.9% data range on the histogram. You can also use the Animators slider/buttons to switch between the four different Stokes parameter images that were computed. If you are unfamiliar with [https://cartavis.org/ CARTA] then take some time to look over its extensive built in documentation and help features. You can find its searchable online manual via the "Help" button at the top or to get more information on a particular widget you can click the corresponding "?" button near it. If you click the Animator tab you'll also notice that [https://cartavis.org/ CARTA] attempts to create total polarization, linear polarization, fractional total polarization, fractional linear polarization, and linear polarization angle images for you. This can be quite convenient, but we'll show how to create these yourself later in this guide.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 response fall-off in the edges. In principle, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] produces primary beam response image, and if we had set parameter ''pbcor=True'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] would had saved a primary beam corrected restored image of our target. Since we used ''deconvolver='mtmfs' '' and ''nterms=2'', the calculation of the primary beam response requires special treatment. To perform wideband primary beam correction, we will use task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. In the future this task will be incorporated into [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but until then this separate task needs to be used.<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms',imagename='3C75_initial',nterms=2, action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
The task will produce primary beam corrected images of our target (3C75_initial.pbcor.image.tt0, 3C75_initial.pbcor.image.tt1, 3C75_initial.pbcor.image.alpha, 3C75_initial.pbcor.image.alpha.error). You can open image 3C75_initial.pbcor.image.tt0 in [https://cartavis.org/ CARTA], and compare it to screenshots in Figure 15. You will see noise (and signal) at the edges of the image has indeed increased.<br />
<br />
== Self-Calibration ==<br />
<br />
Before we get started with self-calibration, it might be good to check whether we need to perform 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. The division will help us to see low level interfrence we might not otherwise notice by just looking at the data column. 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvdist_resid_RR.png',avgspw=False,overwrite=True)<br />
<br />
# If you made a mistake above and didn't clean the polarization as well, then this plot will be empty.<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RL',<br />
plotfile='plotms_3c75-uvdist_resid_RL.png',avgspw=False,overwrite=True)<br />
</source><br />
<br />
{|<br />
| [[Image:plotms-3c75-uvdist-residRR-CASA6.4.1-corr.png|thumb|Figure 16A: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RR correlations.]]<br />
| [[Image:plotms-3c75-uvdist-residRL-CASA6.4.1-corr.png|thumb|Figure 16B: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RL correlations.]]<br />
|}<br />
<br />
Since we are seeing a significant amount of weak residual interference, we will take a few steps to reduce these. <br />
<source lang="python"><br />
# In CASA<br />
<br />
# tfcrop<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RR,ABS_LL',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RL,ABS_LR',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
# rflag<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RR,LL',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RL,LR',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
# extend flags<br />
flagdata(vis='3C75.ms',mode='extend',flagbackup=False)<br />
</source><br />
<br />
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 our dataset. <br />
<br />
'''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. <br />
<br />
<br />
For an array of <math>N</math> antennas there are at any given instant only <math>N</math> gain factors, but how many visibilities?<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Answer</div><br />
<div class="mw-collapsible-content"><br />
<math>{N(N-1) \over 2}</math><br />
<br />
Since we are only considering one instance of time (i.e. one integration) this is also the number of baselines in the array. For a typical 27 antenna VLA observation that comes out to 351.<br />
</div></div><br />
<br />
<br />
For an array with a reasonable number of antennas, <math>N</math> >~ 8, solutions to this set of coupled equations converge quickly. There is some discussion in the old CASA Reference Manual on [http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#section%3Aim.selfcal self calibration] (see Section 5.11), but more detailed discussion can be found in lectures on [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-stsci/cde_selfcal.pdf Self-calibration] given at NRAO community days. <br />
<br />
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 DATA column of the new MS is set to be equal the previous MS's CORRECTED_DATA column. The self-calibration procedure is then: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the (corrected copy) DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
** 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column to form a new CORRECTED_DATA column ''overwriting'' the previous contents of CORRECTED_DATA should it exist.<br />
<br />
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 create a new Stokes I image, which we will use to generate a series of gain corrections (phase only self-calibration) that will be stored in 3C75.ScG0. With this solution, we then perform bandpass self-calibration to remove any amplitude slope that might be present. Next, we apply the derived phase and amplitude corrections to the data to form a set of self-calibrated data, and then re-image the dataset (3C75_selfcal.image). For the purpose of self-calibration, note that in the clean before the self-calibration, it is important that we only use the Stokes I model so that any cleaned polarization does not affect the gaincal. We first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.delmod.html?highlight=delmod# delmod] on the MS to get rid of the previous polarized model, and run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to generate Stokes I-only image.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3C75.ms')<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial_I",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
As discussed, this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] call will 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's total flux density as possible, but not include low level questionable features or sub-structures (ripples) that might be due to calibration or deconvolution artifacts. We modified the two parameters controlling [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]'s minor and major cycles to the following values ''cycleniter=750'' and ''niter=3500'' to reflect this, but you may find that you don't even need 3500 iterations for this first [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] pass.<br />
<br />
If you are happy with the new image, perform the following self-calibration steps:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3C75.ms', caltable='3C75.ScG0', field='', solint='inf', refant='ea10', <br />
spw='',minsnr=3.0, gaintype='G', parang=False, calmode='p')<br />
<br />
bandpass(vis='3C75.ms', caltable='3C75.ScB0', field='', solint='inf', refant='ea10', minsnr=3.0, spw='',<br />
parang = False, gaintable=['3C75.ScG0'], interp=[])<br />
<br />
applycal(vis='3C75.ms', gaintable=['3C75.ScG0','3C75.ScB0'], spw='', applymode='calflagstrict', parang=False)<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities which will be used by next execution of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] which may or may not be a good thing. You can control the action of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] by changing the value of parameter ''applymode''. Setting ''applymode='calflagstrict' ''will be more stringent about flagging data points without valid calibration, while ''applymode='calonly' '' will calibrate those with solutions while passing unchanged the data without solutions. You can see ahead of time what applycal will do by executing it with ''applymode='trial' ''which will do the reporting but nothing else. In our example we used '' applymode='calflagstrict' '', but you will notice that the reported flagged fraction has not changed much, only increasing by 0.6%. This is a good thing.<br />
<br />
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 produce a better image. We do this by invoking the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command once again. <br />
<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_selfcal_1",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
Commonly this self-calibration procedure is applied multiple times. In Figures 17A & B you can see a comparison of the shallow Stokes I image before self-calibration and after two self-calibration steps. The first self-calibration round was done as instructed in this section, while the second round was executed with ''solint='120s' '' and new solution tables were created (3C75.ScG1, 3C75.ScB1). You are encouraged to think about what parameters should and should not differ between the round 1 and round 2 self calibration stages, but they are provided below.<br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:800px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">Round 2 of Self Cal</div><br />
<div class="mw-collapsible-content"><br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3C75.ms', caltable='3C75.ScG1', field='', solint='120s', refant='ea10', <br />
spw='',minsnr=3.0, gaintype='G', parang=False, calmode='p')<br />
<br />
bandpass(vis='3C75.ms', caltable='3C75.ScB1', field='', solint='inf', refant='ea10', minsnr=3.0, spw='',<br />
parang = False, gaintable=['3C75.ScG1'], interp=[])<br />
<br />
applycal(vis='3C75.ms', gaintable=['3C75.ScG1','3C75.ScB1'], spw='', applymode='calflagstrict', parang=False)<br />
<br />
#Producing the Figure 17B image<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_selfcal_2",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
Note that only the gaincal call used the 120s solint. The bandpass of the VLA antennas are generally stable in time so it is relatively rare to have a case for using a time variable bandpass. Also note that the new solution interval is not the only difference between these round 2 calls. Since our previous tclean call (imagename="3C75_selfcal_1") also used savemodel='modelcolumn' these calls will be making use of an improved model.<br />
</div></div><br />
<br />
{|<br />
| [[Image:3c75-initial_I-CASA6.4.1.png|thumb|Figure 17A: Shallow Stokes I image before self-calibration.]]<br />
| [[Image:3c75-selfcal_2-CASA6.4.1.png|thumb|Figure 17B: Stokes I image after two rounds of self-calibration.]]<br />
|} <br />
<br />
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. 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 self-calibration won't help.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to remove an image, or even a set of gain corrections, change something and try again. Having said that, here are several guidelines to consider:<br />
<br />
* 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'' 'selfcal_1' ''is attached to various files to help keep straight what is what. Successive iterations of self-cal could then be'' 'selfcal_2' '','' 'selfcal_3' '', etc.<br />
<br />
* Care is required in setting ''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.<br />
<br />
* A common metric for self-calibration is whether the ''dynamic range'' (= peak flux density/rms) of the image has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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 features 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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''. One may 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager].<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] 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.)<br />
<br />
== Final Polarization Images ==<br />
<br />
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 artifacts 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, and make the image larger to incorporate the bright source into our model in this tclean execution.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms', minsamp=8, datacolumn='corrected', flagbackup=True)<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_final_large",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
The final restored Stokes I,Q,U, and V images are shown in Figures 18A&ndash;D. We've set the color scale to match between the images. Note that there is still a star like pattern in the residuals which are artifacts 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. 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 increases the further away one gets from the beam center. Additionally, the two polarization beams do not sit on top 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. <br />
<br />
{|<br />
| [[Image:3C75-final-I-CASA6.4.1.png|thumb|Figure 18A: Viewer panel of final restored Stokes I image.]]<br />
| [[Image:3C75-final-Q-CASA6.4.1.png|thumb|Figure 18B: Viewer panel of final restored Stokes Q image.]]<br />
| [[Image:3C75-final-U-CASA6.4.1.png|thumb|Figure 18C: Viewer panel of final restored Stokes U image.]]<br />
| [[Image:3C75-final-V-CASA6.4.1.png|thumb|Figure 18D: Viewer panel of final restored Stokes V image.]]<br />
|}<br />
<br />
Note, that these images are not yet primary beam corrected and are displayed on log scaling. You should play with the color scaling as well as the bias/contrast widget in [https://cartavis.org/ CARTA] to better see the faint emission.<br />
<br />
=== Spectral & Polarization Maps ===<br />
<br />
Note: If you are using [https://cartavis.org/ CARTA] then several of the next steps are actually unnecessary. If supplied a proper IQUV image [https://cartavis.org/ CARTA] will compute polarization intensity, linear polarization, fractional polarization intensity, fractional linear polarization intensity, and polarization angle maps for you. We show the steps one would have to take to manually create some of the images below for completeness. When possible the Figures shown will be using values/images that are generated soley by [https://cartavis.org/ CARTA] itself. You are encouraged though to still manually create your own set of images and then overlay them with the [https://cartavis.org/ CARTA] generated images to see that they match.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. As demonstrated earlier, the task can also correct the images for the telescope's primary beam response; this correction will make the images science ready. Parameter ''action='pbcor' '' will perform both actions (correct for the primary beam and calculate spectral index map) while parameter ''threshold'' sets minimum flux density above which the spectral index is calculated (this will allow us to mask all the noise regions).<br />
<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms', imagename='3C75_final_large', nterms=2, threshold='1.0mJy/beam', action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
<br />
For further study of polarization properties, you might want to convert the Stokes images into something more useful for scientific analysis. We will use CASA to calculate polarization intensity, <math>\sqrt{Q^2 + U^2 + V^2}</math>, and polarization angle, <math>{atan2 (U,Q) \over 2}</math>, maps from the final Stokes I,Q,U,V images. You can then look at those with [https://cartavis.org/ CARTA]. For example, Figure 19B shows the polarization intensity image. Since we've yet to apply any mask, the polarization angle image made in the next step will also contain values from low signal-to-noise data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Obtain image for the polarization intensity<br />
immath(outfile='3C75_final.poli',mode='poli',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
# Obtain image for the polarization angle<br />
immath(outfile='3C75_final.pola',mode='pola',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
</source><br />
<br />
{|<br />
| [[Image:3C75-final-spindx-CASA6.4.1.png|thumb|Figure 19A: CASA Computed spectral index map.]]<br />
| [[Image:3C75-final-Ptot-casa6.4.1.png|thumb|Figure 19B: CARTA Computed polarization intensity image.]]<br />
| [[Image:3C75-final-PAng-CASA6.4.1.png|thumb|Figure 19C: CARTA Computed polarized angles (vectors) superposed on the Stokes I raster image plane. We've selected an intensity threshold within CARTA to exclude low S/N points.]]<br />
|}<br />
<br />
Note that for calculations of the polarization intensity and angle images you may &mdash; but do not need to &mdash; use primary beam corrected images; your results will be the same. This is because the primary beam correction cancels out in the equations for these two polarization quantities. If you want to visualize the polarization vectors on top of the Stokes I image, we need to add a mask for the low noise values. <br />
<br />
<source lang="python"><br />
# In CASA<br />
!cp -r '3C75_final.poli' polimg<br />
<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.Q.image',stokes='Q')<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.U.image',stokes='U')<br />
<br />
subimPI='polimg'<br />
ia.open(subimPI)<br />
ia.calcmask(mask=subimPI+'>5e-4',name='mymask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.Q.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.U.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
immath(imagename=['3C75_final.Q.image', '3C75_final.U.image'], mode='pola', outfile='3C75_final.pola.masked')<br />
</source><br />
These steps take the polarized intensity image calculated above (Figure 19B) and create a mask using a polarization intensity threshold of 5e-4 Jy/beam. 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 created from the polarization intensity image. Finally, we can load the Stokes I as raster image into [https://cartavis.org/ CARTA] and add the polarization angle as vectors. You can do this by matching the final IQUV image, 3C75_final_large.image.tt0, and the newly created polarization angle image in WCS space by clicking the "XY" under the "Matching" column of the Image List widget. Then open the Vector Overlay Configuration widget to create the vectors. You can compare the vectors calculated with immath to the ones that [https://cartavis.org/ CARTA] generates for you. You may notice that there are some vectors that appear to disagree with each other. If so, it is likely caused by the pixel averaging being done within [https://cartavis.org/ CARTA], which you can toggle off to confirm. 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.<br />
<br />
=== Rotation Measures ===<br />
<br />
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. <br />
<br />
We show how to produce such images with one last [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] call using the following parameters. Since this is the last tclean call you'll need to perform to complete the guide we'll give you the opportunity to see if you can construct it yourself (Tip: using 'inp tclean' in CASA to see the inputs for the command will be quite useful). <br />
Remember two key differences in this call as compared to the previous:<br />
<br />
- You are making a cube with one spectral window per plane<br />
<br />
- You already know where the emission is (i.e. you have a mask)<br />
<br />
<br />
<div class="toccolours mw-collapsible mw-collapsed" style="width:1000px; overflow:auto;"><br />
<div style="font-weight:bold;line-height:1.6;">The final tclean</div><br />
<div class="mw-collapsible-content"><br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_chan8",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="cube",<br />
reffreq="",<br />
nchan=-1,<br />
start="",<br />
width=64,<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
mask='3C75_final_large.mask',<br />
normtype="flatnoise",<br />
deconvolver="multiscale",<br />
scales=[0, 6, 18],<br />
nterms=1,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="none",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=False)<br />
</source><br />
Here's the differences as compared to the previous tclean:<br />
<br />
* specmode="cube": This tells tclean we want a cube (i.e. separate images for separate frequencies) instead of a continuum image (specmode='mfs')<br />
<br />
* width=64: This tells tclean how wide in number of channels (i.e. frequency) each plane of the cube should be. We wanted one plane per spectral window and our spectral windows are 64 channels wide each.<br />
<br />
* mask='3C75_final_large.mask': We created this in our previous tclean call by interactively drawing it in the GUI. We call it again here to reuse it.<br />
<br />
* deconvolver="multiscale": Previously we used 'mtmfs' which stands for Multi-Term (Multi-scale) Multi-Frequency Synthesis. Since we are making per spectral window images this time were are no longer in the wideband regime and therefore drop the multi-frequency aspect.<br />
<br />
* nterms=1: Same reasoning as the change in deconvolver. Since we are making per spectral window images we need not worry about the spectral index of each image (i.e. we can assume each spectral window has a flat spectrum).<br />
<br />
* savemodel="none": This change is not strictly needed, but since we have no intention of changing our model with this run of tclean it is good form to make sure this is set. It would be a shame to overwrite your model this late into the process only to decide later that you wanted it for some reason.<br />
<br />
* interactive=False: Since we already have a mask we are happy with from the previous run there is no use in having tclean's GUI pop up again.<br />
</div></div><br />
<br />
<br />
Now we use the CASA toolkit to access data for four pixels in the image cube to visualize and fit the rotation measure. <br />
<source lang="python"><br />
# In CASA<br />
import matplotlib<br />
# to display<br />
matplotlib.use('TkAgg')<br />
import matplotlib.pyplot as plt<br />
import numpy as np<br />
<br />
ia.open('3C75_chan8.image')<br />
<br />
# number of channels/frequencies<br />
nunr = 8 <br />
<br />
tt = ia.getchunk()<br />
nu = np.linspace(2.551e9,3.319e9,num=nunr)<br />
c = 2.99792458e8<br />
<br />
Q1 = tt[418,444,1,:nunr]<br />
U1 = tt[418,444,2,:nunr]<br />
Q2 = tt[376,419,1,:nunr]<br />
U2 = tt[376,419,2,:nunr]<br />
Q3 = tt[383,401,1,:nunr]<br />
U3 = tt[383,401,2,:nunr]<br />
Q4 = tt[395,398,1,:nunr]<br />
U4 = tt[395,398,2,:nunr]<br />
<br />
chi1 = 0.5*np.arctan2(U1,Q1)<br />
chi2 = 0.5*np.arctan2(U2,Q2)<br />
chi3 = 0.5*np.arctan2(U3,Q3)<br />
chi4 = 0.5*np.arctan2(U4,Q4)<br />
<br />
#locate the values that are nan and delete these indices from nu<br />
indx1=np.argwhere(chi1==0)<br />
indx2=np.argwhere(chi2==0)<br />
indx3=np.argwhere(chi3==0)<br />
indx4=np.argwhere(chi4==0)<br />
<br />
nu1=np.delete(nu,indx1)<br />
lam1 = c/nu1<br />
lamsq1 = lam1*lam1<br />
<br />
nu2=np.delete(nu,indx2)<br />
lam2 = c/nu2<br />
lamsq2 = lam2*lam2<br />
<br />
nu3=np.delete(nu,indx3)<br />
lam3 = c/nu3<br />
lamsq3 = lam3*lam3<br />
<br />
nu4=np.delete(nu,indx4)<br />
lam4 = c/nu4<br />
lamsq4 = lam4*lam4<br />
<br />
#drop the zero values<br />
chi1=np.delete(chi1,indx1)<br />
chi2=np.delete(chi2,indx2)<br />
chi3=np.delete(chi3,indx3)<br />
chi4=np.delete(chi4,indx4)<br />
<br />
fit1 = np.polyfit(lamsq1,chi1,1)<br />
fit_fn1 = np.poly1d(fit1)<br />
slope1 = fit1[0]<br />
intercept1 = fit1[1]<br />
fit2 = np.polyfit(lamsq2,chi2,1)<br />
fit_fn2 = np.poly1d(fit2)<br />
slope2 = fit2[0]<br />
intercept2 = fit2[1]<br />
fit3 = np.polyfit(lamsq3,chi3,1)<br />
fit_fn3 = np.poly1d(fit3)<br />
slope3 = fit3[0]<br />
intercept3 = fit3[1]<br />
fit4 = np.polyfit(lamsq4,chi4,1)<br />
fit_fn4 = np.poly1d(fit4)<br />
slope4 = fit4[0]<br />
intercept4 = fit4[1]<br />
<br />
plt.figure(1)<br />
plt.title('Overall Title')<br />
plt.subplot(221)<br />
plt.title('Point 1: (418,444)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi1$')<br />
plt.scatter(lamsq1,chi1,color='r')<br />
plt.plot(lamsq1,fit_fn1(lamsq1),'r--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope1,intercept1))<br />
plt.legend(loc=2)<br />
<br />
plt.subplot(222)<br />
plt.title('Point 2: (376,419)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi2$')<br />
plt.scatter(lamsq2,chi2,color='b')<br />
plt.plot(lamsq2,fit_fn2(lamsq2),'b--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope2,intercept2))<br />
plt.legend(loc=1)<br />
<br />
plt.subplot(223)<br />
plt.title('Point 3: (383,401)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi3$')<br />
plt.scatter(lamsq3,chi3,color='g')<br />
plt.plot(lamsq3,fit_fn3(lamsq3),'g--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope3,intercept3))<br />
plt.legend(loc=3)<br />
<br />
plt.subplot(224)<br />
plt.title('Point 4: (395,398)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi4$')<br />
plt.scatter(lamsq4,chi4,color='m')<br />
plt.plot(lamsq4,fit_fn4(lamsq4),'m--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope4,intercept4))<br />
plt.legend(loc=1)<br />
plt.tight_layout()<br />
<br />
plt.show()<br />
#Or to save the figure<br />
plt.savefig('3C75_rmscript_8chan4px.png')<br />
<br />
ia.close()<br />
</source><br />
<br />
The resulting plots are shown in Figure 20A. Alternatively, there exists a CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] which does this basic fitting for you while taking into account the <math>N \pi</math> ambiguity (refer to [http://adsabs.harvard.edu/full/1986A%26A...156..234L] for more info). The fits using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for our case of 3C 75 by making images per spectral window is shown in Figure 20B. Here we set the maximum acceptable position angle error to 20 degrees. If larger, then no rotation measures are calculated.<br />
<br />
<source lang='python'><br />
# In CASA<br />
rmfit('3C75_chan8.image',rm='3C75_chan8_rm.image',rmerr='3C75_chan8_rm.image.err',maxpaerr=0.35)<br />
</source> <br />
<br />
{|<br />
| [[Image:3C75-rmscript-8chan4px-CASA6.4.1.png|thumb|Figure 20A: Rotation measures extracted for 4 pixels from an 8 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmfit-8chan-CARTA-CASA6.4.1.png|thumb|Figure 20B: RMFIT rotation measure image generated from 8 channel image cube.]]<br />
|}<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] task has many more options; for example, you are able to provide a foreground rotation measure to subtract. <br />
<br />
Now we can compare the rotation measures extracted for the 4 pixels from the 8 channel image cube with the values derived in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for the same pixels. In most cases the values are more or less comparable.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Point<br />
! RM Lin. Fit.<br />
! RM RMFIT<br />
|-<br />
| 1<br />
| -65.46<br />
| -57.29<br />
|-<br />
| 2<br />
| 10.41<br />
| 66.62<br />
|-<br />
| 3<br />
| -71.71<br />
| -65.14<br />
|-<br />
| 4<br />
| -7.30<br />
| -5.07<br />
|}<br />
<br />
If time allows you can take this even further. As our source is rather bright, we can derive an IQUV image not just per averaged spectral window as we just did, but rather per channel. To achieve this you can change the above [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] parameter width from 64 to 1, which will result in 512 channels spanning all 8 spectral windows. Note when imaging each channel, the edge channels are flagged which results in the PSF being blank for channels sourrounding each spectral window and some of the images being blank. Don't forget to change the imagename parameter when re-running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. Due to the increased size of the cube you may find that your machine's avaliable memory struggles to keep up with the new [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command. If so, then you can reduce the image size to lower the required memory. For our 512 channel cube we reduced the image size from 800x800 to 270x270. If you do reduce the image size as we have then you'll need to make use of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.imsubimage.html?highlight=imsubimage imsubimage] to first reduce your old image's mask size so it can be used again for your smaller image. Following the same steps as for the 8 channel image cube (adjusting for the new number of channels and new pixel indices for our points of interest), you would then obtain the results shown in Figure 21 where again the polarization position angle as a function of lambda square is shown together with the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] image. We can clearly see that the source exhibits complex structure beyond a simple linear fit 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.<br />
<br />
<br />
{|<br />
| [[Image:3C75-rmscript-512chan4px-CASA6.4.1.png|thumb|Figure 21A: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmscript-512chan4px-ylim-CASA6.4.1.png|thumb|Figure 21B: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75 with enforced limits on y axis for points 1 and 2 to exclude outlier points from the view and see better the variation of the data.]]<br />
| [[Image:3C75-rmfit-512chan-CARTA-CASA6.4.1.png|thumb|Figure 21C: RMFIT rotation measure image generated from 512 channel image cube.]]<br />
|}<br />
<br />
<!-- == Image Analysis ==<br />
<br />
The three most basic analyses are to determine peak brightness, flux density, and 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.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3C75_initial.image.tt0')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '02:58:37.309, +05.47.28.628, I, 3e+09Hz',<br />
'max': array([ 0.14971776]),<br />
'maxpos': array([257, 279, 0, 0], dtype=int32),<br />
'maxposf': '02:57:38.755, +06.03.17.399, I, 3e+09Hz',<br />
'mean': array([ 0.00016331]),<br />
'medabsdevmed': array([ 1.74164962e-05]),<br />
'median': array([ 8.04986788e-09]),<br />
'min': array([-0.01785131]),<br />
'minpos': array([258, 278, 1, 0], dtype=int32),<br />
'minposf': '02:57:38.527, +06.03.13.999, Q, 3e+09Hz',<br />
'npts': array([ 921600.]),<br />
'q1': array([ -1.69758441e-05]),<br />
'q3': array([ 1.78917744e-05]),<br />
'quartile': array([ 3.48676185e-05]),<br />
'rms': array([ 0.0031646]),<br />
'sigma': array([ 0.00316039]),<br />
'sum': array([ 150.50313612]),<br />
'sumsq': array([ 9.22954767]),<br />
'trc': array([479, 479, 3, 0], dtype=int32),<br />
'trcf': '02:56:48.133, +06.14.37.233, V, 3e+09Hz'}<br />
<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.14971776306629181<br />
</pre><br />
and so the peak flux density is 0.150 Jy/beam.<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# 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.<br />
<br />
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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3C75_final.image.tt0' &<br />
</source><br />
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. <br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
2659 1.243414e+02 4.676248e-02 5.722227e-02 <br />
Std dev Minimum Maximum region count <br />
3.298586e-02 -1.063592e-03 1.484267e-01 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
</pre><br />
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.<br />
<br />
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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
1216 -3.509342e-02 -2.885972e-05 6.186932e-05 <br />
Std dev Minimum Maximum region count <br />
5.474847e-05 -1.558577e-04 1.394379e-04 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
<br />
</pre><br />
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.<br />
<br />
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. <br />
<br />
<!-- Similar analysis can be performed on the polarization and spectral index maps, this will be left to the user. --><br />
<br />
<!-- Edited for content & context by T. Perreault 2021-12-30 --><br />
<!-- Last edit by Anna D. Kapinska 2021-12-17 --><br />
<!-- Edited by Frank Schinzel 2021-03-30 --></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35265VLA Continuum Intro Tutorial2023-06-15T18:39:23Z<p>Akapinsk: /* Step 6: Gain Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* In both executions of gaincal() above we used solint='inf'. What does it mean and why is it a good choice here?<br />
* What other options for the parameter could you use, and in what situations?<br />
|-<br />
|}<br />
<br />
<br />
If you check the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()], you should now see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|350px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|340px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
<br />
After the imaging and deconvolution process has finished, there are a few ways for you to inspect your image. CASA still has in-built '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' task, but this task is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
If you would like to use CARTA now, and need some help, please ask one of the tutors to help you out. If you prefer to stick to the simple viewer for the moment, you can start it with the following command:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|350px|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|350px|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35261VLA Continuum Intro Tutorial2023-06-15T16:58:55Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|350px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|340px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
<br />
After the imaging and deconvolution process has finished, there are a few ways for you to inspect your image. CASA still has in-built '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' task, but this task is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
If you would like to use CARTA now, and need some help, please ask one of the tutors to help you out. If you prefer to stick to the simple viewer for the moment, you can start it with the following command:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|350px|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|350px|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35260VLA Continuum Intro Tutorial2023-06-15T16:57:06Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|350px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|340px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
<br />
After the imaging and deconvolution process has finished, there are a few ways for you to inspect your image. CASA still has in-built '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' task, but this task is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
If you would like to use CARTA now, and need some help, please ask one of the tutors to help you out. If you prefer to stick to the simple viewer for the moment, you can start it with the following command:<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|350px|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|350px|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35259VLA Continuum Intro Tutorial2023-06-15T16:48:08Z<p>Akapinsk: /* Image Analysis */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|350px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|340px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|350px|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|350px|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35258VLA Continuum Intro Tutorial2023-06-15T16:47:12Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|350px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|340px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35257VLA Continuum Intro Tutorial2023-06-15T16:46:11Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|400px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|400px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|600px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35256VLA Continuum Intro Tutorial2023-06-15T16:44:11Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|400px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
|}<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|400px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|400px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35255VLA Continuum Intro Tutorial2023-06-15T16:42:09Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask. Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required. Before you execute the task provided below, please read the explanation of the parameters we are setting:<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
Now, revise the parameters, and run the task:<br />
<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=0,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|400px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
|}<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|400px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions:'''<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
|-<br />
|}<br />
<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|400px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35254VLA Continuum Intro Tutorial2023-06-15T16:37:03Z<p>Akapinsk: /* Multi-scale Mosaic Clean */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' window will pop up as shown in Figure 14. 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.<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|400px|thumb|left|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
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 15 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 16) the residuals are looking good (similar noise level inside and outside the clean region). <br />
<br />
{|<br />
| [[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|400px|thumb|left|Figure 15: After the first 500 iterations of multi-scale clean()]]<br />
|}<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|400px|thumb|left|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
|}<br />
<br />
Questions:<br />
* What effect would you expect to see if you changed the scales in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] input? What do you think would happen if you run the task with scales=[0] or scales=[0,5], or scales=[5] only?<br />
* In what situation it is recommended to choose specmode='mfs' and when 'mtmfs'? <br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|400px|thumb|left|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer()]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
<b><br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
</b><br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean()], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor()] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35253VLA Continuum Intro Tutorial2023-06-15T16:24:31Z<p>Akapinsk: /* Applying the Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale()], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal()].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
After running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt()], if you would like to again inspect the calibrated amplitudes of your data with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] , make sure you choose <b>Wt*Amp</b> and corrected data column for your y-axis.<br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35252VLA Continuum Intro Tutorial2023-06-15T16:19:52Z<p>Akapinsk: /* Imaging parameters */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|350px|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, corresponding to smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam (the angular resolution). For the angular resolution of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam (2.5 arcsec/pixel x 5 pixels/synthesized_beam = 12 arcsec/synthesized_beam). <br />
<br />
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: one centered on the remnant with 6 flanking fields; the spacing of the fields was chosen based on the size of the antenna primary beam. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35251VLA Continuum Intro Tutorial2023-06-15T16:14:14Z<p>Akapinsk: /* Imaging parameters */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
{|<br />
| [[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
|}<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35250VLA Continuum Intro Tutorial2023-06-15T16:12:04Z<p>Akapinsk: /* On Your Own: 3C391 second frequency and G93.3+6.9 */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
{{Checked 6.4.1}}</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35249VLA Continuum Intro Tutorial2023-06-15T16:09:01Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: Delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: Complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|300px|thumb|left|Figure 11A: Post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|300px|thumb|center|Figure 11B: Post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
{|<br />
| [[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
|}<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
{|<br />
| [[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
{|<br />
| [[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|left|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
| [[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|center|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
|}<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35248VLA Continuum Intro Tutorial2023-06-15T16:03:25Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|300px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35247VLA Continuum Intro Tutorial2023-06-15T03:11:35Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|420px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|440px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Step 6: Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|300px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|300px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<br />
=== Step 7: Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35246VLA Continuum Intro Tutorial2023-06-15T03:06:34Z<p>Akapinsk: /* Bandpass Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: delay solutions]]<br />
|}<br />
<br />
=== Step 5: Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
<br />
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 continuum data, and in fact it is essential for moderate or high dynamic range imaging. To motivate the need for solving for the bandpass, consider Figure 7. It shows the right circularly polarized data (RR correlation) for the source J1331+3030 that serves as our bandpass calibrator. The data are color coded by spectral window. The visibility data are nearly constant with baseline length for this particular calibrator (Figure 3A), and ideally, they would be constant as a function of frequency as well. The variations with frequency are a reflection of the (slightly) different antenna bandpasses. <br />
<br />
''Exercise: reproduce Figure 7 using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()].''<br />
<br />
{|<br />
| [[Image:Plotms-3C286-RRbandpass2.png|300px|thumb|right|Figure 7: Modeled bandpass illustration]]<br />
|}<br />
<br />
<br />
We can now solve for the bandpass (i.e. model it), using the phase solutions and delays we just derived in previous steps.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
<br />
Once again, we can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization; Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
<br />
As expected, the bandpass phases are relatively flat (Figure 8B) with the slopes seen in Figure 3C removed by the delay calibration. Residual phase excursions are on the order of a few degrees.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|400px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|400px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35245VLA Continuum Intro Tutorial2023-06-15T02:56:46Z<p>Akapinsk: /* Setp 3: Initial Phase Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
The inspection of the initial solutions we have just done, was the only purpose of the .G0all table. We will not use this calibration table any more, and instead we will create a new one, .G0, that will contain initial phase solutions for only the bandpass calibrator. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). It is important that this call is executed after flagging of ''ea05''.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect these new solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: delay solutions]]<br />
|}<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35244VLA Continuum Intro Tutorial2023-06-15T02:50:07Z<p>Akapinsk: /* Delay Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
For the following bandpass solution we need only to solve for our bandpass calibrator, and we will do so now after flagging. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). The ''caltable'' is is the calibration table we create here that we will use later when applying the solutions to the data.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Step 4: Delay Calibration ===<br />
<br />
Before we can solve for bandpass, we need to first solve for the antenna-based delays (these delays put a phase ramp versus frequency channel in each spectral window as demonstrated in Figure 3C, we want to remove that slope). The K gain type in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 does show any problems. This is not a full global delay, but gives one value per spw per polarization.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that we just created <br />
<br />
Plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
You can see that the delays are within around 4 nanoseconds, which is expected for the early science observations with the newly upgraded VLA.<br />
<br />
<br />
{|<br />
| [[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|300px|thumb|right|Figure 6: delay solutions]]<br />
|}<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35243VLA Continuum Intro Tutorial2023-06-15T02:45:04Z<p>Akapinsk: /* Setp 3: Initial Phase Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations - we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. Note, 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set_here_'antenna'_and_'mode'_parameters_to_successfully_flag_ea05>)<br />
</source><br />
<br />
For the following bandpass solution we need only to solve for our bandpass calibrator, and we will do so now after flagging. The following call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). The ''caltable'' is is the calibration table we create here that we will use later when applying the solutions to the data.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35242VLA Continuum Intro Tutorial2023-06-15T02:40:03Z<p>Akapinsk: /* Setp 3: Initial Phase Calibration */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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; depending on frequency and configuration there may occur significant gain variations between different scans especially if the scans are at significantly different elevations and we want to moderate it to help us with bandpass calibration. We will later discard these initial phase solutions. 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 (hence our selection of ''calmode='p' ''). <br />
<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
<pre style="background-color: lightgrey;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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 (Figure 5)<br />
<br />
{|<br />
| [[Image:plotms-3C286-G0all-phase-ea05_CASA5.4.0.png|300px|thumb|left|Figure 5: Initial gain phases colorized by polarization for antenna ea05]]<br />
|}<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, <set here ''antenna'' and ''mode'' parameters to msuccessfully flag ea05>)<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal()] is similar to the one above, but selects only the bandpass calibrator (using the ''field'' parameter). The ''caltable'' is is the calibration table we create here that we will use later when applying the solutions to the data.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35241VLA Continuum Intro Tutorial2023-06-15T02:24:52Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
Here 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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== Step 1: ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Step 2: Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<br />
For the pre-upgrade VLA, the ultimate flux density scale at most frequencies was set long ago by observations of 3C 295. The flux density 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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()]. <br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
<br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
<br />
* ''field='J1331+3030' '': IMPORTANT! If the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From our Figure 3A, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''spw=' ' '': The original data set contained two spectral windows. However, since we separated spectral window 0 for the data set used in this tutorial, it is not necessary to specify spw. Had the spectral window 0 not been split off from the original data, we might wish to specify the spectral window. The reason for it is that in this observation the spectral windows were sufficiently far away from each other 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()], one for each spectral window. If the spectral windows were much closer together, it might be possible to calibrate both using a single, the same model.<br />
<br />
Note: In our case here, a model image of a primary flux density calibrator exists (hence we selected ''model='3C286_C.im' ''). However, sometimes (some kinds of polarization calibration or in extreme situations, e.g. there are problems with the scan on the flux density calibrator), it may be necessary to set the flux density of the source explicitly.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
The flux density in each Stokes plane (IQUV) for the reference channel 0 is reported (although here set to 0), followed by the I flux density in each of the channels to be used for scaling the data. These values are determined from an analytical formula for the spectrum of the source as a function of frequency so that precise predictions can be estimated for our specific frequencies. <br />
<br />
Notes: [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found so all is good. Also, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] can return 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 because we did not assigned it to a python variable:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If you would like to store this result in a python dictionary, call the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy()] task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
<br />
=== Setp 3: Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35240VLA Continuum Intro Tutorial2023-06-15T02:06:29Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35239VLA Continuum Intro Tutorial2023-06-15T01:59:12Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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). To plot baseline length in wavelengths rather than meters, select ''UVwave'' as the X-axis parameter. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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]. )--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|400px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|400px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* What causes the difference between the shape of the plots in 3A and 3B? <i>Hint:</i> recollect 2nd lecture by Rick Perley on Tuesday.<br />
|-<br />
|}<br />
<br />
<br />
<br />
3. 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. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|400px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
At this stage in the data reduction process, you should focus predominantly on the calibrators. The strategy is to determine various corrections from the calibrators, then apply these correction factors to the science target in your observations. The 3C 286 data look relatively clean in that there are no wildly egregious data point (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.<br />
<br />
<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows when various antennas drop out (assuming that ea01 is in the entire observation).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31', xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
Result is in Figure 4 below. You should immediately see that the flagging we did earlier of antennas 10 and 12 (ea13 and ea15) has taken effect. You may also notice that antennas 1, 6, and 13 (ea02, ea08, and ea16) are missing some blocks toward the beginning and the end of the observing run. Antenna 3 (ea04) is missing the last scan 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.<br />
<br />
{|<br />
| [[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|300px|left|thumb|Figure 4: datastream view of MS]]<br />
|}<br />
<br />
<br />
== Calibrating the Data ==<br />
<br />
We are now ready to begin calibrating the data. The general calibration strategy is to derive a series of scaling factors or corrections from the calibrators, which are then collectively applied to the science data. For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35238VLA Continuum Intro Tutorial2023-06-15T01:42:34Z<p>Akapinsk: /* Examining and Editing the Data */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
You can quickly see that the last source observed (J0319+4130, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output earlier). 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.<br />
<br />
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). 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.<br />
<br />
You should spend several minutes displaying the data in various ways. Below are three important examples.<br />
<br />
1. 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 thing 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.)--><br />
<br />
2. By contrast, if you make a similar plot as above but 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.)--><br />
<br />
{|<br />
| [[File:plotms-3C286-Amp vs UVdist 4.6.jpeg|200px|left|thumb|Figure 3A: plotms view of amp vs. uvdist of 3C 286]]<br />
| [[File:Plotms-3C391-Amp vs UVdist 5.0.jpeg|200px|center|thumb|Figure 3B: plotms view of amp vs. uvdist of 3C 391]]<br />
|}<br />
<br />
<br />
3. 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' polarization correlations.<br />
<br />
{|<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|left|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35237VLA Continuum Intro Tutorial2023-06-15T01:27:47Z<p>Akapinsk: /* The Observation */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended -if not necessary- to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35236VLA Continuum Intro Tutorial2023-06-15T01:19:35Z<p>Akapinsk: /* Inspecting data and further flagging */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
| [[Image:Colorbyfield_CASA5.4.0.jpeg|300px|left|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35235VLA Continuum Intro Tutorial2023-06-15T01:18:45Z<p>Akapinsk: /* Inspecting data and further flagging */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
{|<br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|300px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
|}<br />
<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35234VLA Continuum Intro Tutorial2023-06-15T01:09:39Z<p>Akapinsk: /* Examining and Editing the Data */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
=== Flagging for known issues ===<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
=== Inspecting data and further flagging ===<br />
<br />
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. We will use the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms()] task to examine our data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': We want to plot here only selected subsets of our data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': We want to average data points before plotting them (often to speed up loading time, but also because it will highlight RFI).<br />
* ''avgchannel='64' '': Here we are plotting fields vs time, so averaging over all 64 channels in the spectral window will make plotting faster.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35233VLA Continuum Intro Tutorial2023-06-15T01:03:13Z<p>Akapinsk: /* Examining and Editing the Data */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
Note that the flags that existed in the data set prior to this run will be saved to another file called ''flagdata_1''. Should you ever need to revert to the data prior to this run, the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager()] can be used. Also note that the values of all the task parameters (explicit or hidden) are given at the start of the task listing.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': a flagging mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''quackinterval=10 '': In this data set, the sampling time is 10 seconds, hence here the first sample from all scans on all baselines will be flagged.<br />
<br />
<br />
Now return to the observer's log and find out what antennas have known problems. We will flag these antennas now:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='xxxx')<br />
</source><br />
* ''antenna='xxxx' '': requires a string input. Remember the difference between referring to ''antenna='ea01' '' and ''antenna='01' '' (discussed a few paragraphs earlier).<br />
<br />
<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35232VLA Continuum Intro Tutorial2023-06-13T05:27:13Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
It is always a good idea to examine the data before jumping straight into calibration; you do want to remove the most offending RFI before modeling your data. 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, after that examine the data visually for any apriori unknown issues, or RFI.<br />
<br />
In the VLA scheduling block configuration, it is common to insert a setup scan as the first scan. In the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output above, you might have noticed that the first scan is less than 1 minute long; we can safely flag it since it is a setup scan.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata()] will save a copy of the existing set of flags ''before'' entering any new flags. It is up to you if you want to save every flagging step. For example you could choose to save only major flags, or not save them at all (though think about a situation if you would like to revert an accidental or incorrect flag..). ''flagbackup=True'' is the default. <br />
* ''mode='manual' '': Specific data ranges or portions from the set will be selected for editing. <br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger should be something like this:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35231VLA Continuum Intro Tutorial2023-06-13T05:19:40Z<p>Akapinsk: /* The Observation */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? <i>Hint:</i> remember in what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35230VLA Continuum Intro Tutorial2023-06-13T05:16:33Z<p>Akapinsk: /* The Observation */</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Question:'''<br />
* Which antenna is best to use as a reference one here? Hint: remember what configuration these observations were taken.<br />
Please indicate to the tutors that you have arrived to this stage. We will discuss the choice of the reference antenna with the whole group.<br />
|-<br />
|}<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35229VLA Continuum Intro Tutorial2023-06-13T05:12:05Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output, the first <b>scans</b> are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b>. Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
<i>Question:</i> Which antenna is best to use as a reference one here? Hint: remember what configuration these obseravtions were taken. <br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35228VLA Continuum Intro Tutorial2023-06-13T05:07:42Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output (cut out lines indicated by [....]):<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice that in this listobs, the first scans are the fields that will be used for calibration - they are observed before the target fields; what do you think: is there a reason to set up observations like that? Is it necessary? <br />
<br />
Note the portion listing the <b>spectral windows</b> (in this tutorial there is only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide. You can also find what frequency of the first channel is. <br />
<br />
<b>Antennas</b><br />
<br />
Note that the antenna IDs (which are numbered sequentially up to the total number of antennas in the array; how many do we have here?) 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; 'that is, '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.<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants()] (output shown in 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
</source><br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|400px|thumb|center|Figure 1: plotants figure]]<br />
<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35227VLA Continuum Intro Tutorial2023-06-13T04:58:50Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
Excerpt of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
[.....]<br />
<br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
<br />
[....]<br />
<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35226VLA Continuum Intro Tutorial2023-06-13T04:54:03Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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. This guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise. <br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largely self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
We will get back to this information in some of later steps.<br />
<br />
<b>Now, if you have not yet started CASA, navigate to your working directory where the data set is saved, and start the software.</b><br />
<br />
Once you have CASA up and running, start your data reduction by getting some basic information about the data as the first step: the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] task. This task will provide you with a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. To run the task, type the lines below that do not start with # (this sign marks a comment and is ignored by CASA):<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs()] output will show up in the CASA logger window.<br />
<br />
You should see that there are ten sources observed:<br />
* J1331+3030 = 3C 286, a primary calibrator for the visibility amplitudes, i.e., it is assumed to have a precisely known flux density, and a bandpass calibrator;<br />
* J1822-0938, a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, a polarization calibrator (ignored in this tutorial); and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35225VLA Continuum Intro Tutorial2023-06-13T04:41:13Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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.<br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
This tutorial is largerly self-paced. Any time you have a question, or something doesn't look right or you are unsure of, please do summon one of the tutors present in the room.<br />
<br />
<!--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.--><br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
<br />
== The Observation ==<br />
<br />
Before starting the calibration process, it is recommended if not necessary to get some basic information about the data set. VLA operators that monitor the array when your data are being taken record observing conditions during the observing run, as well as problems with the data caused by the weather or misbehaving array hardware. Such an <b>observing log</b> can be downloaded from the [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi observer log depository] for almost all VLA observations. <br />
<br />
To get the observing log of our observations, fill in the 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. <br />
<br />
While inspecting the log, you should find the following:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
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. Note, this guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] can be used to get a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. 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.<br />
* 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; will also serve as the (spectral) bandpass calibrator;<br />
* J1822-0938, which will serve as a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, which was used as a polarization calibrator; and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
To run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs]:<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output will show up in the CASA logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35224VLA Continuum Intro Tutorial2023-06-13T04:29:58Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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.<br />
<br />
There are a number of possible ways to run CASA, described in more detail in [[Getting Started in CASA]]. In this tutorial we would like you to use either (or both) of the following methods so that you can familiarize yourself with the CASA software:<br />
<br />
* Interactive: 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 is stored and can be retrieved via '''tget ''taskname'''''; subsequent runs will overwrite the previous '''tget''' file.<br />
<br />
* Pseudo-interactive: task function calls. In this mode, all of the desired inputs to a task are provided at once inn 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.<br />
<br />
<!--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.--><br />
<br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
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. Note, this guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] can be used to get a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. 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.<br />
* 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; will also serve as the (spectral) bandpass calibrator;<br />
* J1822-0938, which will serve as a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, which was used as a polarization calibrator; and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
To run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs]:<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output will show up in the CASA logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35223VLA Continuum Intro Tutorial2023-06-13T04:24:39Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<br />
== Notes on CASA ==<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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.<br />
<br />
There 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 use CASA:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
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.<br />
<br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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 (before the full operations of the upgraded JVLA started), with 128 MHz of bandwidth in each of two spectral windows, centered at 4.6 and 7.5 GHz. While the observations had a full-polarization correlator setup and included a polarization calibrator, for the purposes of this tutorial we will focus on the total intensity continuum (Stokes I) calibration and imaging only. <br />
<br />
<br />
You should already have the data set downloaded. If you do not, then it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, the data file is 3.1GB).<br />
<br />
This data set has been pre-prepared for this tutorial, where several initial processing steps, listed below, have already been conducted. Many of these initial processing steps are often time consuming (> 1 hr), and while necessary in data processing, they go beyond the subject of calibration and imaging of this tutorial. Specifically, the following has been already done:<br />
<br />
* The initial raw Science Data Model (SDM) file was converted into a Measurement Set (MS).<br />
* Basic data flagging to account for shadowing of the antennas was applied. 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.<br />
* The data were averaged from the initial 1-second correlator sample dump to 10-second samples. In the D configuration, the fringe rate is relatively slow and time-average smearing is less of a concern hence we can get away with 10-second averaging.<br />
* Only one spectral window is considered in this step-by-step tutorial, mainly for a concern of disk space on laptops.<br />
<br />
<!-- 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.--><br />
<br />
Before you can start the tutorial, the data set needs to be unzipped and unpacked (but first place the data set in the directory you will work in):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
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. Note, this guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] can be used to get a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. 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.<br />
* 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; will also serve as the (spectral) bandpass calibrator;<br />
* J1822-0938, which will serve as a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, which was used as a polarization calibrator; and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
To run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs]:<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output will show up in the CASA logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
<br />
<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35208VLA Continuum Intro Tutorial2023-05-31T15:25:46Z<p>Akapinsk: </p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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.<br />
<br />
== Data Set ==<br />
<br />
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 <br />
[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.<br />
<br />
The observations were taken with a full-polarization correlator setup and include a polarization calibrator. For the purposes of this tutorial, we will focus on the continuum (Stokes I) calibration and imaging. (See the CASA guide on radio galaxy 3C75 for an introduction to polarization calibration.)<br />
<br />
<br />
There 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 use CASA:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
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.<br />
<br />
You should already have the data set downloaded, if you don't then: (a) it can be downloaded from here [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] (but may be difficult to download over conference wi-fi, it's 3.1GB), (b) we may have a few usb sticks with the data set for you to copy it over.<br />
<br />
<br />
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:<br />
<br />
<br />
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. <br />
<br />
* The initial Science Data Model (SDM) file was converted into a measurement set.<br />
* 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.<br />
* 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.<br />
* 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.<br />
<br />
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.<br />
<br />
Once the download is complete, unzip and unpack the file (within a working directory, where you will later run CASA):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
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. Note, this guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] can be used to get a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. 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.<br />
* 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; will also serve as the (spectral) bandpass calibrator;<br />
* J1822-0938, which will serve as a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, which was used as a polarization calibrator; and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
To run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs]:<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output will show up in the CASA logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=CASA_Guides:VLA_Polarization_pipe_Tutorial&diff=35151CASA Guides:VLA Polarization pipe Tutorial2023-05-22T19:19:02Z<p>Akapinsk: Akapinsk moved page CASA Guides:VLA Polarization pipe Tutorial to VLA Polarization pipe Tutorial: Took out "CASA guides" words from the title</p>
<hr />
<div>#REDIRECT [[VLA Polarization pipe Tutorial]]</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Polarization_pipe_Tutorial&diff=35150VLA Polarization pipe Tutorial2023-05-22T19:18:49Z<p>Akapinsk: Akapinsk moved page CASA Guides:VLA Polarization pipe Tutorial to VLA Polarization pipe Tutorial: Took out "CASA guides" words from the title</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<b>This CASA Guide is for the monolithic, not the modular pip-wheel version, version 6.4.1 of CASA that includes the VLA 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. This guide also uses [https://cartavis.org/ CARTA] as its choice of image viewer. We strongly recommend using [https://cartavis.org/ CARTA] over the built in CASA viewer, used by tasks such as [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casaviewer.imview.html?highlight=imview imview], as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and [https://cartavis.org/ CARTA], as well as instructions on how to use [https://cartavis.org/ CARTA] at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs].<br />
<br />
== Overview ==<br />
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. <br />
[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. The calibration part of this tutorial can be performed on a laptop computer with sufficient storage. The imaging part, however, will require more computing power and memory. This CASA guide was also used as basis for a presentation on polarization calibration at the 7th VLA data reduction workshop: [https://science.nrao.edu/science/meetings/2019/vla-data-reduction/Schinzel_Polarization.pdf]<br />
<br />
== How to Use This CASA Guide ==<br />
<br />
Here are a number of possible ways to run CASA, described in more detail in [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/usingcasa.html Getting Started in CASA]. In brief, there are at least three different ways to run CASA:<br />
<br />
* Interactively examining task inputs. In this mode, one types '''default taskname''' to load the task (this will also set all the task parameters to default values), '''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 />
* 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.<br />
<br />
* 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).<br />
<br />
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.<br />
<br />
== Obtaining the Data ==<br />
<br />
If starting from scratch, you can obtain the dataset from the [https://data.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. Make sure to select to download the SDM-BDF dataset, if you want to start from the lowest level, because by default a .ms file will be provided by the archive.<br />
<br />
For those who 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/VLA/Polarization/TDRW0001_calibrated_CASA6.4.1.ms.tgz '] (size: 11 GB). It is recommended to use the command line tool '''wget''' to download the calibrated data or directly download through the browser. You will need to untar and unzip the file using the command: 'tar -xzvf TDRW0001_calibrated_CASA6.4.1.ms.tgz' and then give it the same name as the guide uses: 'mv TDRW0001_calibrated_CASA6.4.1.ms TDRW0001_calibrated.ms'. Then you can skip ahead to the section 'The Observation'.<br />
<br />
== Pipeline Calibration of Parallel Hands (RR/LL) ==<br />
<br />
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 at: [https://science.nrao.edu/facilities/vla/data-processing/pipeline https://science.nrao.edu/facilities/vla/data-processing/pipeline].<br />
<br />
In this example, we will not run the pipeline in its standard way but tweak it to force a certain reference antenna, ea10. 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 is better to use one of the outer antennas for reference, which provides 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. <br />
<br />
<source lang="python"><br />
# casa_pipescript.py<br />
<br />
__rethrow_casa_exceptions = True<br />
context = h_init()<br />
context.set_state('ProjectSummary', 'observatory', 'Karl G. Jansky Very Large Array')<br />
context.set_state('ProjectSummary', 'telescope', 'EVLA')<br />
context.set_state('ProjectStructure', 'recipe_name', 'hifv_cal')<br />
try:<br />
hifv_importdata(vis=['TDRW0001.sb35624494.eb35628826.58395.23719237269'], session=['default'])<br />
hifv_hanning(pipelinemode="automatic")<br />
hifv_flagdata(hm_tbuff='1.5int', intents='*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*, *UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*')<br />
hifv_vlasetjy(pipelinemode="automatic")<br />
hifv_priorcals(pipelinemode="automatic")<br />
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')<br />
hifv_checkflag(pipelinemode="automatic")<br />
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')<br />
hifv_checkflag(checkflagmode='semi')<br />
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')<br />
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')<br />
hifv_fluxboot(fitorder=2, 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')<br />
hifv_finalcals(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')<br />
hifv_applycals(pipelinemode="automatic")<br />
hifv_targetflag(intents='*CALIBRATE*,*TARGET*')<br />
hifv_statwt(pipelinemode="automatic")<br />
hifv_plotsummary(pipelinemode="automatic")<br />
hif_makeimlist(intent='PHASE,BANDPASS', specmode='cont')<br />
hif_makeimages(hm_masking='none')<br />
finally:<br />
h_save()<br />
<br />
</source><br />
<br />
Now that we have the script, we can execute the pipeline. Type on the command line the following.<br />
<br />
<source lang="bash"><br />
# On the command line, for your own installation of CASA 6.4.1-12<br />
casa --pipeline --nogui -c casa_pipescript.py<br />
<br />
# If using an NRAO computer, to select the right CASA version use instead<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64 --pipeline --nogui -c casa_pipescript.py<br />
</source><br />
<br />
Now you can go and get a cup of coffee or lunch; this will 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.<br />
<pre style="background-color: #E0FFFF;"><br />
2021-11-25 00:55:08 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.psf.tt0<br />
2021-11-25 00:55:08 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.pb.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.residual.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter1.image.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter1.image.tt0<br />
<br />
2021-11-25 00:55:20 INFO: Saving context to 'pipeline-20211124T225215.context'<br />
</pre><br />
<br />
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 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagmanager(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',mode='restore',versionname='applycal_5')<br />
<br />
applycal(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
antenna='*&*',<br />
gaintable=['TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_2.gc.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_3.opac.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_4.rq.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_6.ants.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_2.finaldelay.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_4.finalBPcal.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_5.averagephasegain.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_7.finalampgaincal.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_8.finalphasegaincal.tbl'],<br />
gainfield=['', '', '', '', '', '', '', '', ''], interp=['', '', '', '',<br />
'', 'linear,linearflag', '', '', ''], spwmap=[[], [], [], [], [], [],<br />
[], [], []], calwt=[False, False, False, False, False, False, False,<br />
False, False], parang=False, applymode='calflagstrict', flagbackup=False)<br />
<br />
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
mode='rflag', correlation='ABS_RR,LL', intent='*CALIBRATE*',<br />
datacolumn='corrected', ntime='scan', combinescans=False,<br />
extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0,<br />
action='apply', flagbackup=True, savepars=True)<br />
<br />
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
mode='rflag', correlation='ABS_RR,LL', intent='*TARGET*',<br />
datacolumn='corrected', ntime='scan', combinescans=False,<br />
extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0,<br />
action='apply', flagbackup=True, savepars=True)<br />
<br />
statwt(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', minsamp=8,<br />
datacolumn='corrected')<br />
<br />
split(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',outputvis='TDRW0001_calibrated.ms',datacolumn='corrected',spw='2~9')<br />
</source><br />
<br />
This applies the flagging state before the final [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] stage of the pipeline, then reapplies the calibration to the corrected column with ''parang=False'', disabling the parallactic angle corrections. After that, we rerun RFI 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.<br />
<br />
If you still have the "--nogui" version of CASA running go ahead and close it. Then reopen it without the "--nogui" as we will need the GUIs for further data inspection. <br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
Antennas in the D-array may be shadowed at low elevations. If shadowing<br />
occurs, sensitivity will be affected.<br />
<br />
NOTE!: The VLA is still recovering from a long power outage, and these data may<br />
have unusual artifacts, missing antennas or IFs, ect., in them. NRAO staff will <br />
examine the data closely after observing to determine if they meet the criteria for <br />
a successful observation.<br />
<br />
Antenna ea05: S-band receiver cooling after work performed, currently 65/177K,<br />
thus we expect lower sensitivity from this antenna.<br />
Antenna ea12: C-band receiver warm for cold head replacement.<br />
<br />
Winds at 5-7 m/s, API RMS phase around 4.5 deg, 10-20% sky cover, cumuliform and stratiform clouds. <br />
</pre><br />
<br />
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/VLA/Polarization/pipeline-20230103T175723.tgz '].<br />
<br />
Inside the weblog you have access to the overview page and the listobs task output that provide some basic information about the data. <br />
<br />
You will note that there are four sources observed. Here the sources are introduced briefly, with more detail contained in the sections below in which they are used:<br />
* 0137+331=3C48, which will serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have precisely known flux density, the spectral bandpass, and the polarization position angle;<br />
* J0259+0747, which will serve as a calibrator for the visibility phases and can be used to determine the instrumental polarization;<br />
* J2355+4950, which can serve as a secondary instrumental polarization calibrator or to check residual instrumental polarization, and;<br />
* 3C75, which is the science target.<br />
<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: /lustre/aoc/sciops/alawson/casaguides/TDRW0001_calibrated.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Emmanuel Momjian Project: uid://evla/pdb/35621723 <br />
Observation: EVLA<br />
Data records: 5503680 Total elapsed time = 9910 seconds<br />
Observed from 04-Oct-2018/05:47:35.0 to 04-Oct-2018/08:32:45.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
04-Oct-2018/05:47:35.0 - 05:48:30.0 3 0 0137+331=3C48 30888 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]<br />
05:48:35.0 - 05:49:00.0 4 0 0137+331=3C48 14040 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]<br />
05:49:05.0 - 05:53:25.0 5 0 0137+331=3C48 146016 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_POL_ANGLE#UNSPECIFIED]<br />
05:53:30.0 - 05:57:55.0 6 1 J2355+4950 148824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
05:58:00.0 - 06:03:55.0 7 2 J0259+0747 199368 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:04:00.0 - 06:18:55.0 8 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:19:00.0 - 06:20:10.0 9 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:20:15.0 - 06:35:05.0 10 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:35:10.0 - 06:36:20.0 11 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:36:25.0 - 06:51:20.0 12 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:51:25.0 - 06:52:30.0 13 2 J0259+0747 36504 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:52:35.0 - 07:07:30.0 14 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:07:35.0 - 07:08:45.0 15 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:08:50.0 - 07:23:40.0 16 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:23:45.0 - 07:26:25.0 17 2 J0259+0747 89856 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:26:30.0 - 07:41:25.0 18 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:41:30.0 - 07:42:40.0 19 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:42:45.0 - 07:57:35.0 20 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:57:40.0 - 07:58:50.0 21 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:58:55.0 - 08:13:50.0 22 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:13:55.0 - 08:15:05.0 23 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
08:15:10.0 - 08:30:00.0 24 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:30:05.0 - 08:32:45.0 25 2 J0259+0747 89856 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 NONE 0137+331=3C48 01:37:41.299431 +33.09.35.13299 J2000 0 190944<br />
1 NONE J2355+4950 23:55:09.458169 +49.50.08.34001 J2000 1 148824<br />
2 NONE J0259+0747 02:59:27.076633 +07.47.39.64322 J2000 2 651456<br />
3 NONE 3C75 02:57:42.630000 +06.01.04.80000 J2000 3 4512456<br />
Spectral Windows: (8 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 EVLA_S#A0C0#2 64 TOPO 2488.000 2000.000 128000.0 2551.0000 12 RR RL LR LL<br />
1 EVLA_S#A0C0#3 64 TOPO 2616.000 2000.000 128000.0 2679.0000 12 RR RL LR LL<br />
2 EVLA_S#A0C0#4 64 TOPO 2744.000 2000.000 128000.0 2807.0000 12 RR RL LR LL<br />
3 EVLA_S#A0C0#5 64 TOPO 2872.000 2000.000 128000.0 2935.0000 12 RR RL LR LL<br />
4 EVLA_S#A0C0#6 64 TOPO 3000.000 2000.000 128000.0 3063.0000 12 RR RL LR LL<br />
5 EVLA_S#A0C0#7 64 TOPO 3128.000 2000.000 128000.0 3191.0000 12 RR RL LR LL<br />
6 EVLA_S#A0C0#8 64 TOPO 3256.000 2000.000 128000.0 3319.0000 12 RR RL LR LL<br />
7 EVLA_S#A0C0#9 64 TOPO 3384.000 2000.000 128000.0 3447.0000 12 RR RL LR LL<br />
Sources: 32<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 0137+331=3C48 0 - - <br />
0 0137+331=3C48 1 - - <br />
0 0137+331=3C48 2 - - <br />
0 0137+331=3C48 3 - - <br />
0 0137+331=3C48 4 - - <br />
0 0137+331=3C48 5 - - <br />
0 0137+331=3C48 6 - - <br />
0 0137+331=3C48 7 - - <br />
1 J2355+4950 2 - - <br />
1 J2355+4950 3 - - <br />
1 J2355+4950 4 - - <br />
1 J2355+4950 5 - - <br />
1 J2355+4950 6 - - <br />
1 J2355+4950 7 - - <br />
2 J0259+0747 2 - - <br />
2 J0259+0747 3 - - <br />
2 J0259+0747 4 - - <br />
2 J0259+0747 5 - - <br />
2 J0259+0747 6 - - <br />
2 J0259+0747 7 - - <br />
3 3C75 2 - - <br />
3 3C75 3 - - <br />
3 3C75 4 - - <br />
3 3C75 5 - - <br />
3 3C75 6 - - <br />
3 3C75 7 - - <br />
Antennas: 27:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
</pre><br />
<br />
Note that the antenna IDs, which are numbered sequentially up to the total number of antennas in the array (from 0 to 26 in this instance), do not correspond to the actual antenna names (ea01 to ea28). Instead, these eaNumbers correspond to those painted on the antennas themselves. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs].<br />
<br />
Both to get a sense of the array, as well as identify the location of the reference antenna that we told the pipeline to choose for parallel hand calibration, have a look at the antenna setup page. For calibration purposes, you would generally 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 choosing an outer antenna to increase the bias toward longer baselines.<br />
<br />
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 [https://casaguides.nrao.edu/index.php?title=VLA-S-CASA_Pipeline-CASA6.4.1 VLA CASA Pipeline Guide]. We assume that the pipeline calibration is good and can use it as a starting point for further calibration steps focusing on polarization calibration and imaging.<br />
<br />
== Examining and Editing the Data ==<br />
<br />
At this point we must start CASA. If you have not used CASA before, some helpful tips are available on the [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/usingcasa.html Getting Started in CASA] page.<br />
<br />
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. <br />
<br />
Start by inspecting these three particular antennas using the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field', plotfile='colorbyfield.jpeg')<br />
</source><br />
[[Image:Colorbyfield_CASA6.2.1.jpeg|200px|right|thumb|Figure 1: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''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.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
The default x- and y-axis parameters are 'time' and 'amp', so the above call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 been left to defaults, but it is possible to select them from within the plotms GUI. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, bandpass, and polarization angle calibrator source), is the brightest source in this observation. The next brightest is the second source observed, J2355+4950, a compact symmetric object (CSO; radio galaxy) 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. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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).<br />
<br />
You should spend several minutes displaying the data in various formats. You can save the version of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] plot as a graphics file by using the menu bar in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] GUI to select the ''Export...'' option under the Export menu.<br />
<br />
Another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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. <br />
<br />
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, we want to fully average each scan). 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.<br />
<br />
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, and non-averaged data. 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, because we are looking at the calibrated visibilities; however, you are seeing 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. <br />
{|<br />
| [[File:Plotms-J0259+0747-Amp-vs-UVdist-CASA6.2.1.jpeg|200px|left|thumb|Figure 2A: plotms view of amp vs. uvdist of J0259+0747, a point source]]<br />
| [[File:Plotms-3C75-Amp-vs-UVwave-CASA6.2.1.jpeg|200px|center|thumb|Figure 2B: plotms view of amp vs. uvwave of 3C 75, a resolved source]]<br />
| [[File:Plotms-3C48-delays-ea01ea21_CASA6.2.1.jpeg|200px|right|thumb|Figure 2C: plotms view of phase vs. channel on one baselines, showing phase delay across the calibrated bandpass]]<br />
|}<br />
<br />
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. <br />
<br />
[[Image:Plotms-3C75guide-datastream-CASA6.2.1.jpeg|200px|right|thumb|Figure 3: datastream view of MS]]<br />
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).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
From this display you can immediately see that flagging performed by the pipeline is present. <br />
<br />
In the following we note on a couple issues that you might have found while inspecting data in this section. We will take care of those through additional flagging.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Issues that you might find:<br />
- ea12, scan 17: amplitude spike at the end of the scan (can be spotted already in Figure 1)<br />
- Residual RFI (see Figure 2A)<br />
</pre><br />
<br />
In the case of the amplitude spike, we can flag the affected time period by invoking the casa task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata]. It is a good idea to save the original flags before performing any flagging by setting '''flagbackup=True'''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TDRW0001_calibrated.ms', flagbackup=True, mode='manual', antenna='ea12',scan='17',timerange='07:25:57~07:26:18')<br />
</source><br />
<br />
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 a good job at this, but there are still some RFI left; we will perform some additional flagging steps in the next section. <br />
<br />
=== Additional Flagging ===<br />
<br />
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). You will notice some left over RFI on the bandpass calibrator in RR, LL. However, we also need to pay particular attention to RL, LR (see Figure 4A). Here we consider calibrators only; we will perform additional flagging on the target field at a later stage. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# for parallel hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RR,LL')<br />
# for cross-hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RL,LR')<br />
</source> <br />
<br />
{|<br />
| [[File:Plotms-preflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|left|thumb|Figure 4a: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency before additional flagging]]<br />
| [[File:Plotms-rflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|right|thumb|Figure 4b: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency after executing addition run of rflag]]<br />
|}<br />
<br />
Since we are dealing with point sources, we do not have to worry about overflagging of shorter baselines, so we can run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# for the parallel hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='tfcrop',<br />
field='0~2',<br />
correlation='',<br />
freqfit='line',<br />
extendflags=False,<br />
flagbackup=False)<br />
<br />
# for the cross-hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='rflag',<br />
datacolumn='data',<br />
field='0~2',<br />
correlation='RL,LR',<br />
extendflags=True,<br />
flagbackup=False)<br />
</source> <br />
<br />
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.<br />
<br />
== Polarization Calibration ==<br />
<br />
<pre style="background-color: #fffacd;"><br />
Polarization calibration is done in three steps:<br />
<br />
* First, we determine the instrumental delay between the two polarization outputs;<br />
<br />
* 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;<br />
<br />
* Third, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C48 here). <br />
</pre><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html#Polarization-Calibration CASA related documentation] also provides helpful information on polarization calibration steps and the different options that are available. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 that 3C48 had an outburst in 2017 and is expected to show a significant degree of variability at higher frequencies in the first instance, progressively affecting lower frequencies as time passes since the event. Since we have applied the pipeline calibration and not corrected for parallactic angle, we can continue polarization calibration using a split measurement set. <br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 codes TPOL0003 or TCAL0009.<br />
<br />
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 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); of these sources, 3C48, 3C138, and 3C147 have been found to be variable. These coefficients are then passed to the setjy task as lists along with the reference frequency and the Stokes I flux density.<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
As an example on how to derive the polarization parameters for the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call, you can perform the following next steps or jump right to the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call below. <br />
<br />
=== Deriving the Polarization Properties of the Polarization Angle Calibrator ===<br />
<br />
First, we tabulate the frequency dependent Stokes I flux density, polarization fraction, and polarization angle in a textfile, which we will call 3C48.dat. The data is taken from [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/flux-density-scale-polarization-leakage-polarization-angle-tables] and the corresponding Stokes I value is calculated from the Perley & Butler (2017) scale. <br />
<br />
Note: The polarization angle values given in the tables have not been derotated.<br />
<br />
<pre><br />
# Frequency I P.F. P.A.<br />
# (GHz) (Jy) (rad)<br />
1.022 20.68 0.00293 0.07445<br />
1.465 15.62 0.00457 -0.60282<br />
1.865 12.88 0.00897 0.39760<br />
2.565 9.82 0.01548 -1.97046<br />
3.565 7.31 0.02911 -1.46542<br />
4.885 5.48 0.04286 -1.24875<br />
6.680 4.12 0.05356 -1.15533<br />
8.435 3.34 0.05430 -1.10638<br />
11.320 2.56 0.05727 -1.08602<br />
14.065 2.14 0.06097 -1.09597<br />
16.564 1.86 0.06296 -1.11891<br />
19.064 1.67 0.06492 -1.18266<br />
25.564 1.33 0.07153 -1.25369<br />
32.064 1.11 0.06442 -1.32430<br />
37.064 1.00 0.06686 -1.33697<br />
42.064 0.92 0.05552 -1.46381<br />
48.064 0.82 0.06773 -1.46412<br />
</pre><br />
<br />
Now to fit Stokes I, we execute in CASA the following commands. These could also be put into a text file and run from inside the CASA prompt using [https://casadocs.readthedocs.io/en/v6.4.1/api/casashell/execfile.html?highlight=execfile#casashell.execfile execfile].<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def S(f,S,alpha,beta):<br />
return S*(f/3.0)**(alpha+beta*np.log10(f/3.0))<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(S, data[0:6,0], data[0:6,1])<br />
print('I@3GHz', popt[0], ' Jy')<br />
print('alpha', popt[1])<br />
print('beta', popt[2])<br />
print( 'Covariance')<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,1], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), S(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Flux Density (Jy)')<br />
plt.show()<br />
<br />
</source><br />
<br />
This will generate a plot for visual inspection, as well as the following text output. <br />
<br />
<pre><br />
I@3GHz 8.555570817459328 Jy<br />
alpha -0.8863795595286049<br />
beta -0.14320026298724836<br />
Covariance<br />
[[1.30835675e-04 1.69587670e-05 2.05918186e-06]<br />
[1.69587670e-05 1.36709052e-05 2.62217377e-05]<br />
[2.05918186e-06 2.62217377e-05 6.27504685e-05]]<br />
</pre><br />
<br />
This provides the coefficients for Stokes I flux density at 3 GHz, the spectral index (alpha), and curvature (beta). It also provides the covariance matrix for the fit.<br />
<br />
We repeat the same for the polarization fraction.<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PF(f,a,b,c,d):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(PF, data[0:6,0], data[0:6,2])<br />
print("Polfrac Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,2], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), PF(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Fraction')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polfrac Polynomial: [ 0.02152856 0.03937167 0.003804 -0.01969663]<br />
Covariance<br />
[[ 2.52776017e-07 3.20765692e-07 -7.13270651e-07 -8.06571096e-07]<br />
[ 3.20765692e-07 4.07949498e-06 -5.46918397e-07 -1.05897559e-05]<br />
[-7.13270651e-07 -5.46918397e-07 3.26372075e-06 1.85490535e-06]<br />
[-8.06571096e-07 -1.05897559e-05 1.85490535e-06 3.07101526e-05]]<br />
</pre><br />
<br />
<source lang="python"><br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PA(f,a,b,c,d,e):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3+e**((f-3.0)/3.0)**4<br />
<br />
# Derotate the 1.8GHz point's polarization angle<br />
data[2,3] = data[2,3]-np.pi<br />
<br />
# Fit 2 - 9 GHz data points<br />
popt, pcov = curve_fit(PA, data[2:8,0], data[2:8,3])<br />
print("Polangle Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[2:8,0], data[2:8,3], 'ro', label='data')<br />
plt.plot(np.arange(1,9,0.1), PA(np.arange(1,9,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Angle (rad)')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polangle Polynomial: [-2.74375466 1.77557424 -1.77089873 0.60309194 0.96199514]<br />
Covariance<br />
[[ 5.97681212e-03 6.08206221e-03 -2.00614015e-02 -1.82633882e-03<br />
8.18331342e-03]<br />
[ 6.08206221e-03 2.68419354e-01 -6.09514004e-02 -1.36381216e+00<br />
1.05931297e+00]<br />
[-2.00614015e-02 -6.09514004e-02 1.52116682e-01 -1.32931084e-03<br />
-4.98635228e-02]<br />
[-1.82633882e-03 -1.36381216e+00 -1.32931084e-03 8.12008149e+00<br />
-6.20697680e+00]<br />
[ 8.18331342e-03 1.05931297e+00 -4.98635228e-02 -6.20697680e+00<br />
4.76282285e+00]]<br />
</pre><br />
<br />
=== Setting the Polarization Calibrator Models ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Reference Frequency for fit values<br />
reffreq = '3.0GHz'<br />
# Stokes I flux density<br />
I = 8.55557<br />
# Spectral Index<br />
alpha = [-0.8864, -0.1432]<br />
# Polarization Fraction<br />
polfrac = [0.02152856, 0.03937167, 0.003804, -0.01969663]<br />
# Polarization Angle<br />
polangle = [-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514]<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='0137+331=3C48',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[I,0,0,0],<br />
spix=alpha,<br />
reffreq=reffreq,<br />
polindex=polfrac,<br />
polangle=polangle,<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
* ''field='0137+331=3C48' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''spix=alpha=[-0.8864, -0.1432] '': 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.<br />
* ''reffreq='3.0GHz' '': The reference frequency for the input Stokes values.<br />
* ''polindex=polfrac=[0.02152856, 0.03937167, 0.003804, -0.01969663] '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=polangle=[-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514] '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=True'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space by not filling the model column, however due to current bugs it is suggested to not use it)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 (unless you used the execfile() method in which case results will be printed in the CASA log window only):<br />
<pre><br />
{'0': {'0': {'fluxd': array([10.07724056, 0.15082879, 0.01240901, 0. ])},<br />
'1': {'fluxd': array([9.64869223, 0.15381396, 0.04441096, 0. ])},<br />
'2': {'fluxd': array([9.25487752, 0.15053557, 0.07574993, 0. ])},<br />
'3': {'fluxd': array([8.89166708, 0.14187061, 0.10510616, 0. ])},<br />
'4': {'fluxd': array([8.55557 , 0.12889591, 0.13157306, 0. ])},<br />
'5': {'fluxd': array([8.24361379, 0.11273472, 0.15463414, 0. ])},<br />
'6': {'fluxd': array([7.95325066, 0.09444074, 0.17410041, 0. ])},<br />
'7': {'fluxd': array([7.68228356, 0.0749225 , 0.19002888, 0. ])},<br />
'fieldName': '0137+331=3C48'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] as '''myset=setjy(...)'''.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 5A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RR',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 5B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 5C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='model')<br />
</source><br />
<br />
{| <br />
| [[Image:Plotms-3C48-model-amp-RR-CASA6.4.1.png|200px|thumb|left|Figure 5A: Model RR amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-amp-RL-CASA6.4.1.png|200px|thumb|center|Figure 5B: Model RL amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-phs-RL-CASA6.4.1.png|200px|thumb|right|Figure 5C: Model RL phases of 3C48.]]<br />
|}<br />
<br />
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_fluxboot inside the CASA log (file stage12/casapy.log). <br />
<br />
<pre style="background-color: #fffacd;"><br />
2023-01-03 19:07:54 INFO fluxscale:::: Fitted spectrum for J2355+4950 with fitorder=2: Flux density = 1.76871 +/- 0.000646066 (freq=2.98457 GHz) spidx: a_1 (spectral index) =-0.599569 +/- 0.00275835 a_2=-0.196812 +/- 0.0670986 covariance matrix for the fit: covar(0,0)=8.14129e-08 covar(0,1)=-1.12826e-07 covar(0,2)=-2.46336e-05 covar(1,0)=-1.12826e-07 covar(1,1)=2.4614e-05 covar(1,2)=0.000242613 covar(2,0)=-2.46336e-05 covar(2,1)=0.000242613 covar(2,2)=0.0145649<br />
<br />
2023-01-03 19:07:55 INFO fluxscale:::: Fitted spectrum for J0259+0747 with fitorder=2: Flux density = 0.970568 +/- 0.000712514 (freq=2.98457 GHz) spidx: a_1 (spectral index) =0.169919 +/- 0.00510126 a_2=-0.143294 +/- 0.134104 covariance matrix for the fit: covar(0,0)=1.87159e-06 covar(0,1)=-2.56746e-06 covar(0,2)=-0.000583154 covar(1,0)=-2.56746e-06 covar(1,1)=0.000479139 covar(1,2)=-9.51772e-05 covar(2,0)=-0.000583154 covar(2,1)=-9.51772e-05 covar(2,2)=0.331122<br />
</pre><br />
<br />
This translates to the following [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] calls.<br />
<br />
<source lang="python"><br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J2355+4950',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[1.76871, 0, 0, 0],<br />
spix=[-0.599569, -0.196812],<br />
reffreq="2984571609.0079317Hz",<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J0259+0747',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[0.970568, 0, 0, 0],<br />
spix=[0.169919, -0.143294],<br />
reffreq='2984571609.0079317Hz',<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
Just as the pipeline did for the parallel-hand (RR,LL) delays before bandpass calibration, we solve for the cross-hand (RL,LR) delays because of the residual delay difference between the R and L on the reference antenna used for the original delay calibration (''ea10'' in this tutorial). 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]. Since the release of CASA 6.1.2, 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 (here 8 spectral windows 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Solve using Multiband Delay<br />
kcross_mbd = "TDRW0001_calibrated.Kcross_mbd" <br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_mbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan,spw",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
<br />
# Solve using Single Band Delay<br />
kcross_sbd = "TDRW0001_calibrated.Kcross_sbd"<br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_sbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
</source><br />
<br />
[[Image:Plotms-3C48-Kcross-delay-CASA6.4.1.png|200px|thumb|right|Figure 6: Single band cross-hand delay solutions.]]<br />
We can plot the single band solutions (see Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=kcross_sbd,xaxis='frequency',yaxis='delay',antenna='ea10',coloraxis='corr')<br />
</source><br />
You can also look at the solutions reported in the logger.<br />
<br />
<pre style="background-color: #fffacd;"><br />
For multiband delay there is one solution:<br />
Multi-band cross-hand delay=3.68373 nsec<br />
<br />
For single band delay there are 8 solutions:<br />
Spw=0 Global cross-hand delay=5.58964 nsec<br />
Spw=1 Global cross-hand delay=1.49907 nsec<br />
Spw=2 Global cross-hand delay=-1.26208 nsec<br />
Spw=3 Global cross-hand delay=0.522402 nsec<br />
Spw=4 Global cross-hand delay=4.25883 nsec<br />
Spw=5 Global cross-hand delay=1.25194 nsec<br />
Spw=6 Global cross-hand delay=3.69895 nsec<br />
Spw=7 Global cross-hand delay=3.02677 nsec<br />
</pre><br />
<br />
Notice that the per spectral window solutions are very scattered. The mean delay is 2.32 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.68 ns. <br />
<br />
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, because 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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 also our complex gain calibrator. The observations of J0259+0747 have 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# J2355+4950 / Df<br />
dtab_J2355 = 'TDRW0001_calibrated.Df' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J2355,<br />
field='J2355+4950',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
<br />
# J0259+0747 / Df+QU<br />
dtab_J0259 = 'TDRW0001_calibrated.DfQU' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J0259,<br />
intent='CALIBRATE_POL_LEAKAGE#UNSPECIFIED',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df+QU',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
</source><br />
<br />
* ''caltable '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal] will create a new calibration table containing the leakage solutions, which we specify with the ''caltable'' parameter.<br />
* ''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.<br />
* ''spw='0~7' '': Select all spectral windows.<br />
* ''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.<br />
* ''solint='inf,2MHz', combine='scan' '': One solution over the entire run, per spectral channel of 2 MHz<br />
* ''gaintable=['kcross_mbd']'': The previous Kcross multiband delay is applied <br />
* ''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' '').<br />
<br />
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.<br />
<pre style="background-color: #fffacd;"><br />
Fractional polarization solution for J0259+0747 (spw = 0): : Q = 0.0259049, U = 0.0336301 (P = 0.0424505, X = 26.1967 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 1): : Q = 0.0139972, U = 0.0382244 (P = 0.0407066, X = 34.944 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 2): : Q = 0.0165052, U = 0.0384224 (P = 0.0418175, X = 33.3765 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 3): : Q = 0.0118274, U = 0.0422875 (P = 0.0439104, X = 37.1871 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 4): : Q = 0.00816816, U = 0.0404744 (P = 0.0412903, X = 39.2952 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 5): : Q = 0.00649365, U = 0.0412879 (P = 0.0417954, X = 40.5309 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 6): : Q = -0.00225595, U = 0.0429258 (P = 0.0429851, X = 46.5042 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 7): : Q = -0.00776873, U = 0.0474773 (P = 0.0481087, X = 49.6465 deg)<br />
</pre><br />
<br />
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 26 to 49 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' ''. <br />
<br />
After we run the two executions of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to ensure that everything looks good and to compare the results using two different calibrators and poltype methods.<br />
{|<br />
|[[Image:Plotms-J0259-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7a: J0259+0747 Df amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7b: J2355+4950 Df+QU amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J0259-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7c: J0259+0747 Df phase vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7d: J2355+4950 Df+QU phase vs. frequency for antenna ea01.]]<br />
|}<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J2355,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J0259,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
plotms(vis=dtab_J2355,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
</source><br />
This will produce plots similar to those shown in Figures 7A-D. You can cycle through the antennas by clicking the Next button within [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. You should see leakages of between 5&ndash;17% 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. <br />
<br />
We can also display these in a single plot versus antenna index (see Figure 8):<br />
[[Image:Plotms-J0259-DfQU-CASA6.4.1.png|thumb|Figure 8: Df+QU solutions for J0259+0747 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata]. If everything went correctly, then this step should not be necessary for this dataset.<br />
<source lang="python"><br />
flagdata(vis=dtab_J2355, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)<br />
<br />
flagdata(vis=dtab_J0259, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)<br />
</source><br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], but this time set parameter ''poltype='Xf', ''which specifies a frequency-dependent (''f'') position angle (''X'') calibration using the source 3C48, the position angle of which is known, having set this earlier with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
xtab = "TDRW0001_calibrated.Xf"<br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=xtab,<br />
spw='0~7',<br />
field='0137+331=3C48',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
poltype='Xf',<br />
refant = 'ea10',<br />
gaintable=[kcross_mbd,dtab_J0259],<br />
gainfield=['',''],<br />
spwmap=[[0,0,0,0,0,0,0,0],[]],<br />
append=False)<br />
</source><br />
<br />
[[Image:Plotms-3C48-Xf-CASA6.4.1.png|thumb|Figure 9: Xf solutions versus frequency.]]<br />
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 refant when performing polarization calibration.<br />
<br />
It is strongly suggested you check that the calibration worked properly by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 9):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=xtab,xaxis='frequency',yaxis='phase',coloraxis='spw')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = 'TDRW0001_calibrated.ms',<br />
field='',<br />
gainfield=['', '', ''], <br />
flagbackup=True,<br />
interp=['', '', ''],<br />
gaintable=[kcross_mbd,dtab_J0259,xtab],<br />
spw='0~7', <br />
calwt=[False, False, False], <br />
applymode='calflagstrict', <br />
antenna='*&*', <br />
spwmap=[[0,0,0,0,0,0,0,0],[],[]], <br />
parang=True)<br />
<br />
</source><br />
<br />
* ''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; here derived from J0259+0747), and the R-L phase corrections (xtab).<br />
* ''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; 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''.<br />
* ''parang '': If polarization calibration has been performed, set parameter ''parang=True''.<br />
<br />
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 10A-10F):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='RR,LL',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J0259-fld2-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',avgbaseline=True,<br />
plotfile='Plotms-J0259-fld2-corrected-phase-CASA6.4.1.jpeg')<br />
</source><br />
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. <br />
<br />
{|<br />
| [[Image:Plotms-3C48-fld0-corrected-amp-CASA6.4.1.png|thumb|Figure 10A: amplitude vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-3C48-fld0-corrected-phase-CASA6.4.1.png|thumb|Figure 10B: phase vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-amp-CASA6.4.1.png|thumb|Figure 10C: amplitude vs channel for J2355+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-phase-CASA6.4.1.png|thumb|Figure 10D: phase vs channel for J2355+4950 RR,LL]]<br />
|}<br />
<br />
{|<br />
| [[Image:Plotms-J0259-fld2-corrected-amp-CASA6.4.1.png|thumb|Figure 10E: amplitude vs channel for J0259+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J0259-fld2-corrected-phase-CASA6.4.1.png|thumb|Figure 10F: phase vs channel for J0259+4950 RR,RL,LR,LL with baseline averaging]]<br />
|}<br />
<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
<br />
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. <br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='TDRW0001_calibrated.ms',outputvis='3C75.ms',<br />
datacolumn='corrected',field='3')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science target.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to place the target field into a measurement set for imaging and joint deconvolution.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms',datacolumn='data',minsamp=8)<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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. In general, 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>). 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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html section of the CASA documentation.]<br />
<br />
[[Image:plotms_3c75-uvwave-CASA6.4.1.png|thumb|Figure 11: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C75 at 3000 MHz]]<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] which both Fourier transforms the data and deconvolves the resulting image. We will use a multi-scale cleaning algorithm because our target source, a complex radio galaxy, contains both diffuse, extended structures on large spatial scales as well as point-like components. This approach will do a better job of modeling the image than the classic clean delta function. For broader examples of many [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Multi-scale Clean ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvwave.jpeg',avgspw=False,overwrite=True)<br />
</source><br />
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 will also see some outliers there which are primarily from residual amplitude errors of ea05, that 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>\theta\approx\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. <br />
<br />
The 3C75 binary black hole system is known to have a maximum extent of at least 8-9 arcminutes, corresponding to about 147 pixels for the chosen cell size. Therefore, we need to choose an image size that covers most of the extent of the source. To aid deconvolution, especially when bright sources far from phase center are present, we should at the minimum image the size of 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<br />
In this tutorial, we will run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
[[Image:3C75-tclean-interactive-start-CASA6.2.1.png|thumb|Figure 12: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
* ''vis='3C75.ms' '': this split MS contains the target field only.<br />
* ''imagename='3C75_initial' '': our output image cubes will all start with this name root, e.g., 3C75_initial.image<br />
* ''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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] task define an appropriate threshold. The number of iterations should then be set high enough to reach the threshold found by tclean.<br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer] window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=480,cell='3.4arcsec' '': See the discussion above regarding setting the image size and cell size. If only one value is specified for the parameter, the same value is used in both directions (declination and right ascension).<br />
* ''stokes='IQUV' '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will output an image cube containing all: total intensity I, and Stokes Q, U, and V.<br />
* ''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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3C75-tclean-interactive-300iters-CASA6.2.1.png|thumb|Figure 13: After the first approximately 300 iterations of multi-scale mfs clean]]<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, an [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.imview.html imview] 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. Similarly, select "All channels". 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 radio galaxy jets. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will do before returning to the GUI (''cycleniter''). 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 ''cycleniter'' value that you might had set before starting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3C75-tclean-interactive-residuals-CASA6.2.1.png|thumb|Figure 14: Interactive residuals after about 13000 iterations of multi-scale mfs clean]]<br />
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 cleaned mask region). As mentioned before, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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)<br />
* ''.pb.tt0'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.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)<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
* ''.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)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
<br />
{|<br />
|[[Image:3c75-CARTA-multiscale-initialI-CASA6.4.1.png|thumb|Figure 15A: Viewer panel of final restored Stokes I image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialQ-CASA6.4.1.png|thumb|Figure 15B: Viewer panel of final restored Stokes Q image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialU-CASA6.4.1.png|thumb|Figure 15C: Viewer panel of final restored Stokes U image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialV-CASA6.4.1.png|thumb|Figure 15D: Viewer panel of final restored Stokes V image (using viridis colormap, linear scale, 99.9%)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use [https://cartavis.org/ CARTA] to look at your image.<br />
<br />
Take some time to play with the color scale to better emphasize the faint emission and to see the underlying noise patterns. For the figures above we selected the viridis color map, the linear scale function, and the 99.9% data range on the histogram. You can also use the Animators slider/buttons to switch between the four different Stokes parameter images that were computed. If you are unfamiliar with [https://cartavis.org/ CARTA] then take some time to look over its extensive built in documentation and help features. You can find its searchable online manual via the "Help" button at the top or to get more information on a particular widget you can click the corresponding "?" button near it. If you click the Animator tab you'll also notice that [https://cartavis.org/ CARTA] attempts to create total polarization, linear polarization, fractional total polarization, fractional linear polarization, and linear polarization angle images for you. This can be quite convenient, but we'll show how to create these yourself later in this guide.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 response fall-off in the edges. In principle, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] produces primary beam response image, and if we had set parameter ''pbcor=True'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] would had saved a primary beam corrected restored image of our target. Since we used ''deconvolver='mtmfs' '' and ''nterms=2'', the calculation of the primary beam response requires special treatment. To perform wideband primary beam correction, we will use task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. In the future this task will be incorporated into [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but until then this separate task needs to be used.<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms',imagename='3C75_initial',nterms=2, action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
The task will produce primary beam corrected images of our target (3C75_initial.pbcor.image.tt0, 3C75_initial.pbcor.image.tt1, 3C75_initial.pbcor.image.alpha, 3C75_initial.pbcor.image.alpha.error). You can open image 3C75_initial.pbcor.image.tt0 in [https://cartavis.org/ CARTA], and compare it to screenshots in Figure 15. You will see noise (and signal) at the edges of the image has indeed increased.<br />
<br />
== Self-Calibration ==<br />
<br />
Before we get started with self-calibration, it might be good to check whether we need to perform 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. The division will help us to see low level interfrence we might not otherwise notice by just looking at the data column. 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvdist_resid_RR.png',avgspw=False,overwrite=True)<br />
<br />
# If you made a mistake above and didn't clean the polarization as well, then this plot will be empty.<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RL',<br />
plotfile='plotms_3c75-uvdist_resid_RL.png',avgspw=False,overwrite=True)<br />
</source><br />
<br />
{|<br />
| [[Image:plotms-3c75-uvdist-residRR-CASA6.4.1-corr.png|thumb|Figure 16A: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RR correlations.]]<br />
| [[Image:plotms-3c75-uvdist-residRL-CASA6.4.1-corr.png|thumb|Figure 16B: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RL correlations.]]<br />
|}<br />
<br />
Since we are seeing a significant amount of weak residual interference, we will take a few steps to reduce these. <br />
<source lang="python"><br />
# In CASA<br />
<br />
# tfcrop<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RR,ABS_LL',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RL,ABS_LR',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
# rflag<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RR,LL',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RL,LR',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
# extend flags<br />
flagdata(vis='3C75.ms',mode='extend',flagbackup=False)<br />
</source><br />
<br />
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 our dataset. <br />
<br />
'''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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as: <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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) \over 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 some discussion in the old CASA Reference Manual on [http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#section%3Aim.selfcal self calibration] (see Section 5.11), but more detailed discussion can be found in lectures on [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-stsci/cde_selfcal.pdf Self-calibration] given at NRAO community days. <br />
<br />
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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
** 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column to form a new CORRECTED_DATA column ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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 create a new Stokes I image, which we will use to generate a series of gain corrections (phase only self-calibration) that will be stored in 3C75.ScG0. With this solution, we then perform bandpass self-calibration to remove any amplitude slope that might be present. Next, we apply the derived phase and amplitude corrections to the data to form a set of self-calibrated data, and then re-image the dataset (3C75_selfcal.image). For the purpose of self-calibration, note that in the clean before the self-calibration, it is important that we only use the Stokes I model so that any cleaned polarization does not affect the gaincal. We first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.delmod.html?highlight=delmod# delmod] on the MS to get rid of the previous polarized model, and run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to generate Stokes I-only image. In principle, it is possible to use the previous image cube and extract the Stokes I model using the CASA toolkit and have [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] fill the model column appropriately. For simplicity, we just re-image with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] selecting only Stokes I.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3C75.ms')<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial_I",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
As discussed, this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] call will 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's total flux density as possible, but not include low level questionable features or sub-structures (ripples) that might be due to calibration or deconvolution artifacts. We modified the two parameters controlling [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]'s minor and major cycles to the following values ''cycleniter=750'' and ''niter=3500'' to reflect this, but you may find that you don't even need 3500 iterations for this first [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] pass.<br />
<br />
If you are happy with the new image, perform the following self-calibration steps:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3C75.ms', caltable='3C75.ScG0', field='', solint='inf', refant='ea10', <br />
spw='',minsnr=3.0, gaintype='G', parang=False, calmode='p')<br />
<br />
bandpass(vis='3C75.ms', caltable='3C75.ScB0', field='', solint='inf', refant='ea10', minsnr=3.0, spw='',<br />
parang = False, gaintable=['3C75.ScG0'], interp=[])<br />
<br />
applycal(vis='3C75.ms', gaintable=['3C75.ScG0','3C75.ScB0'], spw='', applymode='calflagstrict', parang=False)<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities which will be used by next execution of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] which may or may not be a good thing. You can control the action of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] by changing the value of parameter ''applymode''. Setting ''applymode='calflagstrict' ''will be more stringent about flagging data points without valid calibration, while ''applymode='calonly' '' will calibrate those with solutions while passing unchanged the data without solutions. You can see ahead of time what applycal will do by executing it with ''applymode='trial' ''which will do the reporting but nothing else. In our example we used '' applymode='calflagstrict' '', but you will notice that the reported flagged fraction has not changed much, only increasing by 0.6%. This is a good thing.<br />
<br />
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 produce a better image. We do this by invoking the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command once again. <br />
<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_selfcal_1",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
Commonly this self-calibration procedure is applied multiple times. In Figures 17A & B you can see a comparison of the shallow Stokes I image before self-calibration and after two self-calibration steps. The first self-calibration round was done as instructed in this section, while the second round was executed with ''solint='120s' '' and new solution tables were created (3C75.ScG1, 3C75.ScB1).<br />
{|<br />
| [[Image:3c75-initial_I-CASA6.4.1.png|thumb|Figure 17A: Shallow Stokes I image before self-calibration.]]<br />
| [[Image:3c75-selfcal_2-CASA6.4.1.png|thumb|Figure 17B: Stokes I image after two rounds of self-calibration.]]<br />
|} <br />
<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to remove an image, or even a set of gain corrections, change something and try again. Having said that, here are several guidelines to consider:<br />
<br />
* 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'' 'selfcal_1' ''is attached to various files to help keep straight what is what. Successive iterations of self-cal could then be'' 'selfcal_2' '','' 'selfcal_3' '', etc.<br />
<br />
* Care is required in setting ''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.<br />
<br />
* A common metric for self-calibration is whether the ''dynamic range'' (= peak flux density/rms) of the image has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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 features 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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''. One may 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager].<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] 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.)<br />
<br />
== Final Polarization Images ==<br />
<br />
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 artifacts 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, and make the image larger to incorporate the bright source into our model in this tclean execution.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms', minsamp=8, datacolumn='corrected', flagbackup=True)<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_final_large",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
The final restored Stokes I,Q,U, and V images are shown in Figures 18A&ndash;D. We've set the color scale to match between the images. Note that there is still a star like pattern in the residuals which are artifacts 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. 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 increases the further away one gets from the beam center. Additionally, the two polarization beams do not sit on top 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. <br />
<br />
{|<br />
| [[Image:3C75-final-I-CASA6.4.1.png|thumb|Figure 18A: Viewer panel of final restored Stokes I image.]]<br />
| [[Image:3C75-final-Q-CASA6.4.1.png|thumb|Figure 18B: Viewer panel of final restored Stokes Q image.]]<br />
| [[Image:3C75-final-U-CASA6.4.1.png|thumb|Figure 18C: Viewer panel of final restored Stokes U image.]]<br />
| [[Image:3C75-final-V-CASA6.4.1.png|thumb|Figure 18D: Viewer panel of final restored Stokes V image.]]<br />
|}<br />
<br />
Note, that these images are not yet primary beam corrected and are displayed on log scaling. You should play with the color scaling as well as the bias/contrast widget in [https://cartavis.org/ CARTA] to better see the faint emission.<br />
<br />
=== Spectral & Polarization Maps ===<br />
<br />
Note: If you are using [https://cartavis.org/ CARTA] then several of the next steps are actually unnecessary. If supplied a proper IQUV image [https://cartavis.org/ CARTA] will compute polarization intensity, linear polarization, fractional polarization intensity, fractional linear polarization intensity, and polarization angle maps for you. We show the steps one would have to take to manually create some of the images below for completeness. When possible the Figures shown will be using values/images that are generated soley by [https://cartavis.org/ CARTA] itself. You are encouraged though to still manually create your own set of images and then overlay them with the [https://cartavis.org/ CARTA] generated images to see that they match.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. As demonstrated earlier, the task can also correct the images for the telescope's primary beam response; this correction will make the images science ready. Parameter ''action='pbcor' '' will perform both actions (correct for the primary beam and calculate spectral index map) while parameter ''threshold'' sets minimum flux density above which the spectral index is calculated (this will allow us to mask all the noise regions).<br />
<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms', imagename='3C75_final_large', nterms=2, threshold='1.0mJy/beam', action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
<br />
For further study of polarization properties, you might want to convert the Stokes images into something more useful for scientific analysis. We will use CASA to calculate polarization intensity, <math>\sqrt{Q^2 + U^2 + V^2}</math>, and polarization angle, <math>{atan2 (U,Q) \over 2}</math>, maps from the final Stokes I,Q,U,V images. You can then look at those with [https://cartavis.org/ CARTA]. For example, Figure 19B shows the polarization intensity image. Since we've yet to apply any mask, the polarization angle image made in the next step will also contain values from low signal-to-noise data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Obtain image for the polarization intensity<br />
immath(outfile='3C75_final.poli',mode='poli',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
# Obtain image for the polarization angle<br />
immath(outfile='3C75_final.pola',mode='pola',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
</source><br />
<br />
{|<br />
| [[Image:3C75-final-spindx-CASA6.4.1.png|thumb|Figure 19A: CASA Computed spectral index map.]]<br />
| [[Image:3C75-final-Ptot-casa6.4.1.png|thumb|Figure 19B: CARTA Computed polarization intensity image.]]<br />
| [[Image:3C75-final-PAng-CASA6.4.1.png|thumb|Figure 19C: CARTA Computed polarized angles (vectors) superposed on the Stokes I raster image plane. We've selected an intensity threshold within CARTA to exclude low S/N points.]]<br />
|}<br />
<br />
Note that for calculations of the polarization intensity and angle images you may &mdash; but do not need to &mdash; use primary beam corrected images; your results will be the same. This is because the primary beam correction cancels out in the equations for these two polarization quantities. If you want to visualize the polarization vectors on top of the Stokes I image, we need to add a mask for the low noise values. <br />
<br />
<source lang="python"><br />
# In CASA<br />
!cp -r '3C75_final.poli' polimg<br />
<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.Q.image',stokes='Q')<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.U.image',stokes='U')<br />
<br />
subimPI='polimg'<br />
ia.open(subimPI)<br />
ia.calcmask(mask=subimPI+'>5e-4',name='mymask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.Q.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.U.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
immath(imagename=['3C75_final.Q.image', '3C75_final.U.image'], mode='pola', outfile='3C75_final.pola.masked')<br />
</source><br />
These steps take the polarized intensity image calculated above (Figure 19B) and create a mask using a polarization intensity threshold of 5e-4 Jy/beam. 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 created from the polarization intensity image. Finally, we can load the Stokes I as raster image into [https://cartavis.org/ CARTA] and add the polarization angle as vectors. You can do this by matching the final IQUV image, 3C75_final_large.image.tt0, and the newly created polarization angle image in WCS space by clicking the "XY" under the "Matching" column of the Image List widget. Then open the Vector Overlay Configuration widget to create the vectors. You can compare the vectors calculated with immath to the ones that [https://cartavis.org/ CARTA] generates for you. You may notice that there are some vectors that appear to disagree with each other. If so, it is likely caused by the pixel averaging being done within [https://cartavis.org/ CARTA], which you can toggle off to confirm. 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.<br />
<br />
=== Rotation Measures ===<br />
<br />
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. <br />
<br />
To produce an image cube with 8 channels, each image is using 128 MHz of bandwidth, we call [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_chan8",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="cube",<br />
reffreq="",<br />
nchan=-1,<br />
start="",<br />
width=64,<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
mask='3C75_final_large.mask',<br />
normtype="flatnoise",<br />
deconvolver="multiscale",<br />
scales=[0, 6, 18],<br />
nterms=1,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="none",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=False)<br />
</source><br />
<br />
Now we use the CASA toolkit to access data for four pixels in the image cube to visualize and fit the rotation measure. <br />
<source lang="python"><br />
# In CASA<br />
import matplotlib<br />
# to display<br />
matplotlib.use('TkAgg')<br />
import matplotlib.pyplot as plt<br />
import numpy as np<br />
<br />
ia.open('3C75_chan8.image')<br />
<br />
# number of channels/frequencies<br />
nunr = 8 <br />
<br />
tt = ia.getchunk()<br />
nu = np.linspace(2.551e9,3.319e9,num=nunr)<br />
c = 2.99792458e8<br />
<br />
Q1 = tt[418,444,1,:nunr]<br />
U1 = tt[418,444,2,:nunr]<br />
Q2 = tt[376,419,1,:nunr]<br />
U2 = tt[376,419,2,:nunr]<br />
Q3 = tt[383,401,1,:nunr]<br />
U3 = tt[383,401,2,:nunr]<br />
Q4 = tt[395,398,1,:nunr]<br />
U4 = tt[395,398,2,:nunr]<br />
<br />
chi1 = 0.5*np.arctan2(U1,Q1)<br />
chi2 = 0.5*np.arctan2(U2,Q2)<br />
chi3 = 0.5*np.arctan2(U3,Q3)<br />
chi4 = 0.5*np.arctan2(U4,Q4)<br />
<br />
#locate the values that are nan and delete these indices from nu<br />
indx1=np.argwhere(chi1==0)<br />
indx2=np.argwhere(chi2==0)<br />
indx3=np.argwhere(chi3==0)<br />
indx4=np.argwhere(chi4==0)<br />
<br />
nu1=np.delete(nu,indx1)<br />
lam1 = c/nu1<br />
lamsq1 = lam1*lam1<br />
<br />
nu2=np.delete(nu,indx2)<br />
lam2 = c/nu2<br />
lamsq2 = lam2*lam2<br />
<br />
nu3=np.delete(nu,indx3)<br />
lam3 = c/nu3<br />
lamsq3 = lam3*lam3<br />
<br />
nu4=np.delete(nu,indx4)<br />
lam4 = c/nu4<br />
lamsq4 = lam4*lam4<br />
<br />
#drop the zero values<br />
chi1=np.delete(chi1,indx1)<br />
chi2=np.delete(chi2,indx2)<br />
chi3=np.delete(chi3,indx3)<br />
chi4=np.delete(chi4,indx4)<br />
<br />
fit1 = np.polyfit(lamsq1,chi1,1)<br />
fit_fn1 = np.poly1d(fit1)<br />
slope1 = fit1[0]<br />
intercept1 = fit1[1]<br />
fit2 = np.polyfit(lamsq2,chi2,1)<br />
fit_fn2 = np.poly1d(fit2)<br />
slope2 = fit2[0]<br />
intercept2 = fit2[1]<br />
fit3 = np.polyfit(lamsq3,chi3,1)<br />
fit_fn3 = np.poly1d(fit3)<br />
slope3 = fit3[0]<br />
intercept3 = fit3[1]<br />
fit4 = np.polyfit(lamsq4,chi4,1)<br />
fit_fn4 = np.poly1d(fit4)<br />
slope4 = fit4[0]<br />
intercept4 = fit4[1]<br />
<br />
plt.figure(1)<br />
plt.title('Overall Title')<br />
plt.subplot(221)<br />
plt.title('Point 1: (418,444)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi1$')<br />
plt.scatter(lamsq1,chi1,color='r')<br />
plt.plot(lamsq1,fit_fn1(lamsq1),'r--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope1,intercept1))<br />
plt.legend(loc=2)<br />
<br />
plt.subplot(222)<br />
plt.title('Point 2: (376,419)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi2$')<br />
plt.scatter(lamsq2,chi2,color='b')<br />
plt.plot(lamsq2,fit_fn2(lamsq2),'b--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope2,intercept2))<br />
plt.legend(loc=1)<br />
<br />
plt.subplot(223)<br />
plt.title('Point 3: (383,401)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi3$')<br />
plt.scatter(lamsq3,chi3,color='g')<br />
plt.plot(lamsq3,fit_fn3(lamsq3),'g--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope3,intercept3))<br />
plt.legend(loc=3)<br />
<br />
plt.subplot(224)<br />
plt.title('Point 4: (395,398)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi4$')<br />
plt.scatter(lamsq4,chi4,color='m')<br />
plt.plot(lamsq4,fit_fn4(lamsq4),'m--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope4,intercept4))<br />
plt.legend(loc=1)<br />
plt.tight_layout()<br />
<br />
plt.show()<br />
#Or to save the figure<br />
plt.savefig('3C75_rmscript_8chan4px.png')<br />
<br />
ia.close()<br />
</source><br />
<br />
The resulting plots are shown in Figure 20A. Alternatively, there exists a CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] which does this basic fitting for you while taking into account the <math>N \pi</math> ambiguity (refer to [http://adsabs.harvard.edu/full/1986A%26A...156..234L] for more info). The fits using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for our case of 3C 75 by making images per spectral window is shown in Figure 20B. Here we set the maximum acceptable position angle error to 20 degrees. If larger, then no rotation measures are calculated.<br />
<br />
<source lang='python'><br />
# In CASA<br />
rmfit('3C75_chan8.image',rm='3C75_chan8_rm.image',rmerr='3C75_chan8_rm.image.err',maxpaerr=0.35)<br />
</source> <br />
<br />
{|<br />
| [[Image:3C75-rmscript-8chan4px-CASA6.4.1.png|thumb|Figure 20A: Rotation measures extracted for 4 pixels from an 8 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmfit-8chan-CARTA-CASA6.4.1.png|thumb|Figure 20B: RMFIT rotation measure image generated from 8 channel image cube.]]<br />
|}<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] task has many more options; for example, you are able to provide a foreground rotation measure to subtract. <br />
<br />
Now we can compare the rotation measures extracted for the 4 pixels from the 8 channel image cube with the values derived in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for the same pixels. In most cases the values are more or less comparable.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Point<br />
! RM Lin. Fit.<br />
! RM RMFIT<br />
|-<br />
| 1<br />
| -65.46<br />
| -57.29<br />
|-<br />
| 2<br />
| 10.41<br />
| 66.62<br />
|-<br />
| 3<br />
| -71.71<br />
| -65.14<br />
|-<br />
| 4<br />
| -7.30<br />
| -5.07<br />
|}<br />
<br />
As our source is rather bright, we can derive an IQUV image not just per averaged spectral window as we just did, but rather per channel. To achieve this you can change the above [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] parameter width from 64 to 1, which will result in 512 channels spanning all 8 spectral windows. Note when imaging each channel, the edge channels are flagged which results in the PSF being blank for channels sourrounding each spectral window and some of the images being blank. Don't forget to change the imagename parameter when re-running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. Due to the increased size of the cube you may find that your machine's avaliable memory struggles to keep up with the new [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command. If so, then you can reduce the image size to lower the required memory. For our 512 channel cube we reduced the image size from 800x800 to 270x270. If you do reduce the image size as we have then you'll need to make use of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.imsubimage.html?highlight=imsubimage imsubimage] to first reduce your old image's mask size so it can be used again for your smaller image. Following the same steps as for the 8 channel image cube (adjusting for the new number of channels and new pixel indices for our points of interest), you would then obtain the results shown in Figure 21 where again the polarization position angle as a function of lambda square is shown together with the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] image. We can clearly see that the source exhibits complex structure beyond a simple linear fit 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.<br />
<br />
<br />
{|<br />
| [[Image:3C75-rmscript-512chan4px-CASA6.4.1.png|thumb|Figure 21A: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmscript-512chan4px-ylim-CASA6.4.1.png|thumb|Figure 21B: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75 with enforced limits on y axis for points 1 and 2 to exclude outlier points from the view and see better the variation of the data.]]<br />
| [[Image:3C75-rmfit-512chan-CARTA-CASA6.4.1.png|thumb|Figure 21C: RMFIT rotation measure image generated from 512 channel image cube.]]<br />
|}<br />
<br />
<!-- == Image Analysis ==<br />
<br />
The three most basic analyses are to determine peak brightness, flux density, and 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.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3C75_initial.image.tt0')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '02:58:37.309, +05.47.28.628, I, 3e+09Hz',<br />
'max': array([ 0.14971776]),<br />
'maxpos': array([257, 279, 0, 0], dtype=int32),<br />
'maxposf': '02:57:38.755, +06.03.17.399, I, 3e+09Hz',<br />
'mean': array([ 0.00016331]),<br />
'medabsdevmed': array([ 1.74164962e-05]),<br />
'median': array([ 8.04986788e-09]),<br />
'min': array([-0.01785131]),<br />
'minpos': array([258, 278, 1, 0], dtype=int32),<br />
'minposf': '02:57:38.527, +06.03.13.999, Q, 3e+09Hz',<br />
'npts': array([ 921600.]),<br />
'q1': array([ -1.69758441e-05]),<br />
'q3': array([ 1.78917744e-05]),<br />
'quartile': array([ 3.48676185e-05]),<br />
'rms': array([ 0.0031646]),<br />
'sigma': array([ 0.00316039]),<br />
'sum': array([ 150.50313612]),<br />
'sumsq': array([ 9.22954767]),<br />
'trc': array([479, 479, 3, 0], dtype=int32),<br />
'trcf': '02:56:48.133, +06.14.37.233, V, 3e+09Hz'}<br />
<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.14971776306629181<br />
</pre><br />
and so the peak flux density is 0.150 Jy/beam.<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# 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.<br />
<br />
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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3C75_final.image.tt0' &<br />
</source><br />
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. <br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
2659 1.243414e+02 4.676248e-02 5.722227e-02 <br />
Std dev Minimum Maximum region count <br />
3.298586e-02 -1.063592e-03 1.484267e-01 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
</pre><br />
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.<br />
<br />
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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
1216 -3.509342e-02 -2.885972e-05 6.186932e-05 <br />
Std dev Minimum Maximum region count <br />
5.474847e-05 -1.558577e-04 1.394379e-04 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
<br />
</pre><br />
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.<br />
<br />
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. <br />
<br />
<!-- Similar analysis can be performed on the polarization and spectral index maps, this will be left to the user. --><br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
<br />
<!-- Edited for content & context by T. Perreault 2021-12-30 --><br />
<!-- Last edit by Anna D. Kapinska 2021-12-17 --><br />
<!-- Edited by Frank Schinzel 2021-03-30 --></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Polarization_pipe_Tutorial&diff=35149VLA Polarization pipe Tutorial2023-05-22T19:14:54Z<p>Akapinsk: Created page with "Category:EVLACategory:CalibrationCategory:VLA <b>This CASA Guide is for the monolithic, not the modular pip-wheel version, version 6.4.1 of CASA that includes the..."</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<b>This CASA Guide is for the monolithic, not the modular pip-wheel version, version 6.4.1 of CASA that includes the VLA 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. This guide also uses [https://cartavis.org/ CARTA] as its choice of image viewer. We strongly recommend using [https://cartavis.org/ CARTA] over the built in CASA viewer, used by tasks such as [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casaviewer.imview.html?highlight=imview imview], as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASA viewer and [https://cartavis.org/ CARTA], as well as instructions on how to use [https://cartavis.org/ CARTA] at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs].<br />
<br />
== Overview ==<br />
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. <br />
[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. The calibration part of this tutorial can be performed on a laptop computer with sufficient storage. The imaging part, however, will require more computing power and memory. This CASA guide was also used as basis for a presentation on polarization calibration at the 7th VLA data reduction workshop: [https://science.nrao.edu/science/meetings/2019/vla-data-reduction/Schinzel_Polarization.pdf]<br />
<br />
== How to Use This CASA Guide ==<br />
<br />
Here are a number of possible ways to run CASA, described in more detail in [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/usingcasa.html Getting Started in CASA]. In brief, there are at least three different ways to run CASA:<br />
<br />
* Interactively examining task inputs. In this mode, one types '''default taskname''' to load the task (this will also set all the task parameters to default values), '''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 />
* 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.<br />
<br />
* 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).<br />
<br />
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.<br />
<br />
== Obtaining the Data ==<br />
<br />
If starting from scratch, you can obtain the dataset from the [https://data.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. Make sure to select to download the SDM-BDF dataset, if you want to start from the lowest level, because by default a .ms file will be provided by the archive.<br />
<br />
For those who 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/VLA/Polarization/TDRW0001_calibrated_CASA6.4.1.ms.tgz '] (size: 11 GB). It is recommended to use the command line tool '''wget''' to download the calibrated data or directly download through the browser. You will need to untar and unzip the file using the command: 'tar -xzvf TDRW0001_calibrated_CASA6.4.1.ms.tgz' and then give it the same name as the guide uses: 'mv TDRW0001_calibrated_CASA6.4.1.ms TDRW0001_calibrated.ms'. Then you can skip ahead to the section 'The Observation'.<br />
<br />
== Pipeline Calibration of Parallel Hands (RR/LL) ==<br />
<br />
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 at: [https://science.nrao.edu/facilities/vla/data-processing/pipeline https://science.nrao.edu/facilities/vla/data-processing/pipeline].<br />
<br />
In this example, we will not run the pipeline in its standard way but tweak it to force a certain reference antenna, ea10. 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 is better to use one of the outer antennas for reference, which provides 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. <br />
<br />
<source lang="python"><br />
# casa_pipescript.py<br />
<br />
__rethrow_casa_exceptions = True<br />
context = h_init()<br />
context.set_state('ProjectSummary', 'observatory', 'Karl G. Jansky Very Large Array')<br />
context.set_state('ProjectSummary', 'telescope', 'EVLA')<br />
context.set_state('ProjectStructure', 'recipe_name', 'hifv_cal')<br />
try:<br />
hifv_importdata(vis=['TDRW0001.sb35624494.eb35628826.58395.23719237269'], session=['default'])<br />
hifv_hanning(pipelinemode="automatic")<br />
hifv_flagdata(hm_tbuff='1.5int', intents='*POINTING*,*FOCUS*,*ATMOSPHERE*,*SIDEBAND_RATIO*, *UNKNOWN*, *SYSTEM_CONFIGURATION*, *UNSPECIFIED#UNSPECIFIED*')<br />
hifv_vlasetjy(pipelinemode="automatic")<br />
hifv_priorcals(pipelinemode="automatic")<br />
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')<br />
hifv_checkflag(pipelinemode="automatic")<br />
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')<br />
hifv_checkflag(checkflagmode='semi')<br />
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')<br />
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')<br />
hifv_fluxboot(fitorder=2, 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')<br />
hifv_finalcals(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')<br />
hifv_applycals(pipelinemode="automatic")<br />
hifv_targetflag(intents='*CALIBRATE*,*TARGET*')<br />
hifv_statwt(pipelinemode="automatic")<br />
hifv_plotsummary(pipelinemode="automatic")<br />
hif_makeimlist(intent='PHASE,BANDPASS', specmode='cont')<br />
hif_makeimages(hm_masking='none')<br />
finally:<br />
h_save()<br />
<br />
</source><br />
<br />
Now that we have the script, we can execute the pipeline. Type on the command line the following.<br />
<br />
<source lang="bash"><br />
# On the command line, for your own installation of CASA 6.4.1-12<br />
casa --pipeline --nogui -c casa_pipescript.py<br />
<br />
# If using an NRAO computer, to select the right CASA version use instead<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64 --pipeline --nogui -c casa_pipescript.py<br />
</source><br />
<br />
Now you can go and get a cup of coffee or lunch; this will 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.<br />
<pre style="background-color: #E0FFFF;"><br />
2021-11-25 00:55:08 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.psf.tt0<br />
2021-11-25 00:55:08 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.pb.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter0.residual.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter1.image.tt0<br />
2021-11-25 00:55:09 INFO: Plotting oussid.s19_0._0137+331_3C48__bp.S_band.cont.I.iter1.image.tt0<br />
<br />
2021-11-25 00:55:20 INFO: Saving context to 'pipeline-20211124T225215.context'<br />
</pre><br />
<br />
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 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagmanager(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',mode='restore',versionname='applycal_5')<br />
<br />
applycal(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
antenna='*&*',<br />
gaintable=['TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_2.gc.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_3.opac.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_4.rq.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_priorcals.s5_6.ants.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_2.finaldelay.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_4.finalBPcal.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_5.averagephasegain.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_7.finalampgaincal.tbl',<br />
'TDRW0001.sb35624494.eb35628826.58395.23719237269.ms.hifv_finalcals.s13_8.finalphasegaincal.tbl'],<br />
gainfield=['', '', '', '', '', '', '', '', ''], interp=['', '', '', '',<br />
'', 'linear,linearflag', '', '', ''], spwmap=[[], [], [], [], [], [],<br />
[], [], []], calwt=[False, False, False, False, False, False, False,<br />
False, False], parang=False, applymode='calflagstrict', flagbackup=False)<br />
<br />
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
mode='rflag', correlation='ABS_RR,LL', intent='*CALIBRATE*',<br />
datacolumn='corrected', ntime='scan', combinescans=False,<br />
extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0,<br />
action='apply', flagbackup=True, savepars=True)<br />
<br />
flagdata(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',<br />
mode='rflag', correlation='ABS_RR,LL', intent='*TARGET*',<br />
datacolumn='corrected', ntime='scan', combinescans=False,<br />
extendflags=False, winsize=3, timedevscale=4.0, freqdevscale=4.0,<br />
action='apply', flagbackup=True, savepars=True)<br />
<br />
statwt(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms', minsamp=8,<br />
datacolumn='corrected')<br />
<br />
split(vis='TDRW0001.sb35624494.eb35628826.58395.23719237269.ms',outputvis='TDRW0001_calibrated.ms',datacolumn='corrected',spw='2~9')<br />
</source><br />
<br />
This applies the flagging state before the final [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] stage of the pipeline, then reapplies the calibration to the corrected column with ''parang=False'', disabling the parallactic angle corrections. After that, we rerun RFI 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.<br />
<br />
If you still have the "--nogui" version of CASA running go ahead and close it. Then reopen it without the "--nogui" as we will need the GUIs for further data inspection. <br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
Antennas in the D-array may be shadowed at low elevations. If shadowing<br />
occurs, sensitivity will be affected.<br />
<br />
NOTE!: The VLA is still recovering from a long power outage, and these data may<br />
have unusual artifacts, missing antennas or IFs, ect., in them. NRAO staff will <br />
examine the data closely after observing to determine if they meet the criteria for <br />
a successful observation.<br />
<br />
Antenna ea05: S-band receiver cooling after work performed, currently 65/177K,<br />
thus we expect lower sensitivity from this antenna.<br />
Antenna ea12: C-band receiver warm for cold head replacement.<br />
<br />
Winds at 5-7 m/s, API RMS phase around 4.5 deg, 10-20% sky cover, cumuliform and stratiform clouds. <br />
</pre><br />
<br />
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/VLA/Polarization/pipeline-20230103T175723.tgz '].<br />
<br />
Inside the weblog you have access to the overview page and the listobs task output that provide some basic information about the data. <br />
<br />
You will note that there are four sources observed. Here the sources are introduced briefly, with more detail contained in the sections below in which they are used:<br />
* 0137+331=3C48, which will serve as a calibrator for the visibility amplitudes, i.e., it is assumed to have precisely known flux density, the spectral bandpass, and the polarization position angle;<br />
* J0259+0747, which will serve as a calibrator for the visibility phases and can be used to determine the instrumental polarization;<br />
* J2355+4950, which can serve as a secondary instrumental polarization calibrator or to check residual instrumental polarization, and;<br />
* 3C75, which is the science target.<br />
<br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: /lustre/aoc/sciops/alawson/casaguides/TDRW0001_calibrated.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Emmanuel Momjian Project: uid://evla/pdb/35621723 <br />
Observation: EVLA<br />
Data records: 5503680 Total elapsed time = 9910 seconds<br />
Observed from 04-Oct-2018/05:47:35.0 to 04-Oct-2018/08:32:45.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
04-Oct-2018/05:47:35.0 - 05:48:30.0 3 0 0137+331=3C48 30888 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]<br />
05:48:35.0 - 05:49:00.0 4 0 0137+331=3C48 14040 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [SYSTEM_CONFIGURATION#UNSPECIFIED]<br />
05:49:05.0 - 05:53:25.0 5 0 0137+331=3C48 146016 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_POL_ANGLE#UNSPECIFIED]<br />
05:53:30.0 - 05:57:55.0 6 1 J2355+4950 148824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
05:58:00.0 - 06:03:55.0 7 2 J0259+0747 199368 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:04:00.0 - 06:18:55.0 8 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:19:00.0 - 06:20:10.0 9 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:20:15.0 - 06:35:05.0 10 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:35:10.0 - 06:36:20.0 11 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:36:25.0 - 06:51:20.0 12 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
06:51:25.0 - 06:52:30.0 13 2 J0259+0747 36504 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
06:52:35.0 - 07:07:30.0 14 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:07:35.0 - 07:08:45.0 15 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:08:50.0 - 07:23:40.0 16 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:23:45.0 - 07:26:25.0 17 2 J0259+0747 89856 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:26:30.0 - 07:41:25.0 18 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:41:30.0 - 07:42:40.0 19 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:42:45.0 - 07:57:35.0 20 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:57:40.0 - 07:58:50.0 21 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
07:58:55.0 - 08:13:50.0 22 3 3C75 502632 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:13:55.0 - 08:15:05.0 23 2 J0259+0747 39312 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
08:15:10.0 - 08:30:00.0 24 3 3C75 499824 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:30:05.0 - 08:32:45.0 25 2 J0259+0747 89856 [0,1,2,3,4,5,6,7] [5, 5, 5, 5, 5, 5, 5, 5] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED,CALIBRATE_POL_LEAKAGE#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 4<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 NONE 0137+331=3C48 01:37:41.299431 +33.09.35.13299 J2000 0 190944<br />
1 NONE J2355+4950 23:55:09.458169 +49.50.08.34001 J2000 1 148824<br />
2 NONE J0259+0747 02:59:27.076633 +07.47.39.64322 J2000 2 651456<br />
3 NONE 3C75 02:57:42.630000 +06.01.04.80000 J2000 3 4512456<br />
Spectral Windows: (8 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 EVLA_S#A0C0#2 64 TOPO 2488.000 2000.000 128000.0 2551.0000 12 RR RL LR LL<br />
1 EVLA_S#A0C0#3 64 TOPO 2616.000 2000.000 128000.0 2679.0000 12 RR RL LR LL<br />
2 EVLA_S#A0C0#4 64 TOPO 2744.000 2000.000 128000.0 2807.0000 12 RR RL LR LL<br />
3 EVLA_S#A0C0#5 64 TOPO 2872.000 2000.000 128000.0 2935.0000 12 RR RL LR LL<br />
4 EVLA_S#A0C0#6 64 TOPO 3000.000 2000.000 128000.0 3063.0000 12 RR RL LR LL<br />
5 EVLA_S#A0C0#7 64 TOPO 3128.000 2000.000 128000.0 3191.0000 12 RR RL LR LL<br />
6 EVLA_S#A0C0#8 64 TOPO 3256.000 2000.000 128000.0 3319.0000 12 RR RL LR LL<br />
7 EVLA_S#A0C0#9 64 TOPO 3384.000 2000.000 128000.0 3447.0000 12 RR RL LR LL<br />
Sources: 32<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 0137+331=3C48 0 - - <br />
0 0137+331=3C48 1 - - <br />
0 0137+331=3C48 2 - - <br />
0 0137+331=3C48 3 - - <br />
0 0137+331=3C48 4 - - <br />
0 0137+331=3C48 5 - - <br />
0 0137+331=3C48 6 - - <br />
0 0137+331=3C48 7 - - <br />
1 J2355+4950 2 - - <br />
1 J2355+4950 3 - - <br />
1 J2355+4950 4 - - <br />
1 J2355+4950 5 - - <br />
1 J2355+4950 6 - - <br />
1 J2355+4950 7 - - <br />
2 J0259+0747 2 - - <br />
2 J0259+0747 3 - - <br />
2 J0259+0747 4 - - <br />
2 J0259+0747 5 - - <br />
2 J0259+0747 6 - - <br />
2 J0259+0747 7 - - <br />
3 3C75 2 - - <br />
3 3C75 3 - - <br />
3 3C75 4 - - <br />
3 3C75 5 - - <br />
3 3C75 6 - - <br />
3 3C75 7 - - <br />
Antennas: 27:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
</pre><br />
<br />
Note that the antenna IDs, which are numbered sequentially up to the total number of antennas in the array (from 0 to 26 in this instance), do not correspond to the actual antenna names (ea01 to ea28). Instead, these eaNumbers correspond to those painted on the antennas themselves. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs].<br />
<br />
Both to get a sense of the array, as well as identify the location of the reference antenna that we told the pipeline to choose for parallel hand calibration, have a look at the antenna setup page. For calibration purposes, you would generally 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 choosing an outer antenna to increase the bias toward longer baselines.<br />
<br />
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 [https://casaguides.nrao.edu/index.php?title=VLA-S-CASA_Pipeline-CASA6.4.1 VLA CASA Pipeline Guide]. We assume that the pipeline calibration is good and can use it as a starting point for further calibration steps focusing on polarization calibration and imaging.<br />
<br />
== Examining and Editing the Data ==<br />
<br />
At this point we must start CASA. If you have not used CASA before, some helpful tips are available on the [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/usingcasa.html Getting Started in CASA] page.<br />
<br />
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. <br />
<br />
Start by inspecting these three particular antennas using the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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. <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field', plotfile='colorbyfield.jpeg')<br />
</source><br />
[[Image:Colorbyfield_CASA6.2.1.jpeg|200px|right|thumb|Figure 1: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''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.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
The default x- and y-axis parameters are 'time' and 'amp', so the above call to [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 been left to defaults, but it is possible to select them from within the plotms GUI. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, bandpass, and polarization angle calibrator source), is the brightest source in this observation. The next brightest is the second source observed, J2355+4950, a compact symmetric object (CSO; radio galaxy) 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. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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).<br />
<br />
You should spend several minutes displaying the data in various formats. You can save the version of the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] plot as a graphics file by using the menu bar in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] GUI to select the ''Export...'' option under the Export menu.<br />
<br />
Another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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. <br />
<br />
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, we want to fully average each scan). 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.<br />
<br />
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, and non-averaged data. 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, because we are looking at the calibrated visibilities; however, you are seeing 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. <br />
{|<br />
| [[File:Plotms-J0259+0747-Amp-vs-UVdist-CASA6.2.1.jpeg|200px|left|thumb|Figure 2A: plotms view of amp vs. uvdist of J0259+0747, a point source]]<br />
| [[File:Plotms-3C75-Amp-vs-UVwave-CASA6.2.1.jpeg|200px|center|thumb|Figure 2B: plotms view of amp vs. uvwave of 3C 75, a resolved source]]<br />
| [[File:Plotms-3C48-delays-ea01ea21_CASA6.2.1.jpeg|200px|right|thumb|Figure 2C: plotms view of phase vs. channel on one baselines, showing phase delay across the calibrated bandpass]]<br />
|}<br />
<br />
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. <br />
<br />
[[Image:Plotms-3C75guide-datastream-CASA6.2.1.jpeg|200px|right|thumb|Figure 3: datastream view of MS]]<br />
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).<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
From this display you can immediately see that flagging performed by the pipeline is present. <br />
<br />
In the following we note on a couple issues that you might have found while inspecting data in this section. We will take care of those through additional flagging.<br />
<br />
<pre style="background-color: #fffacd;"><br />
Issues that you might find:<br />
- ea12, scan 17: amplitude spike at the end of the scan (can be spotted already in Figure 1)<br />
- Residual RFI (see Figure 2A)<br />
</pre><br />
<br />
In the case of the amplitude spike, we can flag the affected time period by invoking the casa task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata]. It is a good idea to save the original flags before performing any flagging by setting '''flagbackup=True'''. <br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='TDRW0001_calibrated.ms', flagbackup=True, mode='manual', antenna='ea12',scan='17',timerange='07:25:57~07:26:18')<br />
</source><br />
<br />
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 a good job at this, but there are still some RFI left; we will perform some additional flagging steps in the next section. <br />
<br />
=== Additional Flagging ===<br />
<br />
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). You will notice some left over RFI on the bandpass calibrator in RR, LL. However, we also need to pay particular attention to RL, LR (see Figure 4A). Here we consider calibrators only; we will perform additional flagging on the target field at a later stage. <br />
<br />
<source lang="python"><br />
# In CASA<br />
# for parallel hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RR,LL')<br />
# for cross-hands<br />
plotms(vis='TDRW0001_calibrated.ms',xaxis='frequency',yaxis='amplitude',field='0~2',correlation='RL,LR')<br />
</source> <br />
<br />
{|<br />
| [[File:Plotms-preflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|left|thumb|Figure 4a: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency before additional flagging]]<br />
| [[File:Plotms-rflag-Amp-vs-Freq-CASA6.2.1.jpeg|200px|right|thumb|Figure 4b: plotms() view of calibrators' amplitudes (RL,LR) as a function of frequency after executing addition run of rflag]]<br />
|}<br />
<br />
Since we are dealing with point sources, we do not have to worry about overflagging of shorter baselines, so we can run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# for the parallel hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='tfcrop',<br />
field='0~2',<br />
correlation='',<br />
freqfit='line',<br />
extendflags=False,<br />
flagbackup=False)<br />
<br />
# for the cross-hands<br />
flagdata(vis='TDRW0001_calibrated.ms',<br />
mode='rflag',<br />
datacolumn='data',<br />
field='0~2',<br />
correlation='RL,LR',<br />
extendflags=True,<br />
flagbackup=False)<br />
</source> <br />
<br />
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.<br />
<br />
== Polarization Calibration ==<br />
<br />
<pre style="background-color: #fffacd;"><br />
Polarization calibration is done in three steps:<br />
<br />
* First, we determine the instrumental delay between the two polarization outputs;<br />
<br />
* 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;<br />
<br />
* Third, we solve for the polarization position angle using a source with a known polarization position angle (we use 3C48 here). <br />
</pre><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html#Polarization-Calibration CASA related documentation] also provides helpful information on polarization calibration steps and the different options that are available. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 that 3C48 had an outburst in 2017 and is expected to show a significant degree of variability at higher frequencies in the first instance, progressively affecting lower frequencies as time passes since the event. Since we have applied the pipeline calibration and not corrected for parallactic angle, we can continue polarization calibration using a split measurement set. <br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 codes TPOL0003 or TCAL0009.<br />
<br />
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 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); of these sources, 3C48, 3C138, and 3C147 have been found to be variable. These coefficients are then passed to the setjy task as lists along with the reference frequency and the Stokes I flux density.<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
As an example on how to derive the polarization parameters for the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call, you can perform the following next steps or jump right to the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] call below. <br />
<br />
=== Deriving the Polarization Properties of the Polarization Angle Calibrator ===<br />
<br />
First, we tabulate the frequency dependent Stokes I flux density, polarization fraction, and polarization angle in a textfile, which we will call 3C48.dat. The data is taken from [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/flux-density-scale-polarization-leakage-polarization-angle-tables] and the corresponding Stokes I value is calculated from the Perley & Butler (2017) scale. <br />
<br />
Note: The polarization angle values given in the tables have not been derotated.<br />
<br />
<pre><br />
# Frequency I P.F. P.A.<br />
# (GHz) (Jy) (rad)<br />
1.022 20.68 0.00293 0.07445<br />
1.465 15.62 0.00457 -0.60282<br />
1.865 12.88 0.00897 0.39760<br />
2.565 9.82 0.01548 -1.97046<br />
3.565 7.31 0.02911 -1.46542<br />
4.885 5.48 0.04286 -1.24875<br />
6.680 4.12 0.05356 -1.15533<br />
8.435 3.34 0.05430 -1.10638<br />
11.320 2.56 0.05727 -1.08602<br />
14.065 2.14 0.06097 -1.09597<br />
16.564 1.86 0.06296 -1.11891<br />
19.064 1.67 0.06492 -1.18266<br />
25.564 1.33 0.07153 -1.25369<br />
32.064 1.11 0.06442 -1.32430<br />
37.064 1.00 0.06686 -1.33697<br />
42.064 0.92 0.05552 -1.46381<br />
48.064 0.82 0.06773 -1.46412<br />
</pre><br />
<br />
Now to fit Stokes I, we execute in CASA the following commands. These could also be put into a text file and run from inside the CASA prompt using [https://casadocs.readthedocs.io/en/v6.4.1/api/casashell/execfile.html?highlight=execfile#casashell.execfile execfile].<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def S(f,S,alpha,beta):<br />
return S*(f/3.0)**(alpha+beta*np.log10(f/3.0))<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(S, data[0:6,0], data[0:6,1])<br />
print('I@3GHz', popt[0], ' Jy')<br />
print('alpha', popt[1])<br />
print('beta', popt[2])<br />
print( 'Covariance')<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,1], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), S(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Flux Density (Jy)')<br />
plt.show()<br />
<br />
</source><br />
<br />
This will generate a plot for visual inspection, as well as the following text output. <br />
<br />
<pre><br />
I@3GHz 8.555570817459328 Jy<br />
alpha -0.8863795595286049<br />
beta -0.14320026298724836<br />
Covariance<br />
[[1.30835675e-04 1.69587670e-05 2.05918186e-06]<br />
[1.69587670e-05 1.36709052e-05 2.62217377e-05]<br />
[2.05918186e-06 2.62217377e-05 6.27504685e-05]]<br />
</pre><br />
<br />
This provides the coefficients for Stokes I flux density at 3 GHz, the spectral index (alpha), and curvature (beta). It also provides the covariance matrix for the fit.<br />
<br />
We repeat the same for the polarization fraction.<br />
<source lang="python"><br />
# In CASA<br />
<br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PF(f,a,b,c,d):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3<br />
<br />
# Fit 1 - 5 GHz data points<br />
popt, pcov = curve_fit(PF, data[0:6,0], data[0:6,2])<br />
print("Polfrac Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[0:6,0], data[0:6,2], 'ro', label='data')<br />
plt.plot(np.arange(1,5,0.1), PF(np.arange(1,5,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Fraction')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polfrac Polynomial: [ 0.02152856 0.03937167 0.003804 -0.01969663]<br />
Covariance<br />
[[ 2.52776017e-07 3.20765692e-07 -7.13270651e-07 -8.06571096e-07]<br />
[ 3.20765692e-07 4.07949498e-06 -5.46918397e-07 -1.05897559e-05]<br />
[-7.13270651e-07 -5.46918397e-07 3.26372075e-06 1.85490535e-06]<br />
[-8.06571096e-07 -1.05897559e-05 1.85490535e-06 3.07101526e-05]]<br />
</pre><br />
<br />
<source lang="python"><br />
import numpy as np<br />
from scipy.optimize import curve_fit<br />
import matplotlib.pyplot as plt<br />
<br />
data = np.loadtxt('3C48.dat')<br />
<br />
def PA(f,a,b,c,d,e):<br />
return a+b*((f-3.0)/3.0)+c*((f-3.0)/3.0)**2+d*((f-3.0)/3.0)**3+e**((f-3.0)/3.0)**4<br />
<br />
# Derotate the 1.8GHz point's polarization angle<br />
data[2,3] = data[2,3]-np.pi<br />
<br />
# Fit 2 - 9 GHz data points<br />
popt, pcov = curve_fit(PA, data[2:8,0], data[2:8,3])<br />
print("Polangle Polynomial: ", popt)<br />
print("Covariance")<br />
print(pcov)<br />
<br />
plt.plot(data[2:8,0], data[2:8,3], 'ro', label='data')<br />
plt.plot(np.arange(1,9,0.1), PA(np.arange(1,9,0.1), *popt), 'r-', label='fit')<br />
<br />
plt.title('3C48')<br />
plt.legend()<br />
plt.xlabel('Frequency (GHz)')<br />
plt.ylabel('Lin. Pol. Angle (rad)')<br />
plt.show()<br />
</source><br />
<br />
<pre><br />
Polangle Polynomial: [-2.74375466 1.77557424 -1.77089873 0.60309194 0.96199514]<br />
Covariance<br />
[[ 5.97681212e-03 6.08206221e-03 -2.00614015e-02 -1.82633882e-03<br />
8.18331342e-03]<br />
[ 6.08206221e-03 2.68419354e-01 -6.09514004e-02 -1.36381216e+00<br />
1.05931297e+00]<br />
[-2.00614015e-02 -6.09514004e-02 1.52116682e-01 -1.32931084e-03<br />
-4.98635228e-02]<br />
[-1.82633882e-03 -1.36381216e+00 -1.32931084e-03 8.12008149e+00<br />
-6.20697680e+00]<br />
[ 8.18331342e-03 1.05931297e+00 -4.98635228e-02 -6.20697680e+00<br />
4.76282285e+00]]<br />
</pre><br />
<br />
=== Setting the Polarization Calibrator Models ===<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Reference Frequency for fit values<br />
reffreq = '3.0GHz'<br />
# Stokes I flux density<br />
I = 8.55557<br />
# Spectral Index<br />
alpha = [-0.8864, -0.1432]<br />
# Polarization Fraction<br />
polfrac = [0.02152856, 0.03937167, 0.003804, -0.01969663]<br />
# Polarization Angle<br />
polangle = [-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514]<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='0137+331=3C48',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[I,0,0,0],<br />
spix=alpha,<br />
reffreq=reffreq,<br />
polindex=polfrac,<br />
polangle=polangle,<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
* ''field='0137+331=3C48' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''spix=alpha=[-0.8864, -0.1432] '': 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.<br />
* ''reffreq='3.0GHz' '': The reference frequency for the input Stokes values.<br />
* ''polindex=polfrac=[0.02152856, 0.03937167, 0.003804, -0.01969663] '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=polangle=[-2.74375466, 1.77557424, -1.77089873, 0.60309194, 0.96199514] '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=True'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space by not filling the model column, however due to current bugs it is suggested to not use it)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 (unless you used the execfile() method in which case results will be printed in the CASA log window only):<br />
<pre><br />
{'0': {'0': {'fluxd': array([10.07724056, 0.15082879, 0.01240901, 0. ])},<br />
'1': {'fluxd': array([9.64869223, 0.15381396, 0.04441096, 0. ])},<br />
'2': {'fluxd': array([9.25487752, 0.15053557, 0.07574993, 0. ])},<br />
'3': {'fluxd': array([8.89166708, 0.14187061, 0.10510616, 0. ])},<br />
'4': {'fluxd': array([8.55557 , 0.12889591, 0.13157306, 0. ])},<br />
'5': {'fluxd': array([8.24361379, 0.11273472, 0.15463414, 0. ])},<br />
'6': {'fluxd': array([7.95325066, 0.09444074, 0.17410041, 0. ])},<br />
'7': {'fluxd': array([7.68228356, 0.0749225 , 0.19002888, 0. ])},<br />
'fieldName': '0137+331=3C48'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] as '''myset=setjy(...)'''.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 5A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RR',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 5B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='model')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 5C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='RL',<br />
timerange='',antenna='ea01&ea02',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='model')<br />
</source><br />
<br />
{| <br />
| [[Image:Plotms-3C48-model-amp-RR-CASA6.4.1.png|200px|thumb|left|Figure 5A: Model RR amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-amp-RL-CASA6.4.1.png|200px|thumb|center|Figure 5B: Model RL amplitudes of 3C48.]]<br />
| [[Image:Plotms-3C48-model-phs-RL-CASA6.4.1.png|200px|thumb|right|Figure 5C: Model RL phases of 3C48.]]<br />
|}<br />
<br />
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_fluxboot inside the CASA log (file stage12/casapy.log). <br />
<br />
<pre style="background-color: #fffacd;"><br />
2023-01-03 19:07:54 INFO fluxscale:::: Fitted spectrum for J2355+4950 with fitorder=2: Flux density = 1.76871 +/- 0.000646066 (freq=2.98457 GHz) spidx: a_1 (spectral index) =-0.599569 +/- 0.00275835 a_2=-0.196812 +/- 0.0670986 covariance matrix for the fit: covar(0,0)=8.14129e-08 covar(0,1)=-1.12826e-07 covar(0,2)=-2.46336e-05 covar(1,0)=-1.12826e-07 covar(1,1)=2.4614e-05 covar(1,2)=0.000242613 covar(2,0)=-2.46336e-05 covar(2,1)=0.000242613 covar(2,2)=0.0145649<br />
<br />
2023-01-03 19:07:55 INFO fluxscale:::: Fitted spectrum for J0259+0747 with fitorder=2: Flux density = 0.970568 +/- 0.000712514 (freq=2.98457 GHz) spidx: a_1 (spectral index) =0.169919 +/- 0.00510126 a_2=-0.143294 +/- 0.134104 covariance matrix for the fit: covar(0,0)=1.87159e-06 covar(0,1)=-2.56746e-06 covar(0,2)=-0.000583154 covar(1,0)=-2.56746e-06 covar(1,1)=0.000479139 covar(1,2)=-9.51772e-05 covar(2,0)=-0.000583154 covar(2,1)=-9.51772e-05 covar(2,2)=0.331122<br />
</pre><br />
<br />
This translates to the following [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] calls.<br />
<br />
<source lang="python"><br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J2355+4950',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[1.76871, 0, 0, 0],<br />
spix=[-0.599569, -0.196812],<br />
reffreq="2984571609.0079317Hz",<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
<br />
setjy(vis='TDRW0001_calibrated.ms',<br />
field='J0259+0747',<br />
spw='',<br />
selectdata=False,<br />
timerange="",<br />
scan="",<br />
intent="",<br />
observation="",<br />
scalebychan=True,<br />
standard="manual",<br />
model="",<br />
modimage="",<br />
listmodels=False,<br />
fluxdensity=[0.970568, 0, 0, 0],<br />
spix=[0.169919, -0.143294],<br />
reffreq='2984571609.0079317Hz',<br />
polindex=[],<br />
polangle=[],<br />
rotmeas=0,<br />
fluxdict={},<br />
useephemdir=False,<br />
interpolation="nearest",<br />
usescratch=True,<br />
ismms=False,<br />
)<br />
</source><br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
Just as the pipeline did for the parallel-hand (RR,LL) delays before bandpass calibration, we solve for the cross-hand (RL,LR) delays because of the residual delay difference between the R and L on the reference antenna used for the original delay calibration (''ea10'' in this tutorial). 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]. Since the release of CASA 6.1.2, 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 (here 8 spectral windows 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Solve using Multiband Delay<br />
kcross_mbd = "TDRW0001_calibrated.Kcross_mbd" <br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_mbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan,spw",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
<br />
# Solve using Single Band Delay<br />
kcross_sbd = "TDRW0001_calibrated.Kcross_sbd"<br />
gaincal(vis='TDRW0001_calibrated.ms',<br />
caltable=kcross_sbd,<br />
field='0137+331=3C48',<br />
spw='0~7:5~58',<br />
refant='ea10',<br />
gaintype="KCROSS",<br />
solint="inf",<br />
combine="scan",<br />
calmode="ap",<br />
append=False,<br />
gaintable=[''],<br />
gainfield=[''],<br />
interp=[''],<br />
spwmap=[[]],<br />
parang=True)<br />
</source><br />
<br />
[[Image:Plotms-3C48-Kcross-delay-CASA6.4.1.png|200px|thumb|right|Figure 6: Single band cross-hand delay solutions.]]<br />
We can plot the single band solutions (see Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=kcross_sbd,xaxis='frequency',yaxis='delay',antenna='ea10',coloraxis='corr')<br />
</source><br />
You can also look at the solutions reported in the logger.<br />
<br />
<pre style="background-color: #fffacd;"><br />
For multiband delay there is one solution:<br />
Multi-band cross-hand delay=3.68373 nsec<br />
<br />
For single band delay there are 8 solutions:<br />
Spw=0 Global cross-hand delay=5.58964 nsec<br />
Spw=1 Global cross-hand delay=1.49907 nsec<br />
Spw=2 Global cross-hand delay=-1.26208 nsec<br />
Spw=3 Global cross-hand delay=0.522402 nsec<br />
Spw=4 Global cross-hand delay=4.25883 nsec<br />
Spw=5 Global cross-hand delay=1.25194 nsec<br />
Spw=6 Global cross-hand delay=3.69895 nsec<br />
Spw=7 Global cross-hand delay=3.02677 nsec<br />
</pre><br />
<br />
Notice that the per spectral window solutions are very scattered. The mean delay is 2.32 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.68 ns. <br />
<br />
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, because 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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html 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 also our complex gain calibrator. The observations of J0259+0747 have 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# J2355+4950 / Df<br />
dtab_J2355 = 'TDRW0001_calibrated.Df' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J2355,<br />
field='J2355+4950',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
<br />
# J0259+0747 / Df+QU<br />
dtab_J0259 = 'TDRW0001_calibrated.DfQU' <br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=dtab_J0259,<br />
intent='CALIBRATE_POL_LEAKAGE#UNSPECIFIED',<br />
spw='0~7',<br />
refant='ea10',<br />
poltype='Df+QU',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
gaintable=[kcross_mbd],<br />
gainfield=[''],<br />
spwmap=[[0,0,0,0,0,0,0,0]], <br />
append=False)<br />
</source><br />
<br />
* ''caltable '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal] will create a new calibration table containing the leakage solutions, which we specify with the ''caltable'' parameter.<br />
* ''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.<br />
* ''spw='0~7' '': Select all spectral windows.<br />
* ''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.<br />
* ''solint='inf,2MHz', combine='scan' '': One solution over the entire run, per spectral channel of 2 MHz<br />
* ''gaintable=['kcross_mbd']'': The previous Kcross multiband delay is applied <br />
* ''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' '').<br />
<br />
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.<br />
<pre style="background-color: #fffacd;"><br />
Fractional polarization solution for J0259+0747 (spw = 0): : Q = 0.0259049, U = 0.0336301 (P = 0.0424505, X = 26.1967 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 1): : Q = 0.0139972, U = 0.0382244 (P = 0.0407066, X = 34.944 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 2): : Q = 0.0165052, U = 0.0384224 (P = 0.0418175, X = 33.3765 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 3): : Q = 0.0118274, U = 0.0422875 (P = 0.0439104, X = 37.1871 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 4): : Q = 0.00816816, U = 0.0404744 (P = 0.0412903, X = 39.2952 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 5): : Q = 0.00649365, U = 0.0412879 (P = 0.0417954, X = 40.5309 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 6): : Q = -0.00225595, U = 0.0429258 (P = 0.0429851, X = 46.5042 deg)<br />
Fractional polarization solution for J0259+0747 (spw = 7): : Q = -0.00776873, U = 0.0474773 (P = 0.0481087, X = 49.6465 deg)<br />
</pre><br />
<br />
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 26 to 49 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' ''. <br />
<br />
After we run the two executions of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to ensure that everything looks good and to compare the results using two different calibrators and poltype methods.<br />
{|<br />
|[[Image:Plotms-J0259-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7a: J0259+0747 Df amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Damp-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7b: J2355+4950 Df+QU amplitude vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J0259-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7c: J0259+0747 Df phase vs. frequency for antenna ea01.]]<br />
|[[Image:Plotms-J2355-Dphs-ea01-CASA6.4.1_Antennaea01@W06.png|thumb|Figure 7d: J2355+4950 Df+QU phase vs. frequency for antenna ea01.]]<br />
|}<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J2355,xaxis='freq',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis=dtab_J0259,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
plotms(vis=dtab_J2355,xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
<br />
</source><br />
This will produce plots similar to those shown in Figures 7A-D. You can cycle through the antennas by clicking the Next button within [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. You should see leakages of between 5&ndash;17% 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. <br />
<br />
We can also display these in a single plot versus antenna index (see Figure 8):<br />
[[Image:Plotms-J0259-DfQU-CASA6.4.1.png|thumb|Figure 8: Df+QU solutions for J0259+0747 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=dtab_J0259,xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata]. If everything went correctly, then this step should not be necessary for this dataset.<br />
<source lang="python"><br />
flagdata(vis=dtab_J2355, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)<br />
<br />
flagdata(vis=dtab_J0259, mode='clip', correlation='ABS_ALL', clipminmax=[0.0, 0.25], datacolumn='CPARAM', clipoutside=True, action='apply', flagbackup=False, savepars=False)<br />
</source><br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.polcal.html polcal], but this time set parameter ''poltype='Xf', ''which specifies a frequency-dependent (''f'') position angle (''X'') calibration using the source 3C48, the position angle of which is known, having set this earlier with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
xtab = "TDRW0001_calibrated.Xf"<br />
polcal(vis='TDRW0001_calibrated.ms',<br />
caltable=xtab,<br />
spw='0~7',<br />
field='0137+331=3C48',<br />
solint='inf,2MHz',<br />
combine='scan',<br />
poltype='Xf',<br />
refant = 'ea10',<br />
gaintable=[kcross_mbd,dtab_J0259],<br />
gainfield=['',''],<br />
spwmap=[[0,0,0,0,0,0,0,0],[]],<br />
append=False)<br />
</source><br />
<br />
[[Image:Plotms-3C48-Xf-CASA6.4.1.png|thumb|Figure 9: Xf solutions versus frequency.]]<br />
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 refant when performing polarization calibration.<br />
<br />
It is strongly suggested you check that the calibration worked properly by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 9):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=xtab,xaxis='frequency',yaxis='phase',coloraxis='spw')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis = 'TDRW0001_calibrated.ms',<br />
field='',<br />
gainfield=['', '', ''], <br />
flagbackup=True,<br />
interp=['', '', ''],<br />
gaintable=[kcross_mbd,dtab_J0259,xtab],<br />
spw='0~7', <br />
calwt=[False, False, False], <br />
applymode='calflagstrict', <br />
antenna='*&*', <br />
spwmap=[[0,0,0,0,0,0,0,0],[],[]], <br />
parang=True)<br />
<br />
</source><br />
<br />
* ''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; here derived from J0259+0747), and the R-L phase corrections (xtab).<br />
* ''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; 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''.<br />
* ''parang '': If polarization calibration has been performed, set parameter ''parang=True''.<br />
<br />
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 10A-10F):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='0',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-3C48-fld0-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='1',correlation='RR,LL',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',<br />
plotfile='Plotms-J2355-fld1-corrected-phase-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='amp',ydatacolumn='corrected',<br />
coloraxis='corr',<br />
plotfile='Plotms-J0259-fld2-corrected-amp-CASA6.4.1.jpeg')<br />
<br />
plotms(vis='TDRW0001_calibrated.ms',field='2',correlation='',<br />
timerange='',antenna='',avgtime='60',<br />
xaxis='frequency',yaxis='phase',ydatacolumn='corrected',<br />
plotrange=[-1,-1,-180,180],coloraxis='corr',avgbaseline=True,<br />
plotfile='Plotms-J0259-fld2-corrected-phase-CASA6.4.1.jpeg')<br />
</source><br />
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. <br />
<br />
{|<br />
| [[Image:Plotms-3C48-fld0-corrected-amp-CASA6.4.1.png|thumb|Figure 10A: amplitude vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-3C48-fld0-corrected-phase-CASA6.4.1.png|thumb|Figure 10B: phase vs channel for 3C48 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-amp-CASA6.4.1.png|thumb|Figure 10C: amplitude vs channel for J2355+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J2355-fld1-corrected-phase-CASA6.4.1.png|thumb|Figure 10D: phase vs channel for J2355+4950 RR,LL]]<br />
|}<br />
<br />
{|<br />
| [[Image:Plotms-J0259-fld2-corrected-amp-CASA6.4.1.png|thumb|Figure 10E: amplitude vs channel for J0259+4950 RR,RL,LR,LL]]<br />
| [[Image:Plotms-J0259-fld2-corrected-phase-CASA6.4.1.png|thumb|Figure 10F: phase vs channel for J0259+4950 RR,RL,LR,LL with baseline averaging]]<br />
|}<br />
<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
<br />
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. <br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='TDRW0001_calibrated.ms',outputvis='3C75.ms',<br />
datacolumn='corrected',field='3')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science target.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to place the target field into a measurement set for imaging and joint deconvolution.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms',datacolumn='data',minsamp=8)<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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. In general, 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>). 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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html section of the CASA documentation.]<br />
<br />
[[Image:plotms_3c75-uvwave-CASA6.4.1.png|thumb|Figure 11: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C75 at 3000 MHz]]<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] which both Fourier transforms the data and deconvolves the resulting image. We will use a multi-scale cleaning algorithm because our target source, a complex radio galaxy, contains both diffuse, extended structures on large spatial scales as well as point-like components. This approach will do a better job of modeling the image than the classic clean delta function. For broader examples of many [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Multi-scale Clean ==<br />
<br />
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. Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvwave.jpeg',avgspw=False,overwrite=True)<br />
</source><br />
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 will also see some outliers there which are primarily from residual amplitude errors of ea05, that 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>\theta\approx\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. <br />
<br />
The 3C75 binary black hole system is known to have a maximum extent of at least 8-9 arcminutes, corresponding to about 147 pixels for the chosen cell size. Therefore, we need to choose an image size that covers most of the extent of the source. To aid deconvolution, especially when bright sources far from phase center are present, we should at the minimum image the size of 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<br />
In this tutorial, we will run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
[[Image:3C75-tclean-interactive-start-CASA6.2.1.png|thumb|Figure 12: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
* ''vis='3C75.ms' '': this split MS contains the target field only.<br />
* ''imagename='3C75_initial' '': our output image cubes will all start with this name root, e.g., 3C75_initial.image<br />
* ''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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] task define an appropriate threshold. The number of iterations should then be set high enough to reach the threshold found by tclean.<br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer] window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=480,cell='3.4arcsec' '': See the discussion above regarding setting the image size and cell size. If only one value is specified for the parameter, the same value is used in both directions (declination and right ascension).<br />
* ''stokes='IQUV' '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will output an image cube containing all: total intensity I, and Stokes Q, U, and V.<br />
* ''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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3C75-tclean-interactive-300iters-CASA6.2.1.png|thumb|Figure 13: After the first approximately 300 iterations of multi-scale mfs clean]]<br />
<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, an [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.imview.html imview] 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. Similarly, select "All channels". 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 radio galaxy jets. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will do before returning to the GUI (''cycleniter''). 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 ''cycleniter'' value that you might had set before starting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3C75-tclean-interactive-residuals-CASA6.2.1.png|thumb|Figure 14: Interactive residuals after about 13000 iterations of multi-scale mfs clean]]<br />
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 cleaned mask region). As mentioned before, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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)<br />
* ''.pb.tt0'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.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)<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
* ''.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)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane, one for each Taylor Term (.tt0, .tt1, .tt2)<br />
<br />
{|<br />
|[[Image:3c75-CARTA-multiscale-initialI-CASA6.4.1.png|thumb|Figure 15A: Viewer panel of final restored Stokes I image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialQ-CASA6.4.1.png|thumb|Figure 15B: Viewer panel of final restored Stokes Q image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialU-CASA6.4.1.png|thumb|Figure 15C: Viewer panel of final restored Stokes U image (using viridis colormap, linear scale, 99.9%)]]<br />
|[[Image:3c75-CARTA-multiscale-initialV-CASA6.4.1.png|thumb|Figure 15D: Viewer panel of final restored Stokes V image (using viridis colormap, linear scale, 99.9%)]]<br />
|}<br />
<br />
After the imaging and deconvolution process has finished, you can use [https://cartavis.org/ CARTA] to look at your image.<br />
<br />
Take some time to play with the color scale to better emphasize the faint emission and to see the underlying noise patterns. For the figures above we selected the viridis color map, the linear scale function, and the 99.9% data range on the histogram. You can also use the Animators slider/buttons to switch between the four different Stokes parameter images that were computed. If you are unfamiliar with [https://cartavis.org/ CARTA] then take some time to look over its extensive built in documentation and help features. You can find its searchable online manual via the "Help" button at the top or to get more information on a particular widget you can click the corresponding "?" button near it. If you click the Animator tab you'll also notice that [https://cartavis.org/ CARTA] attempts to create total polarization, linear polarization, fractional total polarization, fractional linear polarization, and linear polarization angle images for you. This can be quite convenient, but we'll show how to create these yourself later in this guide.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 response fall-off in the edges. In principle, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] produces primary beam response image, and if we had set parameter ''pbcor=True'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] would had saved a primary beam corrected restored image of our target. Since we used ''deconvolver='mtmfs' '' and ''nterms=2'', the calculation of the primary beam response requires special treatment. To perform wideband primary beam correction, we will use task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. In the future this task will be incorporated into [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but until then this separate task needs to be used.<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms',imagename='3C75_initial',nterms=2, action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
The task will produce primary beam corrected images of our target (3C75_initial.pbcor.image.tt0, 3C75_initial.pbcor.image.tt1, 3C75_initial.pbcor.image.alpha, 3C75_initial.pbcor.image.alpha.error). You can open image 3C75_initial.pbcor.image.tt0 in [https://cartavis.org/ CARTA], and compare it to screenshots in Figure 15. You will see noise (and signal) at the edges of the image has indeed increased.<br />
<br />
== Self-Calibration ==<br />
<br />
Before we get started with self-calibration, it might be good to check whether we need to perform 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. The division will help us to see low level interfrence we might not otherwise notice by just looking at the data column. 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c75-uvdist_resid_RR.png',avgspw=False,overwrite=True)<br />
<br />
# If you made a mistake above and didn't clean the polarization as well, then this plot will be empty.<br />
plotms(vis='3C75.ms',xaxis='uvdist',yaxis='amp',plotrange=[0,0,0,20],<br />
ydatacolumn='data/model_vector', field='3C75',avgtime='30',correlation='RL',<br />
plotfile='plotms_3c75-uvdist_resid_RL.png',avgspw=False,overwrite=True)<br />
</source><br />
<br />
{|<br />
| [[Image:plotms-3c75-uvdist-residRR-CASA6.4.1-corr.png|thumb|Figure 16A: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RR correlations.]]<br />
| [[Image:plotms-3c75-uvdist-residRL-CASA6.4.1-corr.png|thumb|Figure 16B: plotms plot showing Amplitude vs UV Distance residuals in wavelengths for 3C75 for RL correlations.]]<br />
|}<br />
<br />
Since we are seeing a significant amount of weak residual interference, we will take a few steps to reduce these. <br />
<source lang="python"><br />
# In CASA<br />
<br />
# tfcrop<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RR,ABS_LL',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='tfcrop',correlation='ABS_RL,ABS_LR',freqfit='line',extendflags=False,flagbackup=False,datacolumn='residual_data',flagdimension='freq',ntime='scan')<br />
# rflag<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RR,LL',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
flagdata(vis='3C75.ms',mode='rflag',correlation='RL,LR',extendflags=False,flagbackup=False,datacolumn='residual_data',ntime='scan')<br />
# extend flags<br />
flagdata(vis='3C75.ms',mode='extend',flagbackup=False)<br />
</source><br />
<br />
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 our dataset. <br />
<br />
'''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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as: <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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) \over 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 some discussion in the old CASA Reference Manual on [http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#section%3Aim.selfcal self calibration] (see Section 5.11), but more detailed discussion can be found in lectures on [https://science.nrao.edu/facilities/alma/naasc-workshops/nrao-cd-stsci/cde_selfcal.pdf Self-calibration] given at NRAO community days. <br />
<br />
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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
** 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column to form a new CORRECTED_DATA column ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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 create a new Stokes I image, which we will use to generate a series of gain corrections (phase only self-calibration) that will be stored in 3C75.ScG0. With this solution, we then perform bandpass self-calibration to remove any amplitude slope that might be present. Next, we apply the derived phase and amplitude corrections to the data to form a set of self-calibrated data, and then re-image the dataset (3C75_selfcal.image). For the purpose of self-calibration, note that in the clean before the self-calibration, it is important that we only use the Stokes I model so that any cleaned polarization does not affect the gaincal. We first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.delmod.html?highlight=delmod# delmod] on the MS to get rid of the previous polarized model, and run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to generate Stokes I-only image. In principle, it is possible to use the previous image cube and extract the Stokes I model using the CASA toolkit and have [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] fill the model column appropriately. For simplicity, we just re-image with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] selecting only Stokes I.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3C75.ms')<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="data",<br />
imagename="3C75_initial_I",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
As discussed, this [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] call will 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's total flux density as possible, but not include low level questionable features or sub-structures (ripples) that might be due to calibration or deconvolution artifacts. We modified the two parameters controlling [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]'s minor and major cycles to the following values ''cycleniter=750'' and ''niter=3500'' to reflect this, but you may find that you don't even need 3500 iterations for this first [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] pass.<br />
<br />
If you are happy with the new image, perform the following self-calibration steps:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3C75.ms', caltable='3C75.ScG0', field='', solint='inf', refant='ea10', <br />
spw='',minsnr=3.0, gaintype='G', parang=False, calmode='p')<br />
<br />
bandpass(vis='3C75.ms', caltable='3C75.ScB0', field='', solint='inf', refant='ea10', minsnr=3.0, spw='',<br />
parang = False, gaintable=['3C75.ScG0'], interp=[])<br />
<br />
applycal(vis='3C75.ms', gaintable=['3C75.ScG0','3C75.ScB0'], spw='', applymode='calflagstrict', parang=False)<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities which will be used by next execution of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] which may or may not be a good thing. You can control the action of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] by changing the value of parameter ''applymode''. Setting ''applymode='calflagstrict' ''will be more stringent about flagging data points without valid calibration, while ''applymode='calonly' '' will calibrate those with solutions while passing unchanged the data without solutions. You can see ahead of time what applycal will do by executing it with ''applymode='trial' ''which will do the reporting but nothing else. In our example we used '' applymode='calflagstrict' '', but you will notice that the reported flagged fraction has not changed much, only increasing by 0.6%. This is a good thing.<br />
<br />
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 produce a better image. We do this by invoking the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command once again. <br />
<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_selfcal_1",<br />
imsize=480,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="I",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=0.0001,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=3500,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=750,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
Commonly this self-calibration procedure is applied multiple times. In Figures 17A & B you can see a comparison of the shallow Stokes I image before self-calibration and after two self-calibration steps. The first self-calibration round was done as instructed in this section, while the second round was executed with ''solint='120s' '' and new solution tables were created (3C75.ScG1, 3C75.ScB1).<br />
{|<br />
| [[Image:3c75-initial_I-CASA6.4.1.png|thumb|Figure 17A: Shallow Stokes I image before self-calibration.]]<br />
| [[Image:3c75-selfcal_2-CASA6.4.1.png|thumb|Figure 17B: Stokes I image after two rounds of self-calibration.]]<br />
|} <br />
<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to remove an image, or even a set of gain corrections, change something and try again. Having said that, here are several guidelines to consider:<br />
<br />
* 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'' 'selfcal_1' ''is attached to various files to help keep straight what is what. Successive iterations of self-cal could then be'' 'selfcal_2' '','' 'selfcal_3' '', etc.<br />
<br />
* Care is required in setting ''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.<br />
<br />
* A common metric for self-calibration is whether the ''dynamic range'' (= peak flux density/rms) of the image has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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 features 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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''. One may 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager].<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] 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.)<br />
<br />
== Final Polarization Images ==<br />
<br />
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 artifacts 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, and make the image larger to incorporate the bright source into our model in this tclean execution.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3C75.ms', minsamp=8, datacolumn='corrected', flagbackup=True)<br />
<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_final_large",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="mfs",<br />
reffreq="3.0GHz",<br />
nchan=-1,<br />
start="",<br />
width="",<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
normtype="flatnoise",<br />
deconvolver="mtmfs",<br />
scales=[0, 6, 18],<br />
nterms=2,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="modelcolumn",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=True)<br />
</source><br />
<br />
The final restored Stokes I,Q,U, and V images are shown in Figures 18A&ndash;D. We've set the color scale to match between the images. Note that there is still a star like pattern in the residuals which are artifacts 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. 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 increases the further away one gets from the beam center. Additionally, the two polarization beams do not sit on top 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. <br />
<br />
{|<br />
| [[Image:3C75-final-I-CASA6.4.1.png|thumb|Figure 18A: Viewer panel of final restored Stokes I image.]]<br />
| [[Image:3C75-final-Q-CASA6.4.1.png|thumb|Figure 18B: Viewer panel of final restored Stokes Q image.]]<br />
| [[Image:3C75-final-U-CASA6.4.1.png|thumb|Figure 18C: Viewer panel of final restored Stokes U image.]]<br />
| [[Image:3C75-final-V-CASA6.4.1.png|thumb|Figure 18D: Viewer panel of final restored Stokes V image.]]<br />
|}<br />
<br />
Note, that these images are not yet primary beam corrected and are displayed on log scaling. You should play with the color scaling as well as the bias/contrast widget in [https://cartavis.org/ CARTA] to better see the faint emission.<br />
<br />
=== Spectral & Polarization Maps ===<br />
<br />
Note: If you are using [https://cartavis.org/ CARTA] then several of the next steps are actually unnecessary. If supplied a proper IQUV image [https://cartavis.org/ CARTA] will compute polarization intensity, linear polarization, fractional polarization intensity, fractional linear polarization intensity, and polarization angle maps for you. We show the steps one would have to take to manually create some of the images below for completeness. When possible the Figures shown will be using values/images that are generated soley by [https://cartavis.org/ CARTA] itself. You are encouraged though to still manually create your own set of images and then overlay them with the [https://cartavis.org/ CARTA] generated images to see that they match.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.widebandpbcor.html widebandpbcor]. As demonstrated earlier, the task can also correct the images for the telescope's primary beam response; this correction will make the images science ready. Parameter ''action='pbcor' '' will perform both actions (correct for the primary beam and calculate spectral index map) while parameter ''threshold'' sets minimum flux density above which the spectral index is calculated (this will allow us to mask all the noise regions).<br />
<br />
<source lang="python"><br />
# In CASA<br />
widebandpbcor(vis='3C75.ms', imagename='3C75_final_large', nterms=2, threshold='1.0mJy/beam', action='pbcor',<br />
spwlist=[0,1,2,3,4,5,6,7], chanlist=[32,32,32,32,32,32,32,32], weightlist=[1,1,1,1,1,1,1,1])<br />
</source><br />
<br />
<br />
For further study of polarization properties, you might want to convert the Stokes images into something more useful for scientific analysis. We will use CASA to calculate polarization intensity, <math>\sqrt{Q^2 + U^2 + V^2}</math>, and polarization angle, <math>{atan2 (U,Q) \over 2}</math>, maps from the final Stokes I,Q,U,V images. You can then look at those with [https://cartavis.org/ CARTA]. For example, Figure 19B shows the polarization intensity image. Since we've yet to apply any mask, the polarization angle image made in the next step will also contain values from low signal-to-noise data.<br />
<br />
<source lang="python"><br />
# In CASA<br />
<br />
# Obtain image for the polarization intensity<br />
immath(outfile='3C75_final.poli',mode='poli',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
# Obtain image for the polarization angle<br />
immath(outfile='3C75_final.pola',mode='pola',imagename=['3C75_final_large.image.tt0'],sigma='0.0Jy/beam')<br />
</source><br />
<br />
{|<br />
| [[Image:3C75-final-spindx-CASA6.4.1.png|thumb|Figure 19A: CASA Computed spectral index map.]]<br />
| [[Image:3C75-final-Ptot-casa6.4.1.png|thumb|Figure 19B: CARTA Computed polarization intensity image.]]<br />
| [[Image:3C75-final-PAng-CASA6.4.1.png|thumb|Figure 19C: CARTA Computed polarized angles (vectors) superposed on the Stokes I raster image plane. We've selected an intensity threshold within CARTA to exclude low S/N points.]]<br />
|}<br />
<br />
Note that for calculations of the polarization intensity and angle images you may &mdash; but do not need to &mdash; use primary beam corrected images; your results will be the same. This is because the primary beam correction cancels out in the equations for these two polarization quantities. If you want to visualize the polarization vectors on top of the Stokes I image, we need to add a mask for the low noise values. <br />
<br />
<source lang="python"><br />
# In CASA<br />
!cp -r '3C75_final.poli' polimg<br />
<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.Q.image',stokes='Q')<br />
imsubimage(imagename='3C75_final_large.image.tt0',outfile='3C75_final.U.image',stokes='U')<br />
<br />
subimPI='polimg'<br />
ia.open(subimPI)<br />
ia.calcmask(mask=subimPI+'>5e-4',name='mymask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.Q.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
ia.open('3C75_final.U.image')<br />
ia.maskhandler('copy',['polimg:mymask','polithreshmask'])<br />
ia.maskhandler('set','polithreshmask')<br />
ia.done()<br />
<br />
immath(imagename=['3C75_final.Q.image', '3C75_final.U.image'], mode='pola', outfile='3C75_final.pola.masked')<br />
</source><br />
These steps take the polarized intensity image calculated above (Figure 19B) and create a mask using a polarization intensity threshold of 5e-4 Jy/beam. 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 created from the polarization intensity image. Finally, we can load the Stokes I as raster image into [https://cartavis.org/ CARTA] and add the polarization angle as vectors. You can do this by matching the final IQUV image, 3C75_final_large.image.tt0, and the newly created polarization angle image in WCS space by clicking the "XY" under the "Matching" column of the Image List widget. Then open the Vector Overlay Configuration widget to create the vectors. You can compare the vectors calculated with immath to the ones that [https://cartavis.org/ CARTA] generates for you. You may notice that there are some vectors that appear to disagree with each other. If so, it is likely caused by the pixel averaging being done within [https://cartavis.org/ CARTA], which you can toggle off to confirm. 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.<br />
<br />
=== Rotation Measures ===<br />
<br />
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. <br />
<br />
To produce an image cube with 8 channels, each image is using 128 MHz of bandwidth, we call [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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.<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3C75.ms',<br />
field="3C75",<br />
spw="",timerange="",<br />
uvrange="",antenna="",scan="",observation="",intent="",<br />
datacolumn="corrected",<br />
imagename="3C75_chan8",<br />
imsize=800,<br />
cell="3.4arcsec",<br />
phasecenter="",<br />
stokes="IQUV",<br />
projection="SIN",<br />
specmode="cube",<br />
reffreq="",<br />
nchan=-1,<br />
start="",<br />
width=64,<br />
outframe="LSRK",<br />
veltype="radio",<br />
restfreq=[],<br />
interpolation="linear",<br />
gridder="standard",<br />
mosweight=True,<br />
cfcache="",<br />
computepastep=360.0,<br />
rotatepastep=360.0,<br />
pblimit=-0.0001,<br />
pbmask=0.0,<br />
mask='3C75_final_large.mask',<br />
normtype="flatnoise",<br />
deconvolver="multiscale",<br />
scales=[0, 6, 18],<br />
nterms=1,<br />
smallscalebias=0.6,<br />
restoration=True,<br />
restoringbeam=[],<br />
pbcor=False,<br />
outlierfile="",<br />
weighting="briggs",<br />
robust=0.5,<br />
npixels=0,<br />
uvtaper=[],<br />
niter=20000,<br />
gain=0.1,<br />
threshold=0.0,<br />
nsigma=0.0,<br />
cycleniter=1000,<br />
cyclefactor=1.0,<br />
restart=True,<br />
savemodel="none",<br />
calcres=True,<br />
calcpsf=True,<br />
parallel=False,<br />
interactive=False)<br />
</source><br />
<br />
Now we use the CASA toolkit to access data for four pixels in the image cube to visualize and fit the rotation measure. <br />
<source lang="python"><br />
# In CASA<br />
import matplotlib<br />
# to display<br />
matplotlib.use('TkAgg')<br />
import matplotlib.pyplot as plt<br />
import numpy as np<br />
<br />
ia.open('3C75_chan8.image')<br />
<br />
# number of channels/frequencies<br />
nunr = 8 <br />
<br />
tt = ia.getchunk()<br />
nu = np.linspace(2.551e9,3.319e9,num=nunr)<br />
c = 2.99792458e8<br />
<br />
Q1 = tt[418,444,1,:nunr]<br />
U1 = tt[418,444,2,:nunr]<br />
Q2 = tt[376,419,1,:nunr]<br />
U2 = tt[376,419,2,:nunr]<br />
Q3 = tt[383,401,1,:nunr]<br />
U3 = tt[383,401,2,:nunr]<br />
Q4 = tt[395,398,1,:nunr]<br />
U4 = tt[395,398,2,:nunr]<br />
<br />
chi1 = 0.5*np.arctan2(U1,Q1)<br />
chi2 = 0.5*np.arctan2(U2,Q2)<br />
chi3 = 0.5*np.arctan2(U3,Q3)<br />
chi4 = 0.5*np.arctan2(U4,Q4)<br />
<br />
#locate the values that are nan and delete these indices from nu<br />
indx1=np.argwhere(chi1==0)<br />
indx2=np.argwhere(chi2==0)<br />
indx3=np.argwhere(chi3==0)<br />
indx4=np.argwhere(chi4==0)<br />
<br />
nu1=np.delete(nu,indx1)<br />
lam1 = c/nu1<br />
lamsq1 = lam1*lam1<br />
<br />
nu2=np.delete(nu,indx2)<br />
lam2 = c/nu2<br />
lamsq2 = lam2*lam2<br />
<br />
nu3=np.delete(nu,indx3)<br />
lam3 = c/nu3<br />
lamsq3 = lam3*lam3<br />
<br />
nu4=np.delete(nu,indx4)<br />
lam4 = c/nu4<br />
lamsq4 = lam4*lam4<br />
<br />
#drop the zero values<br />
chi1=np.delete(chi1,indx1)<br />
chi2=np.delete(chi2,indx2)<br />
chi3=np.delete(chi3,indx3)<br />
chi4=np.delete(chi4,indx4)<br />
<br />
fit1 = np.polyfit(lamsq1,chi1,1)<br />
fit_fn1 = np.poly1d(fit1)<br />
slope1 = fit1[0]<br />
intercept1 = fit1[1]<br />
fit2 = np.polyfit(lamsq2,chi2,1)<br />
fit_fn2 = np.poly1d(fit2)<br />
slope2 = fit2[0]<br />
intercept2 = fit2[1]<br />
fit3 = np.polyfit(lamsq3,chi3,1)<br />
fit_fn3 = np.poly1d(fit3)<br />
slope3 = fit3[0]<br />
intercept3 = fit3[1]<br />
fit4 = np.polyfit(lamsq4,chi4,1)<br />
fit_fn4 = np.poly1d(fit4)<br />
slope4 = fit4[0]<br />
intercept4 = fit4[1]<br />
<br />
plt.figure(1)<br />
plt.title('Overall Title')<br />
plt.subplot(221)<br />
plt.title('Point 1: (418,444)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi1$')<br />
plt.scatter(lamsq1,chi1,color='r')<br />
plt.plot(lamsq1,fit_fn1(lamsq1),'r--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope1,intercept1))<br />
plt.legend(loc=2)<br />
<br />
plt.subplot(222)<br />
plt.title('Point 2: (376,419)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi2$')<br />
plt.scatter(lamsq2,chi2,color='b')<br />
plt.plot(lamsq2,fit_fn2(lamsq2),'b--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope2,intercept2))<br />
plt.legend(loc=1)<br />
<br />
plt.subplot(223)<br />
plt.title('Point 3: (383,401)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi3$')<br />
plt.scatter(lamsq3,chi3,color='g')<br />
plt.plot(lamsq3,fit_fn3(lamsq3),'g--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope3,intercept3))<br />
plt.legend(loc=3)<br />
<br />
plt.subplot(224)<br />
plt.title('Point 4: (395,398)')<br />
plt.xlabel(r'$\lambda^{2}$')<br />
plt.ylabel(r'$\chi4$')<br />
plt.scatter(lamsq4,chi4,color='m')<br />
plt.plot(lamsq4,fit_fn4(lamsq4),'m--',label='$\chi$ = {:.2f}$\lambda^2$ + {:.2f}'.format(slope4,intercept4))<br />
plt.legend(loc=1)<br />
plt.tight_layout()<br />
<br />
plt.show()<br />
#Or to save the figure<br />
plt.savefig('3C75_rmscript_8chan4px.png')<br />
<br />
ia.close()<br />
</source><br />
<br />
The resulting plots are shown in Figure 20A. Alternatively, there exists a CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] which does this basic fitting for you while taking into account the <math>N \pi</math> ambiguity (refer to [http://adsabs.harvard.edu/full/1986A%26A...156..234L] for more info). The fits using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for our case of 3C 75 by making images per spectral window is shown in Figure 20B. Here we set the maximum acceptable position angle error to 20 degrees. If larger, then no rotation measures are calculated.<br />
<br />
<source lang='python'><br />
# In CASA<br />
rmfit('3C75_chan8.image',rm='3C75_chan8_rm.image',rmerr='3C75_chan8_rm.image.err',maxpaerr=0.35)<br />
</source> <br />
<br />
{|<br />
| [[Image:3C75-rmscript-8chan4px-CASA6.4.1.png|thumb|Figure 20A: Rotation measures extracted for 4 pixels from an 8 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmfit-8chan-CARTA-CASA6.4.1.png|thumb|Figure 20B: RMFIT rotation measure image generated from 8 channel image cube.]]<br />
|}<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] task has many more options; for example, you are able to provide a foreground rotation measure to subtract. <br />
<br />
Now we can compare the rotation measures extracted for the 4 pixels from the 8 channel image cube with the values derived in the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] for the same pixels. In most cases the values are more or less comparable.<br />
<br />
{| class="wikitable"<br />
|-<br />
! Point<br />
! RM Lin. Fit.<br />
! RM RMFIT<br />
|-<br />
| 1<br />
| -65.46<br />
| -57.29<br />
|-<br />
| 2<br />
| 10.41<br />
| 66.62<br />
|-<br />
| 3<br />
| -71.71<br />
| -65.14<br />
|-<br />
| 4<br />
| -7.30<br />
| -5.07<br />
|}<br />
<br />
As our source is rather bright, we can derive an IQUV image not just per averaged spectral window as we just did, but rather per channel. To achieve this you can change the above [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] parameter width from 64 to 1, which will result in 512 channels spanning all 8 spectral windows. Note when imaging each channel, the edge channels are flagged which results in the PSF being blank for channels sourrounding each spectral window and some of the images being blank. Don't forget to change the imagename parameter when re-running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. Due to the increased size of the cube you may find that your machine's avaliable memory struggles to keep up with the new [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] command. If so, then you can reduce the image size to lower the required memory. For our 512 channel cube we reduced the image size from 800x800 to 270x270. If you do reduce the image size as we have then you'll need to make use of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.imsubimage.html?highlight=imsubimage imsubimage] to first reduce your old image's mask size so it can be used again for your smaller image. Following the same steps as for the 8 channel image cube (adjusting for the new number of channels and new pixel indices for our points of interest), you would then obtain the results shown in Figure 21 where again the polarization position angle as a function of lambda square is shown together with the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.rmfit.html rmfit] image. We can clearly see that the source exhibits complex structure beyond a simple linear fit 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.<br />
<br />
<br />
{|<br />
| [[Image:3C75-rmscript-512chan4px-CASA6.4.1.png|thumb|Figure 21A: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75.]]<br />
| [[Image:3C75-rmscript-512chan4px-ylim-CASA6.4.1.png|thumb|Figure 21B: Rotation measures extracted for 4 pixels from an 512 channel image cube of 3C75 with enforced limits on y axis for points 1 and 2 to exclude outlier points from the view and see better the variation of the data.]]<br />
| [[Image:3C75-rmfit-512chan-CARTA-CASA6.4.1.png|thumb|Figure 21C: RMFIT rotation measure image generated from 512 channel image cube.]]<br />
|}<br />
<br />
<!-- == Image Analysis ==<br />
<br />
The three most basic analyses are to determine peak brightness, flux density, and 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.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3C75_initial.image.tt0')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '02:58:37.309, +05.47.28.628, I, 3e+09Hz',<br />
'max': array([ 0.14971776]),<br />
'maxpos': array([257, 279, 0, 0], dtype=int32),<br />
'maxposf': '02:57:38.755, +06.03.17.399, I, 3e+09Hz',<br />
'mean': array([ 0.00016331]),<br />
'medabsdevmed': array([ 1.74164962e-05]),<br />
'median': array([ 8.04986788e-09]),<br />
'min': array([-0.01785131]),<br />
'minpos': array([258, 278, 1, 0], dtype=int32),<br />
'minposf': '02:57:38.527, +06.03.13.999, Q, 3e+09Hz',<br />
'npts': array([ 921600.]),<br />
'q1': array([ -1.69758441e-05]),<br />
'q3': array([ 1.78917744e-05]),<br />
'quartile': array([ 3.48676185e-05]),<br />
'rms': array([ 0.0031646]),<br />
'sigma': array([ 0.00316039]),<br />
'sum': array([ 150.50313612]),<br />
'sumsq': array([ 9.22954767]),<br />
'trc': array([479, 479, 3, 0], dtype=int32),<br />
'trcf': '02:56:48.133, +06.14.37.233, V, 3e+09Hz'}<br />
<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.14971776306629181<br />
</pre><br />
and so the peak flux density is 0.150 Jy/beam.<br />
<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html?highlight=imstat# 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.<br />
<br />
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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3C75_final.image.tt0' &<br />
</source><br />
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. <br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
2659 1.243414e+02 4.676248e-02 5.722227e-02 <br />
Std dev Minimum Maximum region count <br />
3.298586e-02 -1.063592e-03 1.484267e-01 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
</pre><br />
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.<br />
<br />
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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- <br />
(3C75_final.image.tt0) <br />
Stokes Velocity Frame Doppler Frequency <br />
I -104.873km/s LSRK RADIO 3e+09 <br />
BrightnessUnit Npts Sum Mean Rms <br />
1216 -3.509342e-02 -2.885972e-05 6.186932e-05 <br />
Std dev Minimum Maximum region count <br />
5.474847e-05 -1.558577e-04 1.394379e-04 1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
<br />
</pre><br />
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.<br />
<br />
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. <br />
<br />
<!-- Similar analysis can be performed on the polarization and spectral index maps, this will be left to the user. --><br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
<br />
<!-- Edited for content & context by T. Perreault 2021-12-30 --><br />
<!-- Last edit by Anna D. Kapinska 2021-12-17 --><br />
<!-- Edited by Frank Schinzel 2021-03-30 --></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=VLA_Continuum_Intro_Tutorial&diff=35148VLA Continuum Intro Tutorial2023-05-22T19:13:18Z<p>Akapinsk: Created page with "Category:EVLACategory:CalibrationCategory:VLA <b>This CASA Guide is for Version 6.4.1 of CASA.</b> If you are using a later version of CASA and this is the most r..."</p>
<hr />
<div>[[Category:EVLA]][[Category:Calibration]][[Category:VLA]]<br />
<br />
<b>This CASA Guide is for Version 6.4.1 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.<br />
<br />
== Overview ==<br />
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 <br />
[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.<br />
<br />
The observations were taken with a full-polarization correlator setup and include a polarization calibrator. For the purposes of this tutorial, we will focus on the continuum (Stokes I) calibration and imaging. (See the CASA guide on radio galaxy 3C75 for an introduction to polarization calibration.)<br />
<br />
== How to Use This CASA Guide ==<br />
<br />
There 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 use CASA:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* 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).<br />
<br />
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.<br />
<br />
== Obtaining the Data ==<br />
<br />
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:<br />
[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).<br />
<br />
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<br />
<br />
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. <br />
<br />
* The initial Science Data Model (SDM) file was converted into a measurement set.<br />
* 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.<br />
* 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.<br />
* 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.<br />
<br />
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.<br />
<br />
Once the download is complete, unzip and unpack the file (within a working directory, where you will later run CASA):<br />
<br />
<pre style="background-color: lightgrey;”><br />
# In a terminal, inside your working directory:<br />
tar xzvf 3c391_ctm_mosaic_10s_spw0.ms.tgz<br />
</pre><br />
<br />
== The Observation ==<br />
<br />
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:<br />
<br />
<pre style="background-color: #E0FFFF;"><br />
Information from observing log:<br />
There is no C-band receivers on ea13<br />
Antenna ea06 is out of the array<br />
Antenna ea15 has some corrupted data<br />
Antennas ea10, ea12, ea22 do not have good baseline positions<br />
Gusty winds, mixed clouds, API rms up to 11.5.<br />
</pre><br />
<br />
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. Note, this guide is meant to be completed using the monolithic CASA and not modular CASA as the GUI may not work correctly otherwise.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] can be used to get a listing of the individual scans (set amounts of time devoted to specific targets) comprising the observation, the frequency setup, source list, and antenna locations. 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.<br />
* 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; will also serve as the (spectral) bandpass calibrator;<br />
* J1822-0938, which will serve as a calibrator for the visibility phases;<br />
* J0319+4130 = 3C 84, which was used as a polarization calibrator; and<br />
* 3C391 C1--C7, which are 7 fields centered on and surrounding the supernova remnant.<br />
This observation was set up as a 7-pointing mosaic because the supernova remnant is so large that it essentially fills the primary beam.<br />
<br />
To run [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs]:<br />
<br />
<source lang="python"><br />
# In CASA<br />
obs_dict = listobs(vis='3c391_ctm_mosaic_10s_spw0.ms')<br />
</source><br />
<br />
A Python dictionary containing some of the observation's fundamental information is created in the variable ''obs_dict'' and the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output will show up in the CASA logger window:<br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: listobs #####<br />
listobs(vis="3c391_ctm_mosaic_10s_spw0.ms",selectdata=True,spw="",field="",antenna="",<br />
uvrange="",timerange="",correlation="",scan="",intent="",<br />
feed="",array="",observation="",verbose=True,listfile="",<br />
listunfl=False,cachesize=50,overwrite=False)<br />
================================================================================<br />
MeasurementSet Name: 3c391_ctm_mosaic_10s_spw0.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. James Miller-Jones Project: T.B.D. <br />
Observation: EVLA<br />
Data records: 845379 Total integration time = 28681.5 seconds<br />
Observed from 24-Apr-2010/08:02:10.0 to 24-Apr-2010/16:00:11.5 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
24-Apr-2010/08:02:10.0 - 08:02:30.0 1 0 J1331+3030 650 [0] [10] <br />
08:02:20.0 - 08:09:30.0 2 0 J1331+3030 13975 [0] [10] <br />
08:09:20.0 - 08:16:28.0 3 0 J1331+3030 13975 [0] [10] <br />
08:19:38.0 - 08:24:26.5 4 1 J1822-0938 7035 [0] [10] <br />
08:24:48.0 - 08:29:48.0 5 2 3C391 C1 7590 [0] [10] <br />
08:29:38.0 - 08:34:48.0 6 3 3C391 C2 7821 [0] [10] <br />
08:34:38.0 - 08:39:48.0 7 4 3C391 C3 7821 [0] [10] <br />
08:39:38.0 - 08:44:48.0 8 5 3C391 C4 7821 [0] [10] <br />
08:44:38.0 - 08:49:48.0 9 6 3C391 C5 7843 [0] [10] <br />
08:49:38.0 - 08:54:48.0 10 7 3C391 C6 7843 [0] [10] <br />
08:54:38.0 - 08:59:43.5 11 8 3C391 C7 7843 [0] [10] <br />
09:00:03.0 - 09:01:31.0 12 1 J1822-0938 2925 [0] [10] <br />
09:01:52.0 - 09:06:52.0 13 2 3C391 C1 7941 [0] [10] <br />
09:06:42.0 - 09:11:52.0 14 3 3C391 C2 9801 [0] [10] <br />
09:11:42.0 - 09:16:52.0 15 4 3C391 C3 10075 [0] [10] <br />
09:16:42.0 - 09:21:52.0 16 5 3C391 C4 10050 [0] [10] <br />
09:21:42.0 - 09:26:52.0 17 6 3C391 C5 10075 [0] [10] <br />
09:26:42.0 - 09:31:52.0 18 7 3C391 C6 10075 [0] [10] <br />
09:31:42.0 - 09:36:47.5 19 8 3C391 C7 10075 [0] [10] <br />
09:37:07.0 - 09:38:35.0 20 1 J1822-0938 2900 [0] [10] <br />
09:38:57.0 - 09:43:57.0 21 2 3C391 C1 9700 [0] [10] <br />
09:43:47.0 - 09:48:57.0 22 3 3C391 C2 10050 [0] [10] <br />
09:48:47.0 - 09:53:57.0 23 4 3C391 C3 10075 [0] [10] <br />
09:53:47.0 - 09:58:57.0 24 5 3C391 C4 10075 [0] [10] <br />
09:58:47.0 - 10:03:57.0 25 6 3C391 C5 10075 [0] [10] <br />
10:03:47.0 - 10:08:57.0 26 7 3C391 C6 10075 [0] [10] <br />
10:08:47.0 - 10:13:47.0 27 8 3C391 C7 9750 [0] [10] <br />
10:14:12.0 - 10:15:39.5 28 1 J1822-0938 2925 [0] [10] <br />
10:16:01.0 - 10:21:01.0 29 2 3C391 C1 9000 [0] [10] <br />
10:20:51.0 - 10:26:01.0 30 3 3C391 C2 10050 [0] [10] <br />
10:25:51.0 - 10:31:01.0 31 4 3C391 C3 10075 [0] [10] <br />
10:30:51.0 - 10:36:01.0 32 5 3C391 C4 10075 [0] [10] <br />
10:35:51.0 - 10:41:01.0 33 6 3C391 C5 10075 [0] [10] <br />
10:40:51.0 - 10:46:01.0 34 7 3C391 C6 10075 [0] [10] <br />
10:45:51.0 - 10:50:51.0 35 8 3C391 C7 9750 [0] [10] <br />
10:51:15.0 - 10:52:42.5 36 1 J1822-0938 2925 [0] [10] <br />
10:55:14.0 - 10:57:42.0 37 0 J1331+3030 3364 [0] [10] <br />
11:00:13.0 - 11:02:41.0 38 1 J1822-0938 3883 [0] [10] <br />
11:03:03.0 - 11:08:03.0 39 2 3C391 C1 9750 [0] [10] <br />
11:07:53.0 - 11:12:53.0 40 3 3C391 C2 9725 [0] [10] <br />
11:12:43.0 - 11:17:43.0 41 4 3C391 C3 9750 [0] [10] <br />
11:17:33.0 - 11:22:33.0 42 5 3C391 C4 9750 [0] [10] <br />
11:22:23.0 - 11:27:23.0 43 6 3C391 C5 9750 [0] [10] <br />
11:27:13.0 - 11:32:13.0 44 7 3C391 C6 9750 [0] [10] <br />
11:32:03.0 - 11:36:53.0 45 8 3C391 C7 9425 [0] [10] <br />
11:37:21.0 - 11:38:47.0 46 1 J1822-0938 2700 [0] [10] <br />
11:39:11.0 - 11:44:11.0 47 2 3C391 C1 9750 [0] [10] <br />
11:44:01.0 - 11:49:01.0 48 3 3C391 C2 9700 [0] [10] <br />
11:48:51.0 - 11:53:41.0 49 4 3C391 C3 8355 [0] [10] <br />
11:53:41.0 - 11:58:31.0 50 5 3C391 C4 9425 [0] [10] <br />
11:58:21.0 - 12:03:21.0 51 6 3C391 C5 9725 [0] [10] <br />
12:03:11.0 - 12:08:11.0 52 7 3C391 C6 9701 [0] [10] <br />
12:08:01.0 - 12:12:59.0 53 8 3C391 C7 9725 [0] [10] <br />
12:13:29.0 - 12:14:48.0 54 1 J1822-0938 2600 [0] [10] <br />
12:15:18.0 - 12:20:08.0 55 2 3C391 C1 9425 [0] [10] <br />
12:19:58.0 - 12:24:58.0 56 3 3C391 C2 9750 [0] [10] <br />
12:24:48.0 - 12:29:48.0 57 4 3C391 C3 9750 [0] [10] <br />
12:29:38.0 - 12:34:38.0 58 5 3C391 C4 9725 [0] [10] <br />
12:34:28.0 - 12:39:28.0 59 6 3C391 C5 9725 [0] [10] <br />
12:39:18.0 - 12:44:18.0 60 7 3C391 C6 9750 [0] [10] <br />
12:44:08.0 - 12:49:04.5 61 8 3C391 C7 9750 [0] [10] <br />
12:49:35.0 - 12:50:53.0 62 1 J1822-0938 2600 [0] [10] <br />
12:51:24.0 - 12:56:14.0 63 2 3C391 C1 9425 [0] [10] <br />
12:56:04.0 - 13:01:04.0 64 3 3C391 C2 9000 [0] [10] <br />
13:00:54.0 - 13:05:54.0 65 4 3C391 C3 9750 [0] [10] <br />
13:05:44.0 - 13:10:44.0 66 5 3C391 C4 9750 [0] [10] <br />
13:10:34.0 - 13:15:34.0 67 6 3C391 C5 9725 [0] [10] <br />
13:15:24.0 - 13:20:24.0 68 7 3C391 C6 9750 [0] [10] <br />
13:20:14.0 - 13:25:10.0 69 8 3C391 C7 9000 [0] [10] <br />
13:25:40.0 - 13:26:57.5 70 1 J1822-0938 2600 [0] [10] <br />
13:27:28.0 - 13:32:18.0 71 2 3C391 C1 9425 [0] [10] <br />
13:32:08.0 - 13:37:08.0 72 3 3C391 C2 9750 [0] [10] <br />
13:36:58.0 - 13:41:58.0 73 4 3C391 C3 9750 [0] [10] <br />
13:41:48.0 - 13:46:48.0 74 5 3C391 C4 9750 [0] [10] <br />
13:46:38.0 - 13:51:38.0 75 6 3C391 C5 9725 [0] [10] <br />
13:51:28.0 - 13:56:28.0 76 7 3C391 C6 9750 [0] [10] <br />
13:56:18.0 - 14:01:14.0 77 8 3C391 C7 9750 [0] [10] <br />
14:01:44.0 - 14:03:01.5 78 1 J1822-0938 2024 [0] [10] <br />
14:03:33.0 - 14:08:23.0 79 2 3C391 C1 8900 [0] [10] <br />
14:08:13.0 - 14:13:13.0 80 3 3C391 C2 9750 [0] [10] <br />
14:13:03.0 - 14:18:03.0 81 4 3C391 C3 9750 [0] [10] <br />
14:17:53.0 - 14:22:53.0 82 5 3C391 C4 9350 [0] [10] <br />
14:22:43.0 - 14:27:43.0 83 6 3C391 C5 9000 [0] [10] <br />
14:27:33.0 - 14:32:33.0 84 7 3C391 C6 8595 [0] [10] <br />
14:32:23.0 - 14:37:18.5 85 8 3C391 C7 7590 [0] [10] <br />
14:37:48.0 - 14:39:05.5 86 1 J1822-0938 1848 [0] [10] <br />
14:39:36.0 - 14:44:26.0 87 2 3C391 C1 7337 [0] [10] <br />
14:44:16.0 - 14:49:16.0 88 3 3C391 C2 7568 [0] [10] <br />
14:49:06.0 - 14:54:06.0 89 4 3C391 C3 7590 [0] [10] <br />
14:53:56.0 - 14:58:56.0 90 5 3C391 C4 7527 [0] [10] <br />
14:58:46.0 - 15:03:46.0 91 6 3C391 C5 7568 [0] [10] <br />
15:03:36.0 - 15:08:36.0 92 7 3C391 C6 7590 [0] [10] <br />
15:08:26.0 - 15:13:22.0 93 8 3C391 C7 7590 [0] [10] <br />
15:13:51.0 - 15:15:09.0 94 1 J1822-0938 1680 [0] [10] <br />
15:15:40.0 - 15:20:30.0 95 2 3C391 C1 7337 [0] [10] <br />
15:20:20.0 - 15:25:20.0 96 3 3C391 C2 7568 [0] [10] <br />
15:25:10.0 - 15:30:10.0 97 4 3C391 C3 7590 [0] [10] <br />
15:30:00.0 - 15:35:00.0 98 5 3C391 C4 7564 [0] [10] <br />
15:34:50.0 - 15:39:50.0 99 6 3C391 C5 7260 [0] [10] <br />
15:39:40.0 - 15:44:40.0 100 7 3C391 C6 6930 [0] [10] <br />
15:44:30.0 - 15:49:26.0 101 8 3C391 C7 6930 [0] [10] <br />
15:49:55.0 - 15:51:13.5 102 1 J1822-0938 1088 [0] [10] <br />
15:54:52.0 - 16:00:11.5 103 9 J0319+4130 8768 [0] [10] <br />
(nRows = Total number of rows per scan) <br />
Fields: 10<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 N J1331+3030 13:31:08.287984 +30.30.32.95886 J2000 0 31964<br />
1 J J1822-0938 18:22:28.704200 -09.38.56.83501 J2000 1 39733<br />
2 NONE 3C391 C1 18:49:24.244000 -00.55.40.58001 J2000 2 105580<br />
3 NONE 3C391 C2 18:49:29.149001 -00.57.48.00001 J2000 3 110533<br />
4 NONE 3C391 C3 18:49:19.339000 -00.57.48.00001 J2000 4 110331<br />
5 NONE 3C391 C4 18:49:14.434001 -00.55.40.58001 J2000 5 110862<br />
6 NONE 3C391 C5 18:49:19.339000 -00.53.33.16000 J2000 6 110546<br />
7 NONE 3C391 C6 18:49:29.149001 -00.53.33.16000 J2000 7 109884<br />
8 NONE 3C391 C7 18:49:34.054000 -00.55.40.58001 J2000 8 107178<br />
9 Z J0319+4130 03:19:48.160102 +41.30.42.10305 J2000 9 8768<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
Sources: 10<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 J1331+3030 0 - - <br />
1 J1822-0938 0 - - <br />
2 3C391 C1 0 - - <br />
3 3C391 C2 0 - - <br />
4 3C391 C3 0 - - <br />
5 3C391 C4 0 - - <br />
6 3C391 C5 0 - - <br />
7 3C391 C6 0 - - <br />
8 3C391 C7 0 - - <br />
9 J0319+4130 0 - - <br />
Antennas: 26:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
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<br />
##### End Task: listobs #####<br />
##########################################<br />
<br />
</pre><br />
<br />
Notice in this listobs, the first scans are the fields that will be used for calibration before scanning the target fields we want to observe. 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 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.<br />
<br />
Also, note the portion listing the spectral windows (in this example only one, spw='0'):<br />
<br />
<pre style="background-color: #fffacd;"><br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) Corrs <br />
0 Subband:0 64 TOPO 4536.000 2000.000 128000.0 4599.0000 RR RL LR LL<br />
</pre><br />
<br />
In the calibration steps below we will define spw and channel range. Since this C-band instrument configuration uses Full polarization, the spw has 64 channels that are 2.0MHz wide.<br />
<br />
<br />
Both to get a sense of the array, as well as identify an antenna for later use in calibration, use the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html 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!). <br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='3c391_ctm_mosaic_10s_spw0.ms',figfile='plotants_3c391_antenna_layout.png')<br />
clearstat() # This removes the table lock generated by plotants in script mode<br />
</source><br />
<br />
<br />
[[Image:plotants_3c391_antenna_layout_CASA5.4.0.png|200px|thumb|center|Figure 1: plotants figure]]<br />
<br />
== Examining and Editing the Data ==<br />
<br />
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.<br />
<br />
In the scheduling block configuration, it is common to insert a setup scan as the first scan. From the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] output above, one may have noticed that the first scan is less than 1 minute long. This first scan can safely be flagged.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', scan='1')<br />
</source><br />
<br />
* ''flagbackup=True'' : A comment is warranted on the setting of flagbackup. If set to True, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. <br />
* ''mode='manual' '': Specific data are going to be selected to be edited. <br />
<!--* <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, --><br />
* ''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).<br />
<br />
If satisfied with the inputs, run this task. The initial display in the logger will include <br />
<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: flagdata #####<br />
.<br />
.<br />
.<br />
.<br />
Backup original flags before applying new flags<br />
Table type is Measurement Set<br />
Creating new backup flag file called flagdata_1<br />
Table type is Measurement Set<br />
Manual mode is active<br />
Initializing the agents<br />
autocorr is 0<br />
There are 1 valid agents in list<br />
Running the agentflagger tool<br />
------------------------------------------------------------------------------------ <br />
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<br />
=> Data flagged so far 100%<br />
==================================================================================== <br />
=> Percentage of data flagged in table selection: 100%<br />
=> Writing flags to the MS<br />
.<br />
.<br />
##### End Task: flagdata #####<br />
##########################################<br />
</pre><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html 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.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', flagbackup=True, mode='manual', antenna='ea13,ea15')<br />
</source><br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] above.)<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms', mode='quack', quackinterval=10.0, quackmode='beg')<br />
</source><br />
* ''mode='quack' '': Quack is another mode in which the same edit will be applied to all scans for all baselines.<br />
* ''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.<br />
* ''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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].<br />
<br />
<source lang="python"><br />
# In CASA<br />
clearstat() # This removes any existing table locks generated by flagdata<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms', selectdata=True, correlation='RR,LL', averagedata=True, avgchannel='64', coloraxis='field')<br />
</source><br />
[[Image:Colorbyfield_CASA5.4.0.jpeg|200px|right|thumb|Figure 2: Overview of the observation: amplitude vs time, color-coded by field.]]<br />
* ''selectdata=True '': One can choose to plot only selected subsets of the data.<br />
* ''correlation='RR,LL' '': Plot only the left- and right-handed polarization correlation products. The cross-terms ('RL' and 'LR') will be close to zero for non-polarized sources.<br />
* ''averagedata=True'': One can choose to average data points before plotting them.<br />
* ''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.<br />
* ''coloraxis='field' '': Color-code the plotting symbols by field name/number.<br />
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. <br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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, a polarization calibrator, shown in purple) is the brightest source in this observation. The next brightest is the first source observed (J1331+3030, a.k.a. 3C286, shown in black), 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html 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.<br />
<br />
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).<br />
<br />
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.<br />
<br />
As another example of using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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.)<br />
<br />
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.)<br />
<br />
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' polarization correlations.<br />
<br />
{|<br />
| [[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]]<br />
| [[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]]<br />
| [[File:Delays_ea01ea21_CASA5.4.0.jpeg|200px|right|thumb|Figure 3C: plotms view of phase vs. channel on one baseline, showing phase delay across the uncalibrated bandpass]]<br />
|}<br />
<br />
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.<br />
<br />
[[Image:plotms_3c391-datastream_CASA5.4.0.jpeg|200px|right|thumb|Figure 4: datastream view of MS]]<br />
One final useful plot we will make is a datastream plot of the antenna2 in a baseline for the data versus ea01, using spw 0 and channel 31. This shows, assuming that ea01 is in the entire observation, when various antennas drop out.<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='',correlation='RR,LL',<br />
timerange='',antenna='ea01',spw='0:31',<br />
xaxis='time',yaxis='antenna2',<br />
plotrange=[-1,-1,0,26],coloraxis='field')<br />
</source><br />
<br />
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 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.<br />
<br />
== Calibrating the Data ==<br />
<br />
It is now time to begin calibrating the data. The 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. <br />
For more discussion of the philosophy, strategy, and implementation of calibration of synthesis data within CASA, see [https://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_calibration.html Synthesis Calibration] in the CASA documentation.<br />
<br />
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: <br />
<br />
<math><br />
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)]} <br />
</math><br />
<br />
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: <br />
* <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.<br />
* <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.<br />
* <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. <br />
Strictly, the equation above is a simplification of a more general measurement equation formalism, but it is a useful simplification in many cases.<br />
<br />
=== ''A priori'' Antenna Position Corrections ===<br />
<br />
Given the VLA is composed of 27 individual antennas, it is necessary to know their exact positions in order to correctly correlate (match and combine) each signal. Observations are sometimes made before some antenna positions are known exactly, as they can be corrected if the positions are known later. 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.<br />
<br />
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.<br />
<br />
The calculations are inserted via [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gencal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.antpos',caltype='antpos')<br />
</source><br />
<br />
In the logger you can see the corrections reported:<br />
<pre style="background-color: #fffacd;"><br />
##########################################<br />
##### Begin Task: gencal #####<br />
gencal(vis="3c391_ctm_mosaic_10s_spw0.ms",caltable="3c391_ctm_mosaic_10s_spw0.antpos",caltype="antpos",infile="",spw="",<br />
antenna="",pol="",parameter=[],uniform=True)<br />
Opening MS: 3c391_ctm_mosaic_10s_spw0.ms for calibration.<br />
Initializing nominal selection to the whole MS.<br />
Determine antenna position offests from the baseline correction database<br />
offsets for antenna ea01 : 0.00000 0.00300 0.00000<br />
offsets for antenna ea02 : -0.00080 0.00000 0.00000<br />
offsets for antenna ea03 : -0.00280 0.00000 0.00000<br />
offsets for antenna ea05 : 0.00000 0.00280 0.00000<br />
offsets for antenna ea11 : 0.00090 0.00000 0.00000<br />
offsets for antenna ea12 : -0.01000 0.00450 -0.00170<br />
offsets for antenna ea13 : 0.00000 -0.00080 0.00000<br />
offsets for antenna ea17 : -0.00120 0.00000 0.00000<br />
offsets for antenna ea18 : 0.00040 -0.00080 0.00040<br />
offsets for antenna ea22 : -0.02570 0.00270 -0.01900<br />
offsets for antenna ea23 : -0.00140 0.00000 0.00000<br />
offsets for antenna ea24 : -0.00150 0.00000 0.00000<br />
offsets for antenna ea26 : -0.00190 0.00000 0.00210<br />
offsets for antenna ea27 : 0.00000 0.00190 -0.00160<br />
Beginning specifycal-----------------------<br />
Creating KAntPos Jones table from specified parameters.<br />
Writing solutions to table: 3c391_ctm_mosaic_10s_spw0.antpos<br />
##### End Task: gencal #####<br />
##########################################<br />
</pre><br />
<br />
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: <br />
<br />
<pre style="background-color: #E0FFFF;"><br />
; 2010 BASELINE CORRECTIONS IN METERS<br />
;ANT<br />
;MOVED OBSDATE Put_In_ MC(IAT) ANT PAD Bx By Bz<br />
;<br />
JAN27 FEB12 FEB21 01:57 11 E04 0.0000 0.0000 0.0000<br />
JAN27 FEB12 FEB21 01:57 26 W03 -0.0170 0.0204 0.0041<br />
MAR24 MAR25 MAR26 18:28 17 W07 -0.0061 -0.0069 -0.0055<br />
APR21 MAY02 MAY04 23:25 12 E08 -0.0072 0.0045 -0.0017<br />
MAR09 MAY02 MAY04 23:25 22 N04 -0.0220 0.0040 -0.0190<br />
JUN08 JUN20 JUN22 03:00 10 N03 0.0046 -0.0196 0.0090<br />
JUL17 JUL18 21:44 1 W09 0.0000 0.0030 0.0000<br />
JUL17 JUL18 21:44 2 E02 -0.0008 0.0000 0.0000<br />
JUL17 JUL18 21:44 3 E09 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 5 W08 0.0000 0.0028 0.0000<br />
JUL01 JUL17 JUL18 21:44 6 N06 0.0022 0.0010 0.0059<br />
JUL17 JUL18 21:44 10 N03 0.0008 0.0030 -0.0014<br />
JUL17 JUL18 21:44 11 E04 0.0009 0.0000 0.0000<br />
JUL17 JUL18 21:44 12 E08 -0.0028 0.0000 0.0000<br />
JUL17 JUL18 21:44 13 N07 0.0000 -0.0008 0.0000<br />
JUL17 JUL18 21:44 17 W07 -0.0012 0.0000 0.0000 <br />
JUL17 JUL18 21:44 18 N09 0.0004 -0.0008 0.0004<br />
JUL17 JUL18 21:44 22 N04 -0.0037 -0.0013 0.0000<br />
JUL17 JUL18 21:44 23 E07 -0.0014 0.0000 0.0000<br />
JUL17 JUL18 21:44 24 W05 -0.0015 0.0000 0.0000<br />
JUL17 JUL18 21:44 26 W03 -0.0019 0.0000 0.0021<br />
JUL17 JUL18 21:44 27 E03 0.0000 0.0019 -0.0016<br />
</pre><br />
<br />
=== Initial Flux Density Scaling ===<br />
<br />
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 two calibrator sources to transfer the flux density scaling to the secondary gain calibrator (J1822-0938).<br />
<!-- 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. --><br />
<br />
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).<br />
<br />
To start, let's find the available calibrator models with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] and setting the parameter ''listmodels=True'':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', listmodels=True)<br />
</source><br />
<br />
This command will show all available calibrator models:<br />
<pre style="background-color: #fffacd;"><br />
3C123_P.im 3C138_P.im 3C147_A.im 3C147_Q.im 3C286_A.im 3C286_Q.im 3C380_P.im 3C48_P.im README<br />
3C138_A.im 3C138_Q.im 3C147_C.im 3C147_S.im 3C286_C.im 3C286_S.im 3C48_A.im 3C48_Q.im<br />
3C138_C.im 3C138_S.im 3C147_K.im 3C147_U.im 3C286_K.im 3C286_U.im 3C48_C.im 3C48_S.im<br />
3C138_K.im 3C138_U.im 3C147_L.im 3C147_X.im 3C286_L.im 3C286_X.im 3C48_K.im 3C48_U.im<br />
3C138_L.im 3C138_X.im 3C147_P.im 3C196_P.im 3C286_P.im 3C295_P.im 3C48_L.im 3C48_X.im<br />
</pre><br />
Since any image could be a potential calibrator model, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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':<br />
<br />
<source lang="python"><br />
# In CASA<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms',field='J1331+3030',standard='Perley-Butler 2017',<br />
model='3C286_C.im',usescratch=True,scalebychan=True,spw='')<br />
</source><br />
<br />
<!--[[Image:3C391_setjy.png|200px|thumb|right|setjy inputs]]--><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the same flux density.<br />
* ''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. <br />
* ''model='3C286_C.im' '': From plotms above, it can be estimated that 3C 286 is roughly a point source at this observation's frequency. 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. <br />
* ''usescratch=True '': Due to current bugs with the virtual model we explicitly write to a model column in the MS by setting usescratch=True. <br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] determine a flux density value per channel rather than one value for the entire spectral window.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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.<br />
<br />
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.<br />
<br />
The most important output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] should look similar to the following:<br />
<br />
<pre style="background-color: #fffacd;"><br />
Selected 31964 out of 845379 rows.<br />
J1331+3030 (fld ind 0) spw 0 [I=7.6686, Q=0, U=0, V=0] Jy @ 4.536e+09Hz, (Perley-Butler 2017)<br />
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 ...<br />
</pre><br />
<br />
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 plane (IQUV) for the reference channel 0 is reported, followed by the I flux density in each of the channels to be used for scaling 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, [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] will clear any previous calibration model that fits the selection. In this case, no such previous model data was found.<br />
<br />
Note that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6685524, 0. , 0. , 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
If desired, this can be captured by calling the task by setting it to a variable, e.g. '''myset = setjy(...)'''.<br />
<br />
=== Initial Phase Calibration ===<br />
<br />
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.<br />
<br />
We use the CASA task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] to solve for phase versus time for the central channels on our three calibrators: <br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0all', <br />
field='0,1,9', refant='ea21', spw='0:27~36',<br />
gaintype='G',calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G0all' '': The gain solutions will be stored in this external table.<br />
* ''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.<br />
* ''refant='ea21' '': Earlier, by looking at the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants], a reference antenna near the center of the array was noted. Here is the first time that choice is used, as the antenna closest to the center without being shadowed is generally used as the reference antenna. Strictly, all of the gain corrections derived will be relative to this reference antenna.<br />
* ''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).<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]). For the current dataset we know that the calibrator has negligible circular polarization so the V polarization does not need to be set. <br />
* ''calmode='p' '': Solve for only the phase portion of the gain.<br />
* ''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)<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'] '': Having produced antenna position corrections (as we did above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gencal.html gencal]), they should now be applied.<br />
<br />
To really see what is going on, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to inspect the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] for a single antenna at a time, iterating through each antenna in sequence by clicking on the Next button (right pointing single green arrow) on the GUI to advance the displayed antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0all',xaxis='time',yaxis='phase',<br />
coloraxis='corr',iteraxis='antenna',plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
* ''vis='3c391_ctm_mosaic_10s_spw0.G0all' '': the calibration table to examine solutions<br />
* ''xaxis='time' '': plotting phase solutions vs time<br />
* ''yaxis='phase' '': plotting phase solutions vs time<br />
* ''coloraxis=corr '': colorize by polarization (black=R, pink=L; coloring choice is automatic in plotms)<br />
* ''iteraxis='antenna' '': iterating the plot across each antenna<br />
<br />
[[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;”><br />
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 CASA guide tutorials.<br />
</pre><br />
<br />
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.<br />
<br />
Antennas other than ''ea05'' look OK. We will not be able to transfer calibration for antenna ea05 so we flag it from the data:<br />
<source lang="python"><br />
# In CASA<br />
flagdata(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
flagbackup=True, mode='manual', antenna='ea05')<br />
</source><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.G0', <br />
field='J1331+3030', refant='ea21', spw='0:27~36', calmode='p', solint='int', <br />
minsnr=5, gaintable=['3c391_ctm_mosaic_10s_spw0.antpos'])<br />
</source><br />
You can inspect this with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] as we did above. For example, plot (with colorization by polarization) for the first block of 3C286 data only:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G0',<br />
xaxis='time',yaxis='phase',coloraxis='corr',field='J1331+3030',iteraxis='antenna',<br />
plotrange=[-1,-1,-180,180],timerange='08:02:00~08:17:00')<br />
</source><br />
<br />
=== Delay Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.K0', <br />
field='J1331+3030',refant='ea21',spw='0:5~58',gaintype='K', <br />
solint='inf',combine='scan',minsnr=5,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0'])<br />
</source><br />
<br />
* ''field='J1331+3030' '': For the bandpass calibrator<br />
* ''refant='ea21' '': Delays will be relative to this antenna, make sure it is there!<br />
* ''spw='0:5~58' '': Widest possible frequency range in the spw, avoiding edge channels because they have lower sensitivity<br />
* ''gaintype='K' '': Compute K (i.e., delay) solutions, one per antenna per spw per polarization per solution interval<br />
* ''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<br />
* ''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.<br />
* ''gaintable=['3c391_ctm_mosaic_10s_spw0.antpos','3c391_ctm_mosaic_10s_spw0.G0'] '': Use the antpos and G0 tables that were created earlier<br />
<br />
[[Image:Plotms_3c391-K0-delay_CASA5.4.0.png|200px|thumb|right|Figure 6: delay solutions]]<br />
We can plot these solutions (in nanoseconds) as a function of antenna (Figure 6):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.K0',xaxis='antenna1',yaxis='delay',coloraxis='baseline')<br />
</source><br />
These are within about 4 nanoseconds, as expected for the early science observations with the newly upgraded VLA.<br />
<br />
=== Bandpass Calibration ===<br />
<br />
This step solves for the complex bandpass, <math>B_i</math>. <br />
[[Image:Plotms-3C286-RRbandpass2.png|200px|thumb|right|Figure 7: bandpass illustration]]<br />
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 correlation) for the source J1331+3030, which will serve as the bandpass calibrator. The data are color coded by spectral window, as earlier plots from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms].'')<!-- <font color="CDCDCD"> (x-axis is Channel, y-axis is Amp (data column), field=0, antenna=ea01, correlation=RR, channel range is -10--70, amp range is 0--0.25, colorized by antenna2)</font>--><br />
<br />
Now form the bandpass, using the phase solutions just derived.<br />
<source lang="python"><br />
# In CASA<br />
bandpass(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.B0',<br />
field='J1331+3030',spw='',refant='ea21',combine='scan', <br />
solint='inf',bandtype='B',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.G0',<br />
'3c391_ctm_mosaic_10s_spw0.K0'])<br />
</source><br />
<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.B0' '': Specify where to store the bandpass corrections.<br />
* ''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).<br />
* ''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.<br />
* ''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.<br />
<br />
Once again, one can use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to display the bandpass solutions. Note that in the inputs below, the amplitudes are being displayed as a function of frequency channel. The parameters ''gridrows=2'' and ''gridcols=2'' are used to display multiple plots per page (2 plots per page in the y direction and 2 in the x direction). The first command below shows the amplitude solutions (one per polarization) (Figure 8A) and the second command below shows the phase solutions (one per each polarization). Parameter ''iteration='antenna' '' is used to step through separate plots for each antenna.<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='amp',coloraxis='corr',<br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.B0',field='J1331+3030', <br />
xaxis='chan',yaxis='phase',coloraxis='corr',plotrange=[-1,-1,-180,180], <br />
iteraxis='antenna',gridrows=2,gridcols=2)<br />
</source><br />
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.<br />
<br />
{|<br />
| [[Image:Plotms-3C286-B0-amp-CASA5.4.0.png|200px|thumb|left|Figure 8A: bandpass amplitudes for 3C 286]]<br />
| [[Image:Plotms-3C286-B0-phase-CASA5.4.0.png|200px|thumb|center|Figure 8B: bandpass phases for 3C 286]]<br />
|}<br />
<br />
=== Gain Calibration ===<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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.<br />
<br />
In principle, one could determine the complex antenna gains for all sources with a single invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]; for clarity here, two separate invocations will be used.<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1331+3030',spw='0:5~58',<br />
solint='inf',refant='ea21',gaintype='G',calmode='ap',solnorm=False,<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
interp=['','','nearest'])<br />
</source><br />
* ''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.<br />
* ''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.<br />
* ''field='J1331+3030' '': in this first of the two invocations of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], we are finding gain solutions for calibrator source J1331+3030 (3C 286).<br />
* ''gaintype='G' '': with this option, we will determine complex antenna gain solutions separately for each polarization and each spectral window<br />
* ''calmode='ap', solnorm=False'': 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.<br />
* ''solint='inf ' '': Produce a solution for each scan. Phase coherence for these observations is good.<br />
* ''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.<br />
* ''interp=[' ',' ','nearest']'': the temporal interpolation to use for each gaintable. When there is no attribute included, it will default to 'linear' although it is not recommended to leave all the attributes blank. 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.)<br />
<br />
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-0938.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.G1',<br />
field='J1822-0938',<br />
spw='0:5~58',solint='inf',refant='ea21',gaintype='G',calmode='ap',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
append=True)<br />
</source><br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1', append=True'': In the previous invocation of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], ''append'' was set to False. Here, the gain solutions from the phase calibrator are going to be appended to the existing set from 3C 286 and thus stored in a single table. 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.<br />
<br />
If one checks the gain phase solutions using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], one should see smooth solutions for each antenna as a function of time (see Figures 9A--9B). <br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='phase',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-G1-phase.png')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1',xaxis='time',yaxis='amp',<br />
gridrows=1,gridcols=2,iteraxis='corr',coloraxis='baseline',<br />
plotfile='plotms_3c391-G1-amp.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-phase-pol-CASA5.5.0.png|200px|thumb|left|Figure 9A: gain phase solutions, both polarizations]]<br />
| [[Image:plotcal_3c391-G1-amp-pol-CASA5.5.0.png|200px|thumb|center|Figure 9B: gain amplitude solutions, both polarizations]]<br />
|}<br />
<br />
The lower gain solution values (near 1.0) correspond to the two scans of 3C 286, while the higher gain solution values (near 1.5) correspond to the scans of the phase calibrator, J1822-0938. At this stage in the calibration, we have not yet solved for the flux density scaling. In order for the amplitude of 3C 286 in the data to match the amplitude of its model (which we set above with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]), little scaling of the solution is required (value = 1.0). J1822-0938 is fainter than 3C 286, leading to a higher solution value. The ratio of amplitude solutions between the two sources will be used in a later calibration step ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]) to determine the actual flux density of J1822-0938.<br />
<br />
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=' / ' '':<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.G1', xaxis='time', yaxis='phase',<br />
correlation='/', coloraxis='baseline', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
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.<br />
<br />
<br />
{| <br />
| [[Image:plotcal_3c391-G1-RLphasediff-CASA5.5.0.png|200px|thumb|center|Figure 10: complex polarization ratio]]<br />
|}<br />
<br />
<!--<br />
=== Polarization Calibration ===<br />
<br />
''[If time is running short, skip this step and proceed to''' Scaling the Amplitude Gains''' below.]''<br />
<br />
Having set the complex gains, we need to do the polarization calibration. Polarization 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]. <br />
<br />
Before solving for the calibration solutions, we first use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the polarization model for our polarized position-angle calibrator. The initial run of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] above only set the total intensity of our flux calibrator source, 3C 286. This 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.<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] reported values of: I = 7.66964, 7.5989, 7.53174 Jy @(4.535e+09, 4.601e+09, 4.665e+09)Hz.<br />
We use the Python interpreter to compute a spectral index:<br />
<source lang="python"><br />
# In CASA<br />
alpha = log(7.53174/7.6686)/log(4665.0/4536.0)<br />
</source><br />
which gives ''alpha = -0.64217''. (Type alpha in CASA to see the output.)<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] documentation for further details on this topic.)<br />
<br />
To generate the polarization model, the call to setjy looks like the following:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
c0=0.112 # Fractional polarization=11.2%<br />
d0=33*pi/180 # polarization angle of 33 degrees converted to radians<br />
setjy(vis='3c391_ctm_mosaic_10s_spw0.ms', field='J1331+3030', standard='manual',<br />
spw='0', fluxdensity=[i0,0,0,0], spix=[alpha,0], reffreq='4536.0MHz',<br />
polindex=[c0,0], polangle=[d0,0],<br />
scalebychan=True, usescratch=True)<br />
</source><br />
* ''field='J1331+3030' '': if the flux density calibrator is not specified then ''all'' sources will be assumed to have the input model parameters.<br />
* ''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).<br />
* ''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.<br />
* ''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).<br />
* ''reffreq='4536.0MHz' '': The reference frequency for the input Stokes values; in this case it corresponds to channel 0 from listobs.<br />
* ''polindex=[c0,0]' '': The coefficients of polynomial expansion for the polarization index as a function of frequency.<br />
* ''polangle=[d0,0]' '': The coefficients of polynomial expansion for the polarization angle as a function of frequency.<br />
* ''scalebychan=True'': This allows setjy to compute unique values per channel, rather than applying the reference frequency values to the entire spectral window.<br />
* ''usescratch=False'': DO create/use the MODEL_DATA column explicitly. (''usescratch=False'' saves disk space, but is currently experiencing bugs. It will be fixed in a future release.)<br />
The Stokes V flux has been set to zero, corresponding to no circular polarization.<br />
<br />
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:<br />
<pre><br />
{'0': {'0': {'fluxd': array([ 7.6686 , 0.34933927, 0.78462885, 0. ])},<br />
'fieldName': 'J1331+3030'},<br />
'format': "{field Id: {spw Id: {fluxd: [I,Q,U,V] in Jy}, 'fieldName':field name }}"}<br />
</pre><br />
Alternatively, you may capture this dictionary in a return variable, if you call setjy as '''myset=setjy(...)'''.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] has performed the calculation correctly:<br />
<source lang="python"><br />
# In CASA<br />
i0=7.6686 # Stokes I value for spw 0 ch 0<br />
p0=0.112*i0 # Fractional polarization=11.2%<br />
q0=p0*cos(66*pi/180) # Stokes Q for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
u0=p0*sin(66*pi/180) # Stokes U for spw 0 for pang = 33 deg (Q+iU phase = 66 deg)<br />
</source><br />
Enter 'q0' then 'u0' at the CASA command line to see that the result matches with the output from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy], above.<br />
<br />
We can see the results in the model column in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 11A) showing the model source spectrum:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RR.png')<br />
</source><br />
We can see this translates to the spectrum in QU (Figure 11B):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='amp',ydatacolumn='model',<br />
plotfile='plotms_3c391-model-amp-RL.png')<br />
</source><br />
<br />
Finally, our R-L phase difference is constant at 66 degrees (twice the polarization<br />
angle) as desired (Figure 11C):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RL',<br />
timerange='08:02:00~08:17:00',antenna='ea01&ea02',<br />
xaxis='channel',yaxis='phase',ydatacolumn='model',<br />
plotrange=[-1,-1,-180,180],plotfile='plotms_3c391-model-phase-RL.png')<br />
</source><br />
<br />
{| <br />
| [[Image:plotms_3c391-model-amp-RR_CASA5.0.png|200px|thumb|left|Figure 11A: model RR amplitudes]]<br />
| [[Image:plotms_3c391-model-amp-RL_CASA5.0.png|200px|thumb|center|Figure 11B: model RL amplitudes]]<br />
| [[Image:plotms_3c391-model-phase-RL_CASA5.0.png|200px|thumb|right|Figure 11C: model RL phases]]<br />
|}<br />
<br />
==== Solving for the Cross-Hand delays ====<br />
<br />
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.<br />
<source lang="python"><br />
# In CASA<br />
gaincal(vis='3c391_ctm_mosaic_10s_spw0.ms', caltable='3c391_ctm_mosaic_10s_spw0.Kcross',<br />
field='J1331+3030', spw='0:5~58',<br />
gaintype='KCROSS', solint='inf', combine='scan', refant='ea21',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1'],<br />
gainfield=['','','','J1331+3030'],<br />
parang=True)<br />
</source><br />
<br />
[[Image:plotms_3c391-Kcross-delay_CASA5.4.0.png|200px|thumb|right|Figure 12: cross-hand delay solutions]]<br />
We can plot these (see Figure 12):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.Kcross',xaxis='antenna1',yaxis='delay',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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.<br />
<br />
==== Solving for the Leakage Terms ====<br />
<br />
The task {{polcal}} is used for polarization calibration. In this data set, we observed the unpolarized calibrator J0319+4130 (a.k.a. 3C 84) in order to solve for the instrumental polarization. Task {{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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D1',<br />
field='J0319+4130',spw='0:5~58',<br />
refant='ea21',poltype='Df',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J0319+4130',''])<br />
</source><br />
<br />
* ''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.<br />
* ''field='J0319+4130' '': The unpolarized source J0319+4130 (a.k.a. 3C 84) is used to solve for the leakage terms.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal], otherwise the final data set will contain frequency channels for which the leakage terms have not been calibrated.<br />
* ''poltype='Df ' '': Solve for the leakages (''D'') on a per-channel basis (''f''), assuming zero source polarization.<br />
* ''solint='inf ', combine='scan' '': One solution over the entire run<br />
* ''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 <br />
* ''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.<br />
<br />
After polcal has finished running, you are strongly advised to examine the solutions with [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms], to ensure that everything looks good.<br />
[[Image:plotms_3c391-D1-amp-ea01_CASA5.4.0.png|thumb|Figure 13: Df amp vs. channel for ea01]]<br />
[[Image:plotms_3c391-D1-phase-ea01_CASA5.4.0.png|thumb|Figure 14: Df phase vs. channel for ea01]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='amp', <br />
iteraxis='antenna',coloraxis='corr')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='chan',yaxis='phase', <br />
iteraxis='antenna',coloraxis='corr',plotrange=[-1,-1,-180,180])<br />
</source><br />
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:<br />
[[Image:plotms_3c391-D1_CASA5.4.0.png|thumb|Figure 15: Df solutions for J0319+4130 versus antenna index]]<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D1',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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:<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.D2',<br />
field='J1822-0938',spw='0:5~58',<br />
refant='ea21',poltype='Df+QU',solint='inf',combine='scan',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross'],<br />
gainfield=['','','','J1822-0938',''])<br />
</source><br />
<br />
* ''field='J1822-0938' '': Our gain calibrator observed throughout the scheduling block.<br />
* ''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).<br />
* ''gainfield=['&nbsp;','&nbsp;','&nbsp;','J1822-0938','&nbsp;'] '': For '''3c391_ctm_mosaic_10s_spw0.G1''' use only the solutions from J1822-0938 itself.<br />
<br />
[[Image:plotms_3c391-D2_CASA5.4.0.png|thumb|Figure 16: Df solutions for J1822-0938 versus antenna index]]<br />
We now plot this as we did before:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.D2',xaxis='antenna1',yaxis='amp',coloraxis='corr')<br />
</source><br />
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.<br />
<br />
==== Solving for the R-L polarization angle ====<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html 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:<br />
<br />
<source lang="python"><br />
# In CASA<br />
polcal(vis='3c391_ctm_mosaic_10s_spw0.ms',caltable='3c391_ctm_mosaic_10s_spw0.X1',<br />
field='J1331+3030',combine='scan',<br />
refant='ea21',poltype='Xf',solint='inf',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0',<br />
'3c391_ctm_mosaic_10s_spw0.G1',<br />
'3c391_ctm_mosaic_10s_spw0.Kcross',<br />
'3c391_ctm_mosaic_10s_spw0.D2'],<br />
gainfield=['','','','J1331+3030','',''])<br />
</source><br />
<br />
[[Image:plotms_3c391-X1_CASA5.4.0.png|thumb|Figure 17: Xf solutions versus channel.]]<br />
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 model. However, for consistency/safety it is recommended to always specify a refant when performing polarization calibration.<br />
<br />
As always, it is strongly suggested you check that the calibration worked properly, by plotting up the newly-generated calibration table using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (see Figure 17):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.X1',xaxis='chan',yaxis='phase')<br />
</source><br />
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.<br />
<br />
At this point, you have all the necessary polarization calibration tables.<br />
<br />
--><br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
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%. <br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], which produces a new calibration table containing properly-scaled amplitude gains for the secondary calibrator.<br />
<br />
<source lang="python"><br />
# In CASA<br />
myscale = fluxscale(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
caltable='3c391_ctm_mosaic_10s_spw0.G1', <br />
fluxtable='3c391_ctm_mosaic_10s_spw0.fluxscale1', <br />
reference='J1331+3030',<br />
transfer=['J1822-0938'],<br />
incremental=False)<br />
</source><br />
* ''myscale = fluxscale(...) '': [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] returns a dictionary of results, which we capture in the variable '''myscale'''<br />
* ''caltable='3c391_ctm_mosaic_10s_spw0.G1' '': We provide [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] with the calibration table containing the amplitude gain solutions derived earlier.<br />
* ''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.<br />
* ''reference='J1331+3030' '': We specify the source with the known flux density.<br />
* ''transfer=['J1822-0938']'': We specify the source whose amplitude gains are to be rescaled; if there were multiple secondary calibrators to be used, this parameter value would need to be a python list.<br />
* ''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.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html 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<br />
<pre style="background-color: #fffacd;"><br />
CASA <99>: myscale['1']<br />
Out[99]: <br />
{'0': {'fluxd': array([ 2.29600096, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.00692024, 0. , 0. , 0. ]),<br />
'numSol': array([ 46., 0., 0., 0.])},<br />
'fieldName': 'J1822-0938',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
<br />
</pre><br />
<!--<br />
CASA <100>: myscale['9']<br />
Out[100]: <br />
{'0': {'fluxd': array([ 13.66809981, 0. , 0. , 0. ]),<br />
'fluxdErr': array([ 0.03883741, 0. , 0. , 0. ]),<br />
'numSol': array([ 44., 0., 0., 0.])},<br />
'fieldName': 'J0319+4130',<br />
'fitFluxd': 0.0,<br />
'fitFluxdErr': 0.0,<br />
'fitRefFreq': 0.0,<br />
'spidx': array([ 0., 0., 0.]),<br />
'spidxerr': array([ 0., 0., 0.])}<br />
--><br />
The index '1' above refers to the field number. You can also find the flux density values in the CASA logger:<br />
<pre style="background-color: #fffacd;"><br />
...<br />
Found reference field(s): J1331+3030<br />
Found transfer field(s): J1822-0938<br />
Flux density for J1822-0938 in SpW=0 (freq=4.599e+09 Hz) is: 2.296 +/- 0.00692024 (SNR = 331.781, N = 46)<br />
Storing result in 3c391_ctm_mosaic_10s_spw0.fluxscale1<br />
...<br />
</pre><br />
<br />
Again, [https://science.nrao.edu/facilities/vla/docs/manuals/observing/callist 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.<br />
<br />
We plot the rescaled amplitudes from this table:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='R',coloraxis='baseline')<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.fluxscale1',xaxis='time',yaxis='amp',<br />
correlation='L',coloraxis='baseline')<br />
</source><br />
You can see in Figures 11A and 11B that the amplitude gain factors are now similar across sources, compared to the raw factors in the G1 table.<br />
<br />
{| <br />
| [[Image:plotms_3c391-fluxscale1-amp-R-CASA5.5.0.png|200px|thumb|left|Figure 11A: post-fluxscale amp solutions, R pol]]<br />
| [[Image:plotms_3c391-fluxscale1-amp-L-CASA5.5.0.png|200px|thumb|center|Figure 11B: post-fluxscale amp solutions, L pol]]<br />
|}<br />
<br />
== Applying the Calibration ==<br />
<br />
Now that we have derived all the calibration solutions, we need to apply them to the actual data, using the task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal] run.<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1331+3030',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1331+3030','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='J1822-0938',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','nearest','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], the parallel-hand delays (.K0), and the bandpass solutions (.B0).<br />
* ''gainfield, interp '': To ensure that we use the correct gain amplitudes and phases for a given calibrator (those derived on that same calibrator), we must specify for each calibrator source 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale], we set ''gainfield'' to the field name corresponding to that calibrator, and the desired interpolation type (''interp'') to ''nearest''.<br />
* ''calwt=False '': Using calwt=True (calibrating the weights) is dependent on having truly representative weights in the data and currently the VLA data does not do this, though ALMA does. For the VLA, we are not yet using system calibration data to compute real (1/Jy<sup>2</sup>) weights, thus trying to calibrate them during the applycal stage can produce nonsensical results. In particular, experience has shown that calibrating the weights will lead to problems especially in the self-calibration steps. We will instead set the weights before imaging using the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task (further details below).<br />
<br />
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.<br />
<br />
The procedure for applying the calibration to the target source is very similar to what we just did for the calibrator sources.<br />
<source lang="python"><br />
# In CASA<br />
applycal(vis='3c391_ctm_mosaic_10s_spw0.ms',<br />
field='2~8',<br />
gaintable=['3c391_ctm_mosaic_10s_spw0.antpos', <br />
'3c391_ctm_mosaic_10s_spw0.fluxscale1',<br />
'3c391_ctm_mosaic_10s_spw0.K0',<br />
'3c391_ctm_mosaic_10s_spw0.B0'],<br />
gainfield=['','J1822-0938','',''], <br />
interp=['','linear','',''],<br />
calwt=False)<br />
</source><br />
<br />
* ''field '': We can calibrate all seven target fields at once by setting ''field='2~8' ''. <br />
* ''gainfield '': In this case, we wish to use the gains derived on the secondary calibrator, for the reasons explained in the previous paragraph.<br />
* ''interp '': This time, we linearly interpolate between adjacent calibrator scans, to compute the appropriate gains for the intervening observations of the target.<br />
<br />
<br />
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 12A through 12D):<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld0-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='0',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld0-corrected-phase.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='amp',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotfile='plotms_3c391-fld1-corrected-amp.png')<br />
<br />
plotms(vis='3c391_ctm_mosaic_10s_spw0.ms',field='1',correlation='RR,LL',<br />
antenna='',avgtime='60',xaxis='channel',yaxis='phase',<br />
ydatacolumn='corrected',coloraxis='corr',<br />
plotrange=[-1,-1,-180,180],<br />
plotfile='plotms_3c391-fld1-corrected-phase.png')<br />
</source><br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] or via manual flagging in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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. Images 12A through 12D show that there is no sign of bad data remaining.<br />
{|<br />
| [[Image:plotms_3c391-fld0-corrected-amp_5.5.0.png|thumb|Figure 12A: amp vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld0-corrected-phase_5.5.0.png|thumb|Figure 12B: phase vs channel for 3C286 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-amp_5.5.0.png|thumb|Figure 12C: amp vs channel for J1822-0938 RR,LL]]<br />
| [[Image:plotms_3c391-fld1-corrected-phase_5.5.0.png|thumb|Figure 12D: phase vs channel for J1822-0938 RR,LL]]<br />
|}<br />
<br />
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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
split(vis='3c391_ctm_mosaic_10s_spw0.ms',outputvis='3c391_ctm_mosaic_spw0.ms',<br />
datacolumn='corrected',field='2~8',correlation='RR,LL')<br />
</source><br />
<br />
* ''outputvis '': We give the name of the new measurement set to be written, which will contain the calibrated data on the science targets.<br />
* ''datacolumn '': We use the CORRECTED_DATA column, containing the calibrated data which we just wrote using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal].<br />
* ''field '': We wish to put all the mosaic pointings into a single measurement set, for imaging and joint deconvolution.<br />
* ''correlation '': For the purposes of this tutorial, we have calibrated only the parallel polarization correlations.<br />
<br />
Prior to imaging, it is a good idea to run the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html statwt] task to correct the data weights (<i>weight</i> and <i>sigma</i> columns) in the measurement set. Running [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.manipulation.statwt.html 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.<br />
<br />
<source lang="python"><br />
# In CASA<br />
statwt(vis='3c391_ctm_mosaic_spw0.ms',datacolumn='data')<br />
</source><br />
<br />
= Imaging = <br />
<br />
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.<br />
<br />
<math><br />
I(l,m) = \int V(u,v) e^{[2\pi i(ul + vm)]} dudv<br />
</math><br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/synthesis_imaging.html Synthesis Imaging] section of the CASA documentation.<br />
<br />
CASA has a task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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].<br />
<br />
== Imaging parameters ==<br />
<br />
[[Image:plotms_3c391-mosaic0-uvwave.png|thumb|Figure 13: ''plotms'' plot showing Amplitude vs UV Distance in wavelengths for 3C391 at 4600 MHz]]<br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] to look at the newly-calibrated, target-only data set:<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='3c391_ctm_mosaic_spw0.ms',xaxis='uvwave',yaxis='amp',<br />
ydatacolumn='data', field='0',avgtime='30',correlation='RR',<br />
plotfile='plotms_3c391-mosaic0-uvwave.png',overwrite=True)<br />
</source><br />
You should obtain a plot similar to Figure 13 with the calibrated visibility amplitude as a function of <math>u</math>-<math>v</math> distance. Note that while 'uvdist' and 'uvwave' are in essence the same, they differ in units and by respect values. The difference is that 'uvdist' is measured in physical units, i.e., meters (as the antenna separation is in meters), whereas 'uvwave' is measured in units of wavelengths at the specific frequency.<br />
<br />
The maximum baseline is about 16,000 wavelengths, i.e., a smallest angular scale of 12 arcseconds (<math>\lambda/D=1/16000</math>). The most effective cleaning occurs with at least 4-5 pixels across the synthesized beam. For the resolution element of 12 arcseconds, a cell size of 2.5 arcseconds will give just under 5 pixels per beam. <br />
<br />
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. With the choice of ''gridder='mosaic' ''(our main mosaicking algorithm), we will image an area somewhat larger than the size of the supernova remnant in order 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] internally applies a padding of 1.2 (= 3 x 2/5), we will use an image size of 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.<br />
<br />
== Multi-scale Mosaic Clean ==<br />
<br />
In this tutorial, we will run the cleaning task interactively so that we can set and modify the mask:<br />
<source lang="python"><br />
# In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1, threshold='1.0mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45], smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480], cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] is powerful with many inputs and a certain amount of experimentation likely is required.<br />
[[Image:3c391-tclean-interactive-start_CASA5.4.0.jpeg|thumb|Figure 14: Interactive clean at the beginning, having selected polygon region and ready to double-click inside to set the mask.]]<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to verify this).<br />
* ''imagename='3c391_ctm_spw0_multiscale' '': the output image names will all start with this (e.g., 3c391_ctm_spw0_multiscale.image, 3c391_ctm_spw0_multiscale.rms, etc.)<br />
* ''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 an accompanying 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.<br />
* ''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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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, although this can take many hours if the user does all 20000 iterations. <br />
* ''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.<br />
* ''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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window to appear. One can then set clean regions, restricting where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. <br />
* ''imsize=[480,480],cell=['2.5arcsec'] '': See the discussion above regarding the setting of the image size and cell size. If only one number is specified, the same value is used in both x and y directions (square image and/or pixel shape).<br />
* ''stokes='I' '': A single image will be made for total intensity I.<br />
* ''deconvolver='multiscale', scales=[0, 5, 15, 45], 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 (5 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.<br />
* ''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).<br />
* ''pbcor=False '': by default ''pbcor=False'' and a flat-noise image is produced. We can do the primary beam correction later (see below).<br />
* ''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.<br />
<br />
[[Image:3c391-tclean-multiscale-500iters_CASA5.4.0.jpeg|thumb|Figure 15: After the first 500 iterations of multi-scale clean]]<br />
As mentioned above, we can guide the clean process by allowing it to find clean components only within a user-specified region. When [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] runs in interactive mode, a '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' window will pop up as shown in Figure 14. 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.<br />
<br />
At any stage in the cleaning, you can adjust the number of iterations that [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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. [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will keep going until it reaches threshold or runs out of cycles (the cycles field to the right of the iterations).<br />
<br />
[[Image:3c391-tclean-residuals_CASA5.4.0.jpeg|thumb|Figure 16: Interactive residuals after about 14000 iterations of multi-scale clean]]<br />
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 15 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 16) the residuals were looking good (similar noise level inside and outside of the clean region). As mentioned above, restarting [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] with different ''multiscale=[...]'' choices can help also.<br />
<br />
Task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] will make several output files, all named with the prefix given as ''imagename''. These include:<br />
* ''.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<br />
* ''.pb'': effective response of the telescope (the primary beam)<br />
* ''.mask'': areas where [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] has been allowed to search for emission<br />
* ''.model'': sum of all the clean components, which also has been stored as the MODEL_DATA column in the measurement set<br />
* ''.psf'': dirty beam, which is being deconvolved from the true sky brightness during the clean process<br />
* ''.residual'': what is left at the end of the deconvolution process; this is useful to diagnose whether or not to clean more deeply<br />
* ''.weight'': image of un-normalized sum of PB-square (for mosaics)<br />
* ''.sumwt'': a single pixel image containing sum of weights per plane<br />
<br />
[[Image:3c391-tclean-residuals-CASA6.4.1.png|thumb|Figure 17: Viewer panel of final restored image (using HotMetal1 colormap and Scaling Power Cycles = -1)]]<br />
<br />
After the imaging and deconvolution process has finished, you can use the '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' to look at your image.<br />
<source lang="python"><br />
# In CASA<br />
viewer('3c391_ctm_spw0_multiscale.image')<br />
</source><br />
<br />
However, CASA viewer is no longer maintained and will be replaced in future versions of CASA. Therefore, we encourage the user to try using the NRAO replacement visualization tool for images and cubes, CARTA the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization. <br />
<br />
In viewer, 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. In CARTA these options are available via the Render Configuration widget. Using this widget, one may select the scaling type, the max and min value, adjust the bias/contrast, and choose an appropriate color map to better emphasize the faint emission and compare to the noise (Figure 17).<br />
<br />
The [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean], but it is useful to see the flat-noise image and residuals to evaluate the quality of the clean image. Therefore, we use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.impbcor.html impbcor] to divide the ''.image'' by the ''.pb'' image to produce a primary beam corrected restored image:<br />
<source lang="python"><br />
# In CASA<br />
impbcor(imagename='3c391_ctm_spw0_multiscale.image',pbimage='3c391_ctm_spw0_multiscale.pb',<br />
outfile='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
<br />
You can open this in the viewer and see that it has indeed raised the noise (and signal) at the edges of the mosaic.<br />
<br />
== Image Analysis ==<br />
<br />
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://casadocs.readthedocs.io/en/v6.4.1/notebooks/image_analysis.html Image Analysis] section of the CASA documentation.<br />
<br />
The most straightforward statistic is the peak brightness, which is determined by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html imstat].<br />
<source lang="python"><br />
mystat = imstat(imagename='3c391_ctm_spw0_multiscale.pbcorimage')<br />
</source><br />
This task returns a Python dictionary which we capture in the variable ''mystat''.<br />
<br />
The dictionary contains the values which you can extract for further use. For example, for a particular instance of<br />
the previous clean, we found:<br />
<pre style="background-color: #E0FFFF;"><br />
CASA <4>: mystat<br />
Out[4]: <br />
{'blc': array([0, 0, 0, 0], dtype=int32),<br />
'blcf': '18:50:04.251, -01.05.40.567, I, 4.59835e+09Hz',<br />
'flux': array([ 9.78121725]),<br />
'max': array([ 0.15670438]),<br />
'maxpos': array([288, 256, 0, 0], dtype=int32),<br />
'maxposf': '18:49:16.243, -00.55.00.579, I, 4.59835e+09Hz',<br />
'mean': array([ 0.00387879]),<br />
'medabsdevmed': array([ 0.00120803]),<br />
'median': array([ 0.00038406]),<br />
'min': array([-0.00684072]),<br />
'minpos': array([237, 414, 0, 0], dtype=int32),<br />
'minposf': '18:49:24.744, -00.48.25.580, I, 4.59835e+09Hz',<br />
'npts': array([ 116013.]),<br />
'q1': array([-0.00064426]),<br />
'q3': array([ 0.00203547]),<br />
'quartile': array([ 0.00267972]),<br />
'rms': array([ 0.01261286]),<br />
'sigma': array([ 0.01200169]),<br />
'sum': array([ 449.99001048]),<br />
'sumsq': array([ 18.45584197]),<br />
'trc': array([479, 479, 0, 0], dtype=int32),<br />
'trcf': '18:48:44.407, -00.45.43.065, I, 4.59835e+09Hz'}<br />
<br />
CASA <5>: mystat['max'][0]<br />
Out[5]: 0.156704381108284<br />
</pre><br />
and so the peak flux density is 0.157 Jy/beam.<br />
<br />
[[Image:3c391-viewer-final-polygon-CASA6.4.1.png|thumb|right|Figure 18: viewer polygon region drawing for on-source statistics]]<br />
[[Image:3c391-viewer-polygon-forrms-CASA6.4.1.png|thumb|right|Figure 19: viewer polygon region for off-source statistics (with Scaling Power Cycles = -1)]]<br />
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., <br />
<br />
<center><br />
<math>S = \int d\Omega I</math><br />
</center><br />
<br />
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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.imstat.html 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.<br />
<br />
At this point you may open '''[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.viewer.html viewer]''' and use it to display the corrected image or open the image within CARTA (Figure 18). If using viewer then 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 '!':<br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.pbcorimage' &<br />
</source><br />
<br />
In viewer, 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 a polygonal region. If using CARTA one may find a polygonal selection tool to similarly select a polygonal region as shown in Figure 18 with the desired mouse button. <br />
<br />
Using the polygonal selection tool, outline the supernova remnant. Start drawing vertices by clicking on points in the image in succession, when you draw the final vertex then double-click to connect and finalize the region. In CARTA, when you click your mouse 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.<br />
<br />
In CARTA, if you find you don't like your region you can dismiss it with the delete key or by double clicking within the region and clicking the "Delete" button, otherwise in the viewer you may select the region and press ESC. Also, in CARTA you can also select under File; Export regions to export regions you have created for later use or likewise in viewer you may save the region using the region panel.<br />
<br />
In CARTA, to view statistics one may use the Statistics tool located under the Widgets tab and then select the appropriate region. In viewer, 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.<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.pbcorimage)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 18836 4.318515e+02 9.386948e+00 <br />
Mean Rms Std dev Minimum Maximum <br />
2.292692e-02 3.106691e-02 2.096504e-02 -1.934644e-03 1.567044e-01 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
</pre><br />
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.<br />
<br />
By contrast, for the rms noise level, one can load the original (un-pbcor) image: <br />
<source lang="python"><br />
# In CASA<br />
!casaviewer '3c391_ctm_spw0_multiscale.image' &<br />
</source><br />
and to ''exclude'' the source's emission to the extent possible as shown in Figure 19, 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:<br />
<pre style="background-color: #E0FFFF;"><br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
(3c391_ctm_spw0_multiscale.image)<br />
Stokes Velocity Frame Doppler Frequency <br />
I 0km/s LSRK RADIO 4.59835e+09 <br />
BrightnessUnit BeamArea Npts Sum FluxDensity <br />
Jy/beam 46.0055 23833 -1.520854e+00 -3.305808e-02 <br />
Mean Rms Std dev Minimum Maximum <br />
-6.381295e-05 5.174784e-04 5.135396e-04 -2.055434e-03 1.800399e-03 <br />
region count <br />
1 <br />
---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----<br />
<br />
</pre><br />
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.<br />
<br />
<!--<br />
Spectral index imaging with mosaic gridder is not working yet as of CASA 5.4.0.<br />
( Spectral Index Imaging )<br />
<br />
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.<br />
<br />
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.<br />
<br />
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.<br />
--><br />
<br />
== Self-Calibration ==<br />
<br />
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. <br />
<br />
More specifically, the observed visibility data on the <math>i</math>-<math>j</math> baseline can be modeled as <br />
<br />
<math><br />
V'_{ij} = G_i G^*_j V_{ij}<br />
</math><br />
<br />
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.<br />
<br />
For a more detailed introduction to self-calibration, see our [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#Self-calibration_of_VLA_Data VLA Self-calibration Tutorial]. There is also a small amount of discussion in the old CASA Reference Manual on <br />
[http://casa.nrao.edu/docs/cookbook/casa_cookbook006.html#sec355 self calibration] (see Section 5.11), and 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: <br />
<br />
* Produce an image ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]) using the CORRECTED_DATA column.<br />
* Derive a series of gain corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
* Apply these corrections ([https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html applycal]) to the DATA column, to form a new CORRECTED_DATA column, ''overwriting'' the previous contents of CORRECTED_DATA.<br />
<br />
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). We first use '''delmod''' on the MS to get rid of the previous model.<br />
<source lang="python"><br />
#In CASA<br />
delmod('3c391_ctm_mosaic_spw0.ms')<br />
<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_ms_I',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=500,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
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. <br />
<br />
After you are happy with the image:<br />
<source lang="python"><br />
#In CASA<br />
gaincal(vis='3c391_ctm_mosaic_spw0.ms',caltable='3c391_ctm_mosaic_spw0.selfcal1',<br />
field='',spw='',selectdata=False,<br />
solint='30s',refant='ea21',minblperant=4,minsnr=3,<br />
gaintype='G',calmode='p')<br />
<br />
applycal(vis='3c391_ctm_mosaic_spw0.ms',<br />
field='',spw='',selectdata=False,<br />
gaintable= ['3c391_ctm_mosaic_spw0.selfcal1'],gainfield=[''],interp=['nearest'],<br />
calwt=[False],applymode='calflag')<br />
</source><br />
The ''CORRECTED_DATA'' column of the MS now contains the self-calibrated visibilities, they will now be used by [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean]. The <br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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 without changing the data. You can see ahead of time what applycal will do by running with ''applymode='trial' ''which will do the reporting but nothing else.<br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Does allowing applycal to flag the data give better images?<br />
* Or, does using ''applymode='calonly' ''give improved results?<br />
|-<br />
|}<br />
<br />
To see what this selfcal has done, do a deep clean:<br />
<source lang="python"><br />
#In CASA<br />
tclean(vis='3c391_ctm_mosaic_spw0.ms',imagename='3c391_ctm_spw0_multiscale_selfcal1',<br />
field='',spw='',<br />
specmode='mfs',<br />
niter=20000,<br />
gain=0.1,threshold='1mJy',<br />
gridder='mosaic',<br />
deconvolver='multiscale',<br />
scales=[0, 5, 15, 45],smallscalebias=0.9,<br />
interactive=True,<br />
imsize=[480,480],cell=['2.5arcsec','2.5arcsec'],<br />
stokes='I',<br />
weighting='briggs',robust=0.5,<br />
pbcor=False,<br />
savemodel='modelcolumn')<br />
</source><br />
<br />
{| style="background:#98FB98"<br />
|-<br />
| '''Questions for the Advanced Student:'''<br />
* Is this better than the original multiscale image? By how much?<br />
* Can you make a difference image (between the original and selfcal1 images) using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.analysis.immath.html immath]?<br />
* How big were the phase changes made by the calibration? Were there specific antennas with larger errors?<br />
|-<br />
|}<br />
<br />
Commonly, this self-cal procedure is applied multiple times.<br />
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.<br />
<br />
Self-calibration requires experimentation. Do not be afraid to dump an image, or even a set of gain corrections, <br />
change something and try again. Having said that, here are several general comments or guidelines:<br />
<br />
* 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.<br />
<br />
* 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.<br />
<br />
* A common metric for self-calibration is whether the image ''dynamic range'' (= max/rms) has improved. An improvement of 10% is quite acceptable.<br />
<br />
* 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.<br />
<br />
* Start self-calibration with phase-only solutions (parameter ''calmode='p' ''in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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%.<br />
<br />
* In initial rounds of self-calibration, consider solution intervals longer than the nominal sampling time (parameter ''solint'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]) and/or lower signal-to-noise ratio thresholds (parameter ''minsnr'' in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html 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.<br />
<br />
* The task [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.applycal.html 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://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagmanager.html flagmanager]'''.<br />
<br />
* You can track the agreement between the DATA, CORRECTED_DATA, and MODEL in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]. The options in the 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.<br />
<br />
* You should consider examining the solutions from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] by using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] in order to assure that the corrections are sensible. Smoothly varying phases are good, jumps are usually not. (However, because the phases are plotted &plusmn;180 degrees, there can be apparent jumps if the phases are very near &#043;180 deg or &minus;180 deg.)<br />
<br />
* 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.<br />
<br />
= On Your Own: 3C391 second frequency and G93.3+6.9 =<br />
<br />
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.<br />
<br />
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.<br />
<br />
1. 3C391 spw 1 (at 7.5 GHz)<br />
<br />
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<br />
<!-- 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) <br />
--><br />
combine the two calibrated MSs in [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.tclean.html tclean] to make a deeper MFS image (this might be tricky).<br />
<br />
2. Supernova Remnant G93.3+6.9 at L-band<br />
<br />
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:<br />
<br />
* There is strong RFI in this spectral window of the original 2 spw dataset. You will need to find it (e.g., using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms]) and avoid it in imaging. You can also flag those channels using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html 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 [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] (e.g., parameter ''antenna='ea0x&ea0y' '').<br />
<br />
* We have not edited out bad or dead antennas for you (unlike in 3C391). You will need to find these using [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] and then [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.flagging.flagdata.html flagdata] them. One helpful [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html 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?<br />
<br />
* 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).<br />
<br />
* There is no observation of a flux calibrator like J1331+3030. You need to use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] to set the Stokes I flux of the gain calibrator. We use the approximate flux density of 5.8 Jy for J2038+5119.<br />
<br />
* 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? <br />
<br />
* 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 tclean.<br />
<br />
Questions about this tutorial? Please contact the [http://go.nrao.edu/obshelp NRAO Helpdesk].<br />
{{Checked 6.4.1}} <br />
[[Main Page | &#8629; '''CASAguides''']]<br />
6.4.1</div>Akapinskhttps://casaguides.nrao.edu/index.php?title=Karl_G._Jansky_VLA_Tutorials&diff=35040Karl G. Jansky VLA Tutorials2023-05-09T04:44:27Z<p>Akapinsk: /* MG0414+0534 P-band Spectral Line Tutorial */</p>
<hr />
<div><br />
Disclaimer: These tutorials provide guidelines to help users become familiar with VLA data reduction in [https://casa.nrao.edu/ CASA]. They offer examples for common general-use cases such as spectral line, continuum, linear polarization, and mosaicking. However, the results demonstrated here are specific to the given data sets. The VLA is an extremely flexible instrument, and the techniques presented here may not apply equally to every individual VLA data set, especially if the type of observations, quality of data, or imaging analysis are particularly different or complicated. More details about CASA and its tasks and tools are available in the [https://casa.nrao.edu/casadocs Online CASA Documentation]. Further assistance with VLA data reduction is available through the [https://help.nrao.edu/ NRAO HelpDesk].<br />
<br />
''For data reduction of pre-EVLA upgrade VLA data, we provide separate, [https://casaguides.nrao.edu/index.php/Pre-upgrade_VLA_Tutorials pre-upgrade VLA data reduction tutorials]''<br />
<br />
''In addition to the current VLA CASA Guides below, we also provide links to [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials-archived older versions of the VLA CASA guides].''<br />
<br />
<br />
<!--<br />
--><br />
<br />
== Introduction ==<br />
<br />
The Karl G. Jansky Very Large Array (VLA) Tutorials are meant to guide the observer through some common types of data analysis, using example datasets, and including explanations of the individual steps. These analyses will be broadly applicable to many VLA data sets. <br />
<br />
<br />
If you are new to CASA, you may start with <h3>[https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA]</h3><br />
<br />
<!--<br />
If you are new to VLA Data, you may start with <h3>[[VLA: Getting Started | Getting Started with VLA data]]</h3><br />
--><br />
<br />
== VLA Data Reduction Tutorials ==<br />
<br />
<br />
<br />
=== High frequency (36GHz), spectral line data reduction: Carbon Star IRC+10216 ===<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php?title=VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.2.0 IRC+10216 Tutorial] (CASA 6.2.0) <br />
<br />
* This tutorial requires to download a dataset <font color=green>1.1GB</font> in size<br />
<br />
Calibrate and make image cubes of the line emission from this asymptotic giant branch star. This is a high-frequency VLA dataset. Includes:<br />
* Inspecting data; basic flagging & calibration<br />
* Subtracting continuum emission <br />
* Imaging the spectral lines<br />
* Imaging the continuum<br />
* Image analysis<br />
* Self-calibration <br />
</blockquote><br />
<br />
=== 6cm Continuum Imaging, Mosaicking: Supernova Remnant 3C391 ===<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php?title=VLA_Continuum_Tutorial_3C391 3C391 Tutorial] (CASA 6.4.1) <br />
<br />
* This tutorial requires to download a dataset <font color=orange>3.1GB</font> in size<br />
<br />
Calibrate VLA continuum data, image a mosaic of the region in Stokes I. Includes:<br />
* Inspecting data; basic flagging <br />
* Calibration<br />
* Image Analysis<br />
* Self-calibration <br />
</blockquote><br />
<br />
=== Polarization Calibration based on CASA pipeline standard reduction: The radio galaxy 3C75 ===<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php/Polarization_Calibration_based_on_CASA_pipeline_standard_reduction:_The_radio_galaxy_3C75 Polarization Calibration based on CASA pipeline (3C75)] (CASA 6.4.1) <br />
<br />
* This tutorial requires to download a dataset <font color=red>10GB</font> in size<br />
<br />
This tutorial demonstrates continuum calibration with the standard VLA pipeline and focuses on linear polarization calibration based on pipeline products, as well as full Stokes wide-field imaging and analysis. It includes:<br />
* Instructions on how to execute the VLA pipeline<br />
* How to modify pipeline products for polarization calibration<br />
* Linear Polarization Calibration<br />
* Wide-field Polarization Imaging<br />
* Self-calibration<br />
* Analysis of Polarization Products<br />
</blockquote><br />
<br />
=== P-band continuum imaging data reduction tutorial: 3C129 ===<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php/VLA_Radio_galaxy_3C_129:_P-band_continuum_tutorial 3C129 P-band Tutorial] (CASA 6.4.1)<br />
<br />
* This tutorial requires to download a dataset <font color=red>26GB</font> in size <br />
<br />
This low frequency VLA tutorial for the observation of radio galaxy 3C 129 focuses on low frequency wide-fractional-bandwidth data in the sub GHz regime and demonstrates multi-frequency synthesis imaging with w-projection. This includes:<br />
* Basic flagging and evaluation<br />
* Automatic RFI Excision<br />
* Ionospheric Calibration<br />
* Self - Calibration<br />
* Widefield imaging <br />
</blockquote><br />
<br />
=== MG0414+0534 P-band Spectral Line Tutorial ===<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php?title=MG0414%2B0534_P-band_Spectral_Line_Tutorial_-_CASA_6.5.2 MG0414+0534 P-band Spectral Line Tutorial (CASA 6.5.2)] <br />
<br />
* This tutorial is based on an archival data-set of 142 GB in size, but we will extract only a <font color=red>33GB</font> portion of this data-set to work on. <br />
<br />
This VLA P-band tutorial is aimed at calibrating and making an image cube of line-emission centered on 390.6 MHz. It includes:<br />
* P-band spectral-line observing strategies<br />
* Basic flagging options<br />
* Low-frequency calibration and self-calibration<br />
* Spectral-line imaging<br />
</blockquote><br />
<br />
=== HI 21 cm Spectral Line Data Reduction Tutorial ===<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php/HI_21cm_(1.4_GHz)_spectral_line_data_reduction:_LEDA_44055-CASA6.5.2 HI 21cm Spectral Line (CASA 6.5.2)]<br />
<br />
* This tutorial is based on an archival data-set of <font color=red>85 GB</font> in size. <br />
<br />
This HI 21cm spectral line tutorial is aimed at calibrating and making an image cube of the dwarf galaxy LEDA4 4055. It includes:<br />
* Finding the HI 21 cm spectral line in LEDA 44055<br />
* Basic flagging <br />
* Splitting out the HI Line<br />
* Spectral-line imaging<br />
* Continuum Subtraction<br />
<br />
</blockquote><br />
<br />
== VLA Topical Guides ==<br />
<br />
<br />
=== Flagging VLA Data in CASA === <br />
<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php/VLA_CASA_Flagging Topical Guide: Flagging VLA Data] (CASA 6.4.1)<br />
<br />
* This tutorial requires to download a dataset <font color=orange>4.9GB</font> in size<br />
<br />
This tutorial describes different flagging techniques, including:<br />
<br />
* Identifying Problematic Antennas from the Operator Logs<br />
* Online Flags <br />
* Shadowing, zeroes, quacking, flagmanager, Hanning smoothing<br />
* Automatic RFI excision (TFCrop, RFlag)<br />
* Interactive Flagging (plotms, msview)<br />
* Flagging Summary & Report<br />
</blockquote><br />
<br />
=== Imaging VLA Data in CASA ===<br />
<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php/VLA_CASA_Imaging Topical Guide: Imaging VLA Data] (CASA 6.5.2)<br />
<br />
* This tutorial requires to download a dataset <font color=green>1.2GB</font> in size<br />
<br />
The Imaging topical guide shows annotated examples of different imaging techniques that are applicable to different science applications. This tutorial includes:<br />
<br />
* An Introduction to the CLEAN algorithm, data and imaging weights, primary and synthesized beams<br />
* Clean Output Images<br />
* Dirty Image, Regular CLEAN & RMS Noise, CLEAN with different Weights<br />
* Multi-Scale CLEAN<br />
* Multi-Scale, Wide-Field CLEAN (w-projection)<br />
* Multi-Scale, Multi-Term Frequency Synthesis<br />
* Multi-Scale, Multi-Term Frequency, Widefield CLEAN<br />
* Imaging Outlier Fields<br />
* Primary Beam Correction<br />
* Imaging Spectral Cubes, Beam per Plane<br />
* Image Header, Image Conversion<br />
</blockquote><br />
<br />
=== Self-calibration of VLA Data ===<br />
<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php/VLA_Self-calibration_Tutorial Topical Guide: VLA Self-calibration Tutorial] (CASA 6.4.1)<br />
* This tutorial requires to download a dataset <font color=red>19GB</font> in size<br />
<br />
This tutorial demonstrates how to perform self-calibration on a VLA data set, covering aspects such as how to choose the time interval, signal-to-noise ratio, and combination over spectral windows and polarizations.<br />
</blockquote><br />
<br />
=== VLA Multi-Configuration Data Combination ===<br />
<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php/VLA_Data_Combination Topical Guide: VLA Data Combination Guide] (CASA 6.4.1) <br />
* This tutorial requires to download a dataset <font color=green>3.0GB</font> in size<br />
<br />
The VLA Data Combination Tutorial provides guidance on the combination of multi-configuration VLA data sets (in this case VLA A, B, C and D configurations). The data are re-weighted in two different ways, combined, and imaged.<br />
</blockquote><br />
<br />
=== Source Subtraction in VLA data ===<br />
<br />
<blockquote><br />
* [[VLA_Source_Subtraction_Topical_Guide | Topical Guide: Source Subtraction in VLA data]] (CASA 6.4.1)<br />
* This tutorial requires to download a dataset <font color=green>1.4GB</font> in size<br />
<br />
This topical guide demonstrates how to remove a time variable source from the visibility data.<br />
</blockquote><br />
<br />
=== Correcting for a Spectral Index in Bandpass Calibration ===<br />
<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php/VLA_CASA_Bandpass_Slope Topical Guide: Correcting for a Spectral Index in Bandpass Calibration] (CASA 6.4.1)<br />
* This tutorial requires to download a dataset <font color=orange>3.4GB</font> in size<br />
<br />
This tutorial explains how to obtain a bandpass solution when the bandpass calibrator is a source with an unknown spectral index. This is typically encountered at high frequency observations, where the standard VLA flux density calibrators are too weak for high signal-to-noise bandpass solutions.<br />
</blockquote><br />
<br />
<br />
<!-- <br />
== VLA Tutorials for more Advanced Users ==<br />
<br />
* '''Supernova SN2010FZ: Wide-band, narrow-field imaging; C-band (5-7 GHz)''' (CASA 4.4)<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php?title=EVLA_6cmWideband_Tutorial_SN2010FZ Supernova SN2010FZ Tutorial ] <br />
<br />
* This tutorial requires to download a dataset <font color=orange>2.9GB</font> in size<br />
</blockquote><br />
<br />
<blockquote><br />
Calibrate and image a galaxy field for this mid-frequency VLA observation. This includes:<br />
* Excising RFI from the data<br />
* Basic flagging and calibration steps<br />
* Imaging from one spectral window to full dataset<br />
* Using multi-scale, multi-frequency synthesis<br />
* Image analysis<br />
</blockquote><br />
<br />
* '''Protostar G192.16-3.84: Wide-band, narrow-field imaging using 3-bit sampled data; Ka-band (27-38 GHz)''' (CASA 4.4)<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php?title=EVLA_3-bit_Tutorial_G192 Protostar G192.16-3.84 Tutorial]<br />
<br />
* This tutorial requires the download of an <font color=red>18GB</font> dataset<br />
</blockquote><br />
<br />
<blockquote><br />
Calibrate and image a protostar for this high-frequency VLA observation taken using the 3-bit samplers. Note that this tutorial can be used as a guide for 8-bit data as well. This includes:<br />
* Deleting bad data and RFI<br />
* Basic calibration, including tropospheric opacity and requantizer gain corrections<br />
* Bootstrapping to determine the spectrum of the bandpass calibration source<br />
* Imaging from a single spectral window to the full dataset<br />
* Using multi-frequency synthesis imaging <br />
* Image analysis<br />
</blockquote><br />
<br />
* '''Supernova G55.7_3.4: Wide-band, wide-field imaging; L-band (1-2 GHz)''' (CASA 4.4)<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php?title=EVLA_Wide-Band_Wide-Field_Imaging:_G55.7_3.4 G55.7+3.4 Tutorial]<br />
<br />
* This tutorial requires to download a dataset <font color=red>14GB</font> in size<br />
</blockquote><br />
<br />
<blockquote><br />
This low-frequency VLA tutorial for the observation of a supernova remnant focuses on RFI excision as well as imaging wide-field and wide-fractional-bandwidth data. This includes:<br />
* Basic flagging and evaluation<br />
* Different methods for automatic RFI excision<br />
* Calibrating the data<br />
* Exploring different imaging options: widefield, multi-scale, and multi-frequency synthesis<br />
</blockquote><br />
<br />
<br />
<!--<br />
== Specific Topics ==<br />
<br />
<br />
* [http://casaguides.nrao.edu/index.php?title=WorkshopSelfcal_(Caltech) Self-calibration]<br />
<br />
<br />
* CASA: [http://casaguides.nrao.edu/index.php?title=Writing_a_CASA_Task Writing a CASA task]<br />
<br />
<blockquote><br />
Presents the basics of writing a CASA task, and provides examples of tasks that will be helpful and instructive. <br />
</blockquote><br />
<br />
* [[Baseband Stitching-CASA4.1]]<br />
<br />
<blockquote><br />
Demonstrates the use of the contributed "stitch" task to edit data which has been obtained in an overlapping subband mode.<br />
</blockquote><br />
<br />
* [[Imaging Flanking Fields]]<br />
<br />
* [[Transient reduction pipeline]]<br />
<br />
* [[Obtaining EVLA Data: 3C 391 Example]]<br />
<br />
<br />
== Other ==<br />
* Data Calibration, Imaging, and Analysis - simplified for Community Day Events: [[EVLA high frequency Spectral Line Tutorial - CDE]]<br />
--><br />
<br />
== VLA CASA Simulation Guide ==<br />
<br />
<blockquote><br />
* [https://casaguides.nrao.edu/index.php/Protoplanetary_Disk_Simulation_-_VLA VLA Protoplanetary Disk Simulation Guide] (CASA 6.4.1)<br />
* This tutorial does not require any download. <br />
<br />
The VLA Protoplanetary Disk Simulation Guide shows examples on how to simulate VLA data based on model images. The tutorial will explain the main simulation tools, apply different parameters to simulations, and compares the results to the VLA exposure calculator. <br />
</blockquote><br />
<br />
== VLA CASA Pipeline Guide ==<br />
<br />
<blockquote><br />
* [http://casaguides.nrao.edu/index.php/VLA_CASA_Pipeline VLA CASA Pipeline Guide] (CASA 6.4.1)<br />
* This tutorial does not require any download. <br />
* The guide contains a link to [https://casaguides.nrao.edu/index.php?title=Pipeline:_Frequent_VLA_problems Frequent VLA problems] and how to address them within a pipeline run. <br />
<br />
The VLA CASA Pipeline Guide provides an example of a VLA CASA pipeline run. Whereas the [https://science.nrao.edu/facilities/vla/data-processing/pipeline VLA Pipeline Web Page] describes the pipeline structure, requirements, execution options including restoration, pipeline output products, and pipeline modifications, this CASA guide is a detailed walkthrough of the weblog and provides interpretations of pipeline plots, tables, and Quality Assurance (QA) metrics. <br />
</blockquote></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=MG0414%2B0534_P-band_Spectral_Line_Tutorial_-_CASA_6.5.2&diff=35039MG0414+0534 P-band Spectral Line Tutorial - CASA 6.5.22023-05-09T04:43:37Z<p>Akapinsk: /* Obtaining the data */</p>
<hr />
<div><!--By Bjorn Emonts--><br />
<br />
<b>This CASA Guide is for Version 6.5.2 of CASA.</b> <br />
<br />
{| class="wikitable"<br />
|-<br />
| style="background: red; color: white;" | '''DISCLAIMER'''<br />
|-<br />
| The following guide is for users who are experts in data reduction using CASA. If you are a beginner or novice user, please review other CASA guides found at [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials VLA Tutorials]. <b> Note: This guide may take up to 2-days to complete </b><br />
|}<br />
<br />
== Overview ==<br />
<br />
This tutorial describes how to use CASA 6.5.2 to reduce spectral-line data in the low-frequency P-band of the VLA (230&ndash;470 MHz). The goal is to make an image cube containing HI 21cm absorption against the strong radio continuum of gravitationally lensed radio galaxy MG0414+0534. As a result of the high redshift of z=2.6365, the HI absorption signal in MG0414+0534 is redshifted to an observed frequency of 390.597 MHz. The HI absorption in MG0414+0534 was previously imaged with the VLA by Moore, Carilli & Menten 1999 ([http://iopscience.iop.org/article/10.1086/311818/meta ApJ, 510, 87]), before the upgrade to the WIDAR system.<br />
<br />
We would like to note that the CASAviewer (supporting tasks viewer, imview and msview) has not been maintained for a few years now and will be removed from future versions of CASA. The NRAO replacement visualization tool for images and cubes is CARTA, the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization.<br />
<br />
=== Observing strategy ===<br />
<br />
To perform P-band spectrsocopy, there are three important considerations for planning the observations:<br />
<br />
* Use a bandpass calibrator that is strong enough to accurately calibrate the frequency-dependent gain variations. This is particularly important for most HI 21cm absorption projects, which are typically performed against strong radio continuum sources. As a rule-of-thumb, use ''t''<sub>cal</sub> > ''t''<sub>obj</sub> × (''S''<sub>obj</sub> / ''S''<sub>cal</sub>)<sup>2</sup>, with ''t'' the exposure time and ''S'' the source flux density. This rule-of-thumb serves to avoid introducing excessive additional noise in the spectrum.<br />
<br />
* Additionally, if very high spectral dynamic range is needed (i.e., when expecting a ratio between the detection limit and the radio continuum of about 1:10,000 or more), consider observing a bandpass calibrator several times during your run to be able to correct for time-varying bandpass changes, which scale with the continuum emission in the target field. See the [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/calibration Calibration section] of the Guide to Observing with the VLA for more information.<br />
<br />
* Use a bandwidth that is wide enough to perform accurate self calibration. Using a wide bandwidth for self-calibration is important for fields with relatively weak continuum sources. For strong continuum sources, a narrower bandwidth can be used to avoid excessive RFI. <br />
<br />
The P-band test data on MG0414+0534 that we use in this tutorial were obtained using a large bandwidth. This is to ensure that good bandpass solutions can be procured, and that self-calibration can accurately be performed. However, due to the strong radio continuum of MG0414+0534 (3.3 Jy at 390 MHz), and the large amounts of RFI across the entire band, we only use a small fraction of the total band for data reduction and analysis in this tutorial.<br />
<br />
== Obtaining the data ==<br />
<br />
<font color=red>'''This 33 GB data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing). We are providing this starting data set, rather than the original data set for 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.We will use test data that was taken in a hybrid configuration when the VLA array was being moved from B-config to A-config. <br />
<br />
The entire data set can be downloaded from the [https://data.nrao.edu NRAO archive] by searching for the following Project Code: <br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001<br />
</pre><br />
</div><br />
<br />
This returns a long list with test-data that are publicly available. Our observations were performed on 14 Sept 2016:<br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001.sb32720781.eb32763188.57645.263958564814<br />
</pre><br />
</div><br />
<br />
Note that this observation was duplicated on 15 September 2016. <!-- This second day of observations can be found under filename:<br />
TSUB0001.sb32720781.eb32773507.57646.24443702547 --><br />
<br />
The 15 GB data set from the download has already had online flagging and Hanning smoothing applied, and the smaller data set split out from the larger data set. If you wish, you can download the SDM from the NRAO archive in order to apply the online flags and run Hanning smoothing on the large data set before splitting out the smaller data set to work on. To apply the on line flag use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd]; to apply the Hanning smoothing use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.hanningsmooth.html hanningsmooth] on scans 7 to 16 and field 3 and 4; and to split the data, use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]. For the purpose of this tutorial, we only reduce and image the first data set. Then, you will need to split only the spw 17, and only channels 20 to 485 to remove the borders. <br />
<br />
<!-- The second data set can be reduced in an identical way (pending the flagging, given that the RFI conditions most likely changed). During the imaging stage you can then combine both reduced data sets. --><br />
<br />
<!-- To download the data, fill in your email, select either the "SDM-BDF (all files)" or “MS” option, and check the box next to the data sets that you want. The practical difference between selecting the MeasurementSet (MS) and Science Data Model (SDM) is that for MS the first step in the data reduction described below, namely reading in the SDM data to save it as a MeasurementSet, is already done by the archival engine. Note that you can also opt to download the data as a tar-file by tickking the appropriate box.<br />
<br />
Optionally, you can request to discard data marked as ‘bad’ by ticking the box “Apply Telescope Flags”, which gets rid of data taken during times of instrument calibration, shadowing, slewing, etc. However, it also applies all flags on the science data that were automatically created during the observations. Therefore, a safer option is to not apply any flags before downloading the data, but first inspect and subsequently apply the flags generated during the observations using [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd], as part of the data reduction plan.<br />
<br />
Click "Get My Data" will forward you to the next page, where you should choose the delivery method (either downloading over the internet, or sending home a hard-drive with the data). If you opt to retrieve the data over the internet, wait until you get an email confirming that the data is ready for download. --><br />
<br />
== Examining the Data ==<br />
<br />
=== Loading data into CASA ===<br />
<br />
We will have to untar the 15 GB data set that you've downloaded.<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
tar -xzf MG0414_d1_data.ms.tgz<br />
</pre><br />
<br />
Please use CASA 6.5.2 for this tutorial (typing ''casa -ls'' in a linux window shows the available versions and the current version; to explicitly change the version type, e.g., ''casa -r 6.5.2-26-py3.6'')<br />
<br />
<source lang='bash'><br />
casa<br />
</source><br />
on the command line. This should start a CASA interactive python (iPython) session, and open a separate log window. To guarantee that the below mentioned procedure for data reduction and imaging works, make sure you are using CASA version 6.5.2. While older versions may work as well for the purpose of this tutorial, it is good to read instructions on how to [https://casa.nrao.edu/casa_obtaining.shtml download and install] the latest version of CASA.<br />
<!-- <br />
We will begin by importing our data from the binary format (SDM-BDF) into the MeasurementSet format, which is the standard for CASA data. For this, we use <i>importevla</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
importevla(asdm='TSUB0001.sb32720781.eb32763188.57645.263958564814', vis='MG0414_d1.ms', flagpol=False, applyflags=False, savecmds=True, outfile='flagfile.txt')<br />
</source><br />
<br />
<!-- In this case, we do not apply the flags that were created as part of the observations, but we will write them out to a <i>flagfile.txt</i> file. We will inspect and apply the flags as follows:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagcmd(vis='MG0414_d1.ms', action='plot')<br />
flagcmd(vis='MG0414_d1.ms', action='apply')<br />
</source><br />
<br />
As an alternative to <i>flagcmd</i>, given that we saved the flags to <i>flagfile.txt</i>, we can also use <br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='list', inpfile='flagfile.txt', action='apply')<br />
</source><br />
<br />
to apply the flags.<br />
<br />
One of the flag commands is to <i>clip</i> all data points that have a 0-value, as these most likely have not recorded any science data. This is normally done with the settings <i>correlation=`ABS_RR’</i> and <i>correlation=`ABS_LL’</i>. Because the VLA P-band and 4-band systems use linear XX and YY polarisation, rather than the circular RR and LL polarisation of the other VLA bands, you will encounter an error message when running <i>flagcmd</i>. We can get around this issue by manually clipping the 0-data for the XX and LL polarization with <i>flagdata</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='clip', correlation='ABS_XX,ABS_YY', clipzeros=True, action='apply')<br />
</source><br />
--><br />
<br />
It is a good practice to read the Operator Log that was created by the duty operator during the observations. This log can provide additional information on data that should be flagged manually during the data reduction stage. The Operator logs can be found at [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi Ops Logs form entry], and this is the [http://www.vla.nrao.edu/operators/logs/2016/9/2016-09-14_0620_TSUB0001.pdf direct link for the log of the observation] (in PDF format).<br />
<br />
=== Inspecting the observation info ===<br />
<br />
We will inspect the content of our data set using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs].<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms')<br />
</source><br />
<br />
The task plots an overview of the data in the CASA logger. Notice that the task returns a dictionary on the terminal screen. Using the parameter <i>listfile=`listobs.txt’</i>, this information is written out to the file <i>listobs.txt</i>: <br />
<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms', listfile='listobs.txt')<br />
</source><br />
<br />
The content is included below:<br />
<br />
<small style="font-size:80%;"><pre><br />
Observer: . Frazer Owen Project: uid://evla/pdb/1695465 <br />
Observation: EVLA<br />
Data records: 1179738 Total elapsed time = 9390 seconds<br />
Observed from 14-Sep-2016/06:43:48.0 to 14-Sep-2016/09:20:18.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
14-Sep-2016/06:43:48.0 - 06:48:42.0 7 0 3C48 37044 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
06:48:45.0 - 07:08:39.0 8 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:08:42.0 - 07:28:36.0 9 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:28:39.0 - 07:48:33.0 10 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:48:36.0 - 08:08:30.0 11 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:08:33.0 - 08:14:30.0 12 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
08:14:33.0 - 08:34:27.0 13 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:34:30.0 - 08:54:21.0 14 1 MG0414+0534 150066 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:54:24.0 - 09:14:18.0 15 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
09:14:21.0 - 09:20:18.0 16 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 NONE 3C48 01:37:41.299431 +33.09.35.13299 J2000 0 127008<br />
1 NONE MG0414+0534 04:14:37.800000 +05.34.41.99999 J2000 1 1052730<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 EVLA_P#A0C0#17 466 TOPO 386.312 15.625 7281.2 389.9453 12 XX XY YX YY<br />
Sources: 2<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C48 0 - - <br />
1 MG0414+0534 0 - - <br />
Antennas: 27:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 ea01 W24 25.0 m -107.38.49.0 +33.53.04.0 -2673.3457 -1784.6009 10.4844 -1604008.744400 -5042135.825100 3553403.710800<br />
1 ea02 W56 25.0 m -107.44.26.7 +33.49.54.6 -11333.1991 -7637.6832 15.3636 -1613255.391400 -5042613.097800 3548545.906000<br />
2 ea03 W40 25.0 m -107.41.13.5 +33.51.43.1 -6377.9680 -4286.7773 8.2312 -1607962.451800 -5042338.218100 3551324.962400<br />
3 ea04 E04 25.0 m -107.37.00.8 +33.53.59.7 102.7973 -63.7800 -2.6177 -1601068.806000 -5042051.932700 3554824.838800<br />
4 ea05 E36 25.0 m -107.33.20.2 +33.52.34.3 5761.3733 -2704.6731 33.0133 -1596127.730800 -5045193.742100 3552652.419700<br />
5 ea06 N24 25.0 m -107.37.16.1 +33.55.37.7 -290.3584 2961.8653 -12.2425 -1600930.069900 -5040316.395500 3557330.390000<br />
6 ea07 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8512 1426.6377 -9.3934 -1601061.954400 -5041175.875300 3556058.026700<br />
7 ea08 W64 25.0 m -107.46.20.1 +33.48.50.9 -14240.7524 -9606.2900 17.0885 -1616361.575500 -5042770.516600 3546911.419900<br />
8 ea09 N40 25.0 m -107.37.29.5 +33.57.44.4 -633.6056 6878.5897 -20.7984 -1600592.749000 -5038121.341300 3560574.826900<br />
9 ea10 E20 25.0 m -107.35.43.6 +33.53.29.9 2082.1759 -987.0087 9.4361 -1599340.800100 -5043150.963000 3554065.231500<br />
10 ea12 N32 25.0 m -107.37.22.0 +33.56.33.6 -441.7248 4689.9674 -16.9328 -1600781.044500 -5039347.439100 3558761.527100<br />
11 ea13 E28 25.0 m -107.34.39.3 +33.53.04.9 3732.7776 -1757.3308 21.4271 -1597899.895900 -5044068.684700 3553432.450200<br />
12 ea14 E08 25.0 m -107.36.48.9 +33.53.55.1 407.8283 -206.0315 -3.2236 -1600801.931400 -5042219.382600 3554706.429400<br />
13 ea15 N64 25.0 m -107.37.58.7 +34.02.20.5 -1382.3871 15410.1326 -40.6450 -1599855.687000 -5033332.368600 3567636.606800<br />
14 ea16 W72 25.0 m -107.48.24.0 +33.47.41.2 -17419.4641 -11760.2694 14.9442 -1619757.299900 -5042937.656400 3545120.392300<br />
15 ea17 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2042 12254.2800 -34.2710 -1600128.378100 -5035104.139200 3565024.633900<br />
16 ea18 W48 25.0 m -107.42.44.3 +33.50.52.1 -8707.9181 -5861.7682 15.5302 -1610451.901900 -5042471.123800 3550021.073100<br />
17 ea19 W16 25.0 m -107.37.57.4 +33.53.33.0 -1348.7121 -890.6209 1.2959 -1602592.853500 -5042054.992400 3554140.702800<br />
18 ea20 E16 25.0 m -107.36.09.8 +33.53.40.0 1410.0403 -673.4656 -0.7790 -1599926.104100 -5042772.977200 3554319.801100<br />
19 ea21 E24 25.0 m -107.35.13.4 +33.53.18.1 2858.1906 -1349.1352 13.7186 -1598663.082000 -5043581.391200 3553767.014100<br />
20 ea22 W32 25.0 m -107.39.54.8 +33.52.27.2 -4359.4399 -2923.1314 11.7614 -1605808.634100 -5042230.084000 3552459.197800<br />
21 ea23 E12 25.0 m -107.36.31.7 +33.53.48.5 848.6994 -411.6226 -2.7575 -1600416.518000 -5042462.430500 3554536.041700<br />
22 ea24 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1080 -272.1514 -1.5061 -1601614.083200 -5042001.656900 3554652.505900<br />
23 ea25 N08 25.0 m -107.37.07.5 +33.54.15.8 -68.9088 433.1829 -5.0674 -1601147.942500 -5041733.833600 3555235.947000<br />
24 ea26 E32 25.0 m -107.34.01.5 +33.52.50.3 4701.6503 -2209.7119 25.1976 -1597053.124400 -5044604.675000 3553058.992700<br />
25 ea27 N48 25.0 m -107.37.38.1 +33.59.06.2 -855.2719 9405.9407 -25.9485 -1600374.881000 -5036704.201700 3562667.858900<br />
26 ea28 N72 25.0 m -107.38.10.5 +34.04.12.2 -1685.6797 18861.8306 -43.5015 -1599557.928700 -5031396.353400 3570494.736800<br />
</pre></small><br />
<br />
<!-- === Hanning smoothing the data ===<br />
<br />
When plotting the data in plotms (plotting amplitude against frequency), it is immediately clear that our observing band contains lots of Radio Frequency Interference (RFI), which is unavoidable at these low frequencies. The situation actually looks worse than it is, because ‘Gibbs ringing’ causes the blending of strong RFI signal into adjacent channels (Fig.1). To reduce the effect of Gibbs ringing, we first Hanning smooth the data (please note that this can take a while to run on the entire 142 Gb data set):<br />
<br />
<source lang='python'><br />
# In CASA<br />
hanningsmooth(vis='MG0414_d1_data.ms', datacolumn='data', outputvis='MG0414_d1_hanning.ms')<br />
</source><br />
<br />
[[File:Pband_hanning.png|400px|thumb|right|Fig.1 Reducing the effects of Gibbs ringing by Hanning smoothing the data. Shown is only a small fraction of the band, both before and after Hanning smooth. The amplitude scale is the same in both plots.]]<br />
<br />
=== Splitting the data ===<br />
<br />
Upon further inspection in “plotms” (using ea01, field 0, corr xx,yy, and coloraxis baseline), it is clear that there is a lot of RFI across most of the 64 MHz (or 43,000 km/s) band that we used for the observations. Luckily, the region around the expected HI absorption line at 390.6 MHz is relatively clean of RFI. Because our target is strong enough in the continuum to perform a good self-calibration, we select this relatively clean part of the band centered around the expected HI line. Note that there were two IFs with different spectral resolution included in the observations. We need only one of the two IFs, and choose the one with the highest spectral resolution. Moreover, we only need the sources 3C48 (which we will use for bandpass, gain and flux calibration) and our target MG0414+0534, hence we select field=’3,4’. This approach has the additional advantage that we reduce our data volume a lot, bringing it down to about 15 Gb.<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_hanning.ms', outputvis='MG0414_d1_data.ms', datacolumn='data', field='3,4', spw='17:20~485', keepflags=False)<br />
</source><br />
<br />
<font color=red>'''This 15 Gb data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing), and the file can be unpacked by typing <i>tar xzf MG0414_d1_data.ms.tgz</i><br />
--><br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white;"<br />
| style="border: 1px solid darkgray;" | [[File:MG0414_plotants_5.4.0.png|350px|thumb]] || style="border: 1px solid darkgray" | [[File:Ant_logplot_6.5.2.png |350px|thumb]]<br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 1a. Plotants plot for <br />MG0414. || Figure 1b. Plotants plot <br />for MG0414 in a log scale.<br />
|}<br />
<br />
Next we look at a graphical plot of the antenna locations and save a hard copy<br />
in case you want it later using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.plotants.html plotant] (see Figures 1a and 1b). This will be useful for selecting a reference antenna. Note that the VLA was in a period of re-configuration when these MG0414 data were taken, so the antenna configuration is not a standard VLA configuration. Typically a good choice is an antenna close to the center of the array (see Figure 1b). Unless it shows problems after inspection of the data, we provisionally choose ea04. (Note: clicking on any image will open up a larger version.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='MG0414_d1_data.ms',figfile='ant_locations.png')<br />
<br />
# In CASA<br />
# If you would like to see another view of the antennas you may plot them on a log plot<br />
plotants(vis='MG0414_d1_data.ms',logpos=True,figfile='ant_logplot.png')<br />
<br />
</source><br />
<br />
=== Flagging ===<br />
<br />
<!-- NOTE: when revising for CASA release 5.3.0, EM wants to revisit how flagging is approached in the guide. Some of the flagging tasks, such as running rflag and flagging out antennas ea09, 14, and 17 should be introduced earlier - perhaps in this section - so that major flagging is done once and then the user can proceed to the self-calibration and imaging section. Tony --><br />
<br />
[[File:Pband_flagchan.png|760px|thumb|right|Figure 2. Flagging of calibrator 3C48. Shown are the XX and YY polarization on antenna ea01, both before (left) and after (right) flagging the bad channels. The colors represent the different baselines with ea01.]]<br />
<br />
We will now perform a more in-depth flagging of the bad data. Our strategy is to first focus on the calibrator source (in this case only 3C48). If the calibrator data are flagged well, we should be able to perform an accurate calibration of the target data. Later in this document we will then flag the calibrated target data using an automated flagger. <br />
<br />
When plotting amplitude vs frequency in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms], we see that there are still two ranges of channels filled with RFI throughout the observing run (see Figure 2). <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We will flag this data with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]. Because we are flagging channels on all scans of the bandpass calibrator 3C48, these channels cannot be calibrated accurately, so we flag these channels also in the data of the target.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:148~155', action='apply')<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:51~59', action='apply')<br />
</source><br />
<br />
The data on our bandpass+gain+flux calibrator 3C48 now look clean, with no dead or misbehaving antennas. We can repeat the same [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] call as above: <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We now start with the calibration.<br />
<br />
== Calibration ==<br />
<br />
Many of the steps below are based on the CASA tutorial on [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#3C129_P-band_continuum_imaging_data_reduction_tutorial reducing VLA P-band continuum data].<br />
<br />
=== <i>A priori</i> Antenna Position Corrections ===<br />
<br />
We start the calibration by obtaining the latest set of antenna-position corrections compared to the stored values that were derived at the start of the observing period. For this you need to run CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>. (Be sure to have internet connection in order to grab the antenna position corrections.)<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='antpos', caltable='antpos.cal')<br />
</source><br />
<br />
The output is a list of antenna position corrections that are written to the calibration table <i>antpos.cal</i>:<br />
<br />
<small style="font-size:85%;"><pre><br />
2017-07-25 19:54:51 INFO gencal Determine antenna position offests from the baseline correction database<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea01 : 0.00200 0.00000 0.00200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea02 : 0.00210 0.01800 0.00430<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea03 : -0.00700 0.01600 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea06 : 0.00200 -0.00200 0.00500<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea08 : -0.01290 0.01280 0.02920<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea09 : -0.01200 -0.01300 0.02400<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea15 : -0.00500 -0.01000 0.01100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea16 : 0.01100 -0.01500 -0.01200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea17 : -0.01300 0.00000 0.05000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea18 : -0.00600 0.02200 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea22 : 0.00600 0.00000 0.00000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea25 : -0.00140 0.00140 -0.00140<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea27 : -0.00400 -0.00500 0.03100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea28 : -0.02100 -0.02900 0.01900<br />
2017-07-25 19:54:52 INFO calibrater Beginning specifycal-----------------------<br />
2017-07-25 19:54:52 INFO Creating KAntPos Jones table from specified parameters.<br />
2017-07-25 19:54:52 WARN NB: This EVLA dataset appears to fall within the period<br />
2017-07-25 19:54:52 WARN + of semester 16B during which the online tropospheric<br />
2017-07-25 19:54:52 WARN + delay model was mis-applied.<br />
2017-07-25 19:54:52 WARN A correction for the online tropospheric delay model error WILL BE APPLIED!<br />
2017-07-25 19:54:52 WARN Marking antpos caltable to turn ON the trop delay correction.<br />
</pre></small><br />
<br />
Note that these observations were taken during a period in which the atmospheric delay terms were calculated incorrectly. In CASA versions 4.7.1 and up a [https://science.nrao.edu/facilities/vla/data-processing/vla-atmospheric-delay-problem correction] for this term is taken into account automatically when running CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>.<br />
<br />
=== Ionospheric calibration ===<br />
<br />
At frequencies below 5 GHz, ionospheric effects may need to be corrected. These corrections become important for frequencies < 1 GHz. CASA’s strategy is to obtain information on the total electron content (TEC) for the date of observations, which is based on data from the [https://science.nrao.edu/facilities/vlba/publications/memos/sci/gps_ion/node3 global navigation satellite system (GNSS)]. A series of CASA images in the form of a 24 hour movie of the TEC, as function of longitude and latitude, is then generated and stored as ''filename.IGS_TEC.im'', with a corresponding TEC error movie named ''filename.IGS_RMS_TEC.im'' (these movies can be viewed in CASA’s [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.viewer.html viewer] (please note that this task is deprecated, and in the future CARTA should be used for the visualizations). In order to download the data, you need to be connected to the internet:<br />
<br />
<source lang='python'><br />
# In CASA<br />
<br />
from casatasks.private import tec_maps<br />
<br />
tec_image, tec_rms_image, plotname = tec_maps.create(vis='MG0414_d1_data.ms', doplot=True)<br />
</source><br />
If, for any reason, the file cannot be retrieved from the server automatically, you can also download this specific TEC file for the tutorial [http://casa.nrao.edu/Data/EVLA/MG0414/igsg2580.16i here].<br />
<br />
<br />
The information regarding the TEC is sparse and either active or direction-dependent ionospheric conditions may not be corrected very well. Also, the online TEC information improves with time, hence the quality of these data is best about two weeks after the observations.<br />
<br />
[[File:Pband_TECIM.png|400px|thumb|right|Figure 3. Total Electron Content (TEC) as functions of time for the day and location of the observations. The time of the observing run is shown in red. We can also see this plot on the log scale, depending on the last plotants inputs.]]<br />
<br />
An ionosphere correction table is subsequently generated using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal], in which the projected line-of-sight TEC (which depends on the zenith angle) is sampled for all times in the observation and stored in a standard CASA caltable. Figure 3 shows a plot that is generated for this caltable and can be opened using [https://gitlab.com/DavidGriffith/xv xv].<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='tecim', caltable='tecim.cal',infile=tec_image)<br />
</source><br />
<br />
See the CASA Cookbook 4.7.2 for a [https://casa.nrao.edu/casa_cookbook.pdf#subsection.4.3.9 detailed description] on ionosphere corrections in CASA (thanks are due to Jason Kooi, University of Iowa, for his contributions).<br />
<br />
=== Calibration of requantizer gains ===<br />
<br />
Next we will calibrate the requantizer gain levels, which are the visibility amplitudes that were set as the input of the WIDAR correlator. Requantizer scans are added to a P-band observation to optimize the digital power in each spectral window which, in turn, maximizes the signal-to-noise of each window. Because there is a significant variation in power across the 240 MHz of P-band, and because some spectral windows may experience a high power due to strong RFI, setting the requantizer levels during the observations may improve the quality of the data, including the shape of the bandpass across multiple spectral windows. As part of the test observations of MG0414+0534, the very strong source Cygnus A was observed at the start of the run. Re-setting the requantizer levels both before observing Cygnus A and before targeting the other (much weaker) sources was essential to optimize the digital power and avoid correlation errors. Although we do not use Cygnus A as part of this tutorial, and we use only a single spectral window, performing calibration of the requantizer gains is still good practice for P-band spectral line reduction using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal].<br />
:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='rq', caltable='rq.cal')<br />
</source><br />
<br />
=== Initial absolute flux density scale calibration ===<br />
<br />
<br />
The next step is to set the absolute flux levels of our flux calibrator 3C48 (field='0' from our [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs] output), for which a well-known model exists using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.setjy.html setjy]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
setjy(vis='MG0414_d1_data.ms', field='0', scalebychan=True, standard='Perley-Butler 2017', listmodels=False, usescratch=True)<br />
</source><br />
<br />
It is crucial for spectral line work to set the parameter ''scalebychan=True'' to ensure that the absolute flux level is calculated per channel and correctly interpolated across the observing band. If ''scalebychan=False'', then only a single value per spectral window is calculated, resulting in a step function in flux between spectral windows.<br />
<br />
=== Delay calibration ===<br />
<br />
The delay of each antenna, for each polarization and each spectral window, is now determined. Doing this on a short scan of the primary calibrator is generally sufficient and will correct for both internal (e.g., electronics, cables) and external (e.g., ionosphere) effects. We select ea04 as reference antenna as it produced good data, has baselines to all other used antennas in the array, and is located in the center of the array. We also need to apply, "on-the-fly," the calibration tables for the antenna positions, the total electron content, and the requantizer levels using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]. <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
</source><br />
<br />
[[File:Pband_delaycal_5.4.0.png|500px|thumb|right|Figure 4. Delays for each antenna and each polarization. Plot made with CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms].]]<br />
The calibration solutions can be plotted using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 4):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='delays.cal',xaxis='antenna1',yaxis='delay',field='0',coloraxis='corr')<br />
</source><br />
<br />
<br />
Note that any delays deviating by more than 30 nsec should be treated with caution and, if needed, flagged.<br />
<br />
=== Bandpass calibration ===<br />
<br />
Next step is to calibrate the bandpass, which corrects for the frequency dependent gain variations. Before determining the frequency dependent gains, we first calibrate the phases in time, deriving a solution for each integration, to make sure that we can derive accurate bandpass solutions when integrating over a full scan on the bandpass calibrator 3C48. This is done using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
[[File:396px-Pband BPcal.png|1500px|thumb|right|Figure 5. Effects of bandpass calibration on the frequency dependent amplitudes (top) and phases (bottom) across the observing band. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8a below.) The various colors show the different baselines with reference antenna ea04. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing the option ''Data Column: data''.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
</source><br />
<br />
We use these phase solutions to perform the actual bandpass calibration. In this case, we have scans of our bandpass calibrator 3C48 taken at three different times during the observation. By interpolating the bandpass solutions in time, we try to minimize any possible time-varying bandpass effects and improve our spectral dynamic range. Bandpass calibration is performed in CASA by the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.bandpass.html bandpass]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
</source><br />
<br />
To interpolate between bandpass scans, it is essential to specify parameter <i>combine=' '</i>. The reason being that the default of <i>combine='scan'</i>, when coupled with the parameter <i>solint='inf'</i>, would cross the scan boundaries to form one single solution for the bandpass. Only when combining <i>solint='inf'</i> with <i>combine=' '</i> is a bandpass solution obtained for each individual scan on 3C48. The bandpass plots can be viewed using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 5).<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
=== Gain calibration ===<br />
<br />
After the bandpass calibration, we perform a phase calibration of our data. Because we apply the bandpass solutions "on-the-fly," we can use the full bandwidth to determine the phase solutions. We will create two different calibration tables to correct for the time-varying phases. First we calibrate the phases on each interval with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of ''solint'' set to ''int'': <br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
[[File:NewFig6_plot.png|500px|thumb|right|Figure 6. Effects of phase calibration. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8b below.) The various colors show the different baselines with reference antenna ea04.]]<br />
<br />
The sole purpose of generating phase solutions on each 10 second interval is to be able to accurately correct for the time-varying amplitudes as we will see below. This method, however, is not ideal for interpolating the phase solutions in time. For that we do a second phase calibration, this time averaging the signal across the phase calibrator scans with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of <i>solint='inf'</i>:<br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
Note that an alternative approach to deriving phase solutions per scan is to use the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.smoothcal.html smoothcal] to average the phase corrections obtained every 10s with <i>solin='int'</i> over the full duration of a single scan. Generate a phase plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] with the parameters below (see Figure 6):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',coloraxis='baseline')<br />
</source><br />
<br />
We have selected an arbitrarily high number for the average channel to ensure it will include all of them. It will led to a warning message on the terminal screen.<br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
[[File:NewFig7_plot.png|500px|thumb|right|Figure 7. Effects of amplitude and flux density scale calibration. The green points are the YY products on an offending antenna ea17, which we will flag in our target data. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 9 below.)]]<br />
<br />
<br />
We now perform a calibration of the amplitude variations in time. For this, we will apply the phase solution obtained in each 10 second interval via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]: <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
Normally this procedure will only calibrate the relative amplitudes, and the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.fluxscale.html fluxscale] is required to place the data on an absolute flux density scale. However, because our flux-calibrator is also our bandpass and gain calibrator, the absolute flux density scale will already be ok, so we can skip this step. Generate an amplitude gain plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 7) with the parameters below:<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',coloraxis='baseline')<br />
</source><br />
<br />
=== Applying the calibration ===<br />
<br />
We have now finished the calibration of the data. We will apply the calibration tables that were derived from 3C48 to both the calibrator 3C48 itself and our target MG0414+0354. The CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] creates a '''corrected''' data column where the calibrated data are stored.<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
Sometimes after calibrating the data it is easier to see any offending antennas or baselines. Replotting with <i>ydatacolumn='corrected'</i> will produce the corrected calibration plots (Figures 8a-d). <br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs frequency, Figures 8a and 8b<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs time, Figures 8c and 8d<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
<br />
The calibrated data of the primary calibrator 3C48 show that the YY amplitudes of ea17 are off during the second part of the run (see the green points with low values in figure 7). Because calibration solutions are antenna based, to get the best calibration, flag any poor data and re-run the calibration process. A currently known issue is that CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] will not find good solutions if any correlation, including cross-correlation, in the data is completely flagged. In this case, there is no difference between flagging only the YY polarization of ea17 or the entire antenna.<br />
Antenna ea17 will be flagged using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', antenna='ea17', action='apply')<br />
</source><br />
<br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white; vertical-align: top;"<br />
| style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_6.5.1.png|400px|thumb]] <br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 8a. Effects of bandpass calibration on the frequency dependent amplitudes across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8b. Effects of bandpass calibration on the frequency dependent phases across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8c. Effects of phase calibration on the time dependent amplitudes across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. || Figure 8d. Effects of phase calibration on the time dependent phases across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. <br />
|}<br />
<br />
<font size="+1">'''<br /><br /> '''</font> <br />
<br />
<font size="+1">'''Then run the calibration process again starting with the <i>Delay calibration</i>:'''</font> <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
[[File:Pband_ampcal_corrected_CASA5.5.0.png|thumb|500px|thumb|right|Figure 9. Effects of amplitude and flux density scale calibration. The green points (the YY products of antenna ea17 clearly seen in Figure 7) have been flagged. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected'']]<br />
<br />
<br />
<br />
The new calibration tables have overwritten the previous tables. Once you've re-run the calibration, you need to apply it. <br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<br />
And then, plot the corrected amplitudes vs time with ea17 flagged (see Figure 9):<br />
<br />
<source lang='python'><br />
# In CASA for corrected amp vs time with ea17 flagged, Figure 9<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
We now split the calibrated data of our target into a new measurement set, including only the XX and YY polarization products. Using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split] the calibrated target data are placed into the '''data''' column of the new measurement set:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_data.ms', outputvis='MG0414_d1_calibrated.ms', datacolumn='corrected', field='1', correlation='xx,yy', keepflags=False)<br />
</source><br />
<br />
== Imaging and Self-calibration ==<br />
<br />
We now have a calibrated data set that has all calibration applied except for possible self-calibration. Self-calibration relies on the target itself to better calibrate antenna-based gains (phases and amplitudes) as a function of time. It can be applied to targets that are strong in the continuum or have a strong enough spectral line to derive good phase and, if desired, also amplitude solutions on short (order of minutes) timescales. The procedure relies on an initial model of the target, which then can be used iteratively to improve the gains and hence the quality of the image itself. Here we show the various steps in self-calibrating our data based on the strong continuum emission of MG0414+0354. Please refer to a [https://casaguides.nrao.edu/index.php?title=First_Look_at_Self_Calibration_CASA_6 dedicated CASA guide] on self-calibration for further details.<br />
<br />
If strong RFI is present in the target, it may be necessary to flag your data before proceeding with self-calibration. This is not the case with MG0414+0354.<br />
<br />
We create an initial model of our target field using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. Notice that we will exclude from the continuum image the channels that we have flagged and the channels where we expected to detect the line:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_calibrated.ms', datacolumn='data', imagename='MG0414_d1_cont_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=100, threshold='1.5Jy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The information in the MODEL column consist of visibilities that present a model of the target field. CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] produces a ''.model'' image of the model that you can visualize with [https://cartavis.org/ CARTA] software. It is essential that only components that you know for sure represent the continuum in the target field are taken into account in self-calibration. If this is not the case, you probably cleaned too deep and included noise features or artifacts (e.g., from the beam-pattern) in the model. Self-calibration would permanently lock these as features in your data, so this should be avoided. On the other hand, it is equally crucial to ensure that the model is not empty, as this will result in your target being shifted to the phase center.<br />
<br />
You can see the tclean results using the CARTA tool, as we show in figure 10. Please refer to the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA documentation] on how to load the image into CARTA.<br />
<br />
[[File:CARTA-MG0414_d1_cont_R03-6.5.2.png|800px|thumb|right|Figure 10. Image obtained after the first run of tclean task (MG0414_d1_cont_R03.image), visualized with CARTA.]]<br />
<br />
Next, we derive phase corrections to this model. Because our target is strong enough to do self-calibration on it, we should get enough S/N per baseline on a 60 sec interval, using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_calibrated.ms', caltable='sc1.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='60s', combine='', minsnr=3.0)<br />
</source><br />
<br />
This creates a new phase-calibration table that we call ''sc1.gcal''. We now apply this calibration table to the calibrated data in order to improve the phase-only solutions using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_calibrated.ms', field='0', gaintable=['sc1.gcal'], interp='linear')<br />
</source><br />
<br />
Because self-calibration is an iterative process, we want to repeat this step again in order to further improve the gain calibration. For that, we first split the data calibrated with the self-calibration solutions applied to the DATA column to a new measurement set, again using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_calibrated.ms', outputvis='MG0414_d1_sc1.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
Now we can use this newly created measurement set to make a better continuum image and subsequently perform the next round of self-calibration:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc1.ms', datacolumn='data', imagename='MG0414_d1_cont_sc1.R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=500, threshold='500mJy', imsize=[256,256],cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc1.ms', caltable='sc2.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='30s', combine='', minsnr=3.0)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc1.ms', field='0', gaintable=['sc2.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc1.ms', outputvis='MG0414_d1_sc2.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc2.ms', datacolumn='data', imagename='MG0414_d1_cont_sc2_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
Now that we have a good model of the continuum in the field of MG0414+0354, we will attempt a final self-calibration using both the phases and amplitudes via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] :<br />
<br />
[[File:CARTA-MG0414_d1_cont_sc3ap_R03-6.5.2.png|800px|thumb|right|Figure 11. Image obtained after self-calibration. Compare with image shown in Figure 10.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc2.ms', caltable='sc3ap.gcal', field='0', spw='0', refant='ea04', calmode='ap', solint='30s', combine='', minsnr=3.0, solnorm=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc2.ms', field='0', gaintable=['sc3ap.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc2.ms', outputvis='MG0414_d1_sc3ap.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
[[File:MG0414_sc3ap_msview_6.5.2.png|right|thumb|800px|Figure 12. Display of time vs baseline for the MG0414+0354_d1_sc3ap.ms measurement set in [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview], with the animation axis set to 'channel'.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_cont_sc3ap_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The output continuum image from the last iteration of CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] continues to be an improvement over previous imaging, as you can see using [https://cartavis.org/ CARTA] again (Figure 11 showing results after three passes of self-calibration).<br />
<br />
<br />
However, now it also shows that we are not likely to gain further improvement with additional rounds of self-calibration (you can inspect this yourself by comparing the images created across the different iterations in [https://cartavis.org/ CARTA]). This indicates that we now have a calibrated data-set of MG0414+0354 that is almost ready for final imaging. Before imaging, we need to flag the target data to remove poor-quality data. First, we run an automated flagging routine using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] with the parameter <i>mode='rflag'</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='rflag', datacolumn='data')<br />
</source><br />
<br />
<br />
<br />
After having ran this automated flagging, we inspect the data via the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview] by displaying ''time'' vs ''channel'' for the different baselines, or you may display ''time'' vs ''baseline'' for the different channels:<br />
<br />
<source lang='python'><br />
# In CASA<br />
msview('MG0414_d1_sc3ap.ms') <br />
</source><br />
<br />
<br />
Keep in mind that when the data is properly calibrated, it is easier to recognize low-level imperfections which may have to be flagged to improve the image quality. In this case, the noisier baselines are seen with lighter colors (see Figure 12). Hovering over these baselines will report a number pair such as 8-16, 8-17, etc. in the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview]. From this we can tell that baselines 8-# and 12-# (which correspond to antennas ea09 and ea14) have significantly higher noise than the other antennas, something which was not picked up by the automated flagging routine. Additionally, for a number of baselines, the data quality looks relatively poor. We flag these antennas and baselines via the CASA [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] task before imaging the data.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea09', datacolumn='data')<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea14', datacolumn='data')<br />
</source><br />
<br />
To flag offending individual baselines, in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] you may use <i>antenna='antenna&antenna(&antenna...)'</i>. <br />
<br />
<br />
Flagging data can be an iterative process. Often, the better the data is calibrated, the easier it is to recognize low-level imperfections in it. To optimize the data reduction, you can script the calibration process, and opt to flag the data also in the original data set (i.e., before calibration), after which you run the entire calibration again.<br />
<br />
When you flag these antennas on the MS before the self calibration took place, you must go back and rerun the calibration before the final imaging, starting at the '''<i>Delay calibration</i>''' section. If you rerun the calibration you will either have to rename your measurement sets created from split during self calibration, or delete them in order to redo self calibration as split will not overwrite a ms name. <br />
<br />
We image the data using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. A 0.5Jy threshold was chosen for this command by interactively cleaning a single channel of the final self calibrated image and taking the 5σ of the noise levels once the image was cleaned. With an ideal threshold found, we can now clean all channels (this process can take hours to complete depending on the machine you are using):<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_line_sc3ap_vel_R03', spw='0', specmode='cube', outframe='bary', veltype='optical', restfreq='390.600MHz', niter=10000000, threshold='0.05Jy', imsize=[256,256], cell='1arcsec', pbcor=True, weighting='briggs', robust=0.2, perchanweightdensity=True, savemodel='none',interpolation='nearest')<br />
</source><br />
<br />
<br />
OBS: From CASA version 6.2.0 onwards, one new input parameter has been added to the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. The psfcutoff parameter allows fitting non-Gaussian PSF. The default value is 0.35, but can vary from 0.01 to 0.99. It is a parameter for advanced users, and it should rarely be changed. If a user needs to use it, the resulting fits should be carefully checked. We have used the default value in all [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] runs of this tutorial since we have not set it at any time.<br />
<br />
<br />
We can inspect the resulting line-data cube, again using [https://cartavis.org/ CARTA]. The HI absorption feature is clearly present (see Figure 14). If you did NOT re-run the calibration sequence, you should get a plot that should look similar to Figures 13 and 14. To see your spectral line, open the last image of the source. Go to a channel that shows the source, then zoom in on the source. Click the ''Point marking'' icon, find the brightest pixel in the source and click on it. Now click on the ''spectral profile tool'' button to get the single point profile of the spectrum. Here you will see a spectrum with 2 dips that drop to zero; these dips are a part of the flagging we have done. You will need to zoom in in order to notice any spectral lines due to the auto scaling; zoom in by clicking on the graph and creating a yellow box then release.<br />
<br />
The data cube contains both continuum and line emission, which can optionally be separated using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub]. In principle, this task can be used for continuum subtraction and fitting in the uv domain; however, combining spws for the continuum fitting is not yet supported in the updated [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub] in CASA 6.5.2, and for that particular functionality the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub_old.html uvcontsub_old] should be used for the time being.<br />
<br />
<br />
[[File:CARTA-cube-6.5.2.png|1250px|thumb|center|Figure 13. Test-data of the redshifted HI 21cm absorption line on top of the radio continuum in MG 0414+0354 (i.e., the continuum was not subtracted); see More, Carilli & Mention 1999 (Apj, 510, 87) for the original detection. It is the final cleaned image here displayed using CARTA. As can be read from the bottom right panel, shown is channel 115, at 388.07 MHz. The profiles on the right show a single point 1D spectrum on x and y axes.]]<br />
<br />
<br />
{{Checked 6.5.2}}<br />
<br />
<!-- NO LONGER RELEVANT, CARTA DOES EVERYTHING IN ONE, PREV. FIG. [[File:MG0414 d1 line sc3ap vel R03 recal 6.2.0.png|1100px|thumb|right|Figure 14. Left: The Single Point Spectral Profile with the auto scaling. Noticed the tip, make a tight horizontal yellow box around the main signal, like shown in figure. On right: The same after we zoom it.]]--><br />
<br />
<br />
<!--IMVIEW: Alternative Tip: You can click in the save icon (top left) in the Spectral Profile tool and export the spectral profile as a text file. And then, you can use any program you find appropriate to make the plot. You can see small differences in the continuum flux level, depending on the pixel you have selected to see the line profile. However, you should be able to identify the line in any of the bright central pixels.--><br />
<br />
<!-- --[[User:bemonts|Bjorn Emonts]] <br />
-- 5.0 corrections: [[User:kradford| Karlee Radford]] (2018-03-21)<br />
-- Edits [[User:tperreau| Tony Perreault]] (26 Apr 2018)<br />
-- Edits [[User:Hmedlin | Heidi Medlin]] (27 April 2018)<br />
-- Yet more edits [[User:tperreau| Tony Perreault]] (2 May 2018)<br />
-- And yet more edits [[User:tperreau| Tony Perreault]] (May the 4th be with you 2018)<br />
-- 5.4.0 updates: [User:kradford| Karlee Radford]] (2018-10-11)<br />
-- 5.5.0 updates: [User:asobotka| Alex Sobotka]] (3 July 2019)<br />
-- 5.7.0 updates: [User:pbeaklin| Pedro P.B. Beaklini]] (29 September 2020)<br />
-- Changed last figure: [User:pbeaklin| Pedro P.B. Beaklini]] (7 October 2020)<br />
-- 5.7.2 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Cheking tec_map (21 December 2020)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Added before and after selfcal figures (21 June 2021)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Changed task links, changed robust and added 'nearest' on last clean. (01 July 2021) <br />
-- 6.5.2 updates [User:akapinsk| Anna D Kapinska]]. Exchanged the ms.tgz file for download (error of unexpected EOF when unpacking), and exchanged some figures for clarity, plus some minor corrections. Removed imview, added CARTA. (13 Feb 2023)<br />
--></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=MG0414%2B0534_P-band_Spectral_Line_Tutorial_-_CASA_6.5.2&diff=34815MG0414+0534 P-band Spectral Line Tutorial - CASA 6.5.22023-02-13T19:41:07Z<p>Akapinsk: </p>
<hr />
<div><!--By Bjorn Emonts--><br />
<br />
<b>This CASA Guide is for Version 6.5.2 of CASA.</b> <br />
<br />
{| class="wikitable"<br />
|-<br />
| style="background: red; color: white;" | '''DISCLAIMER'''<br />
|-<br />
| The following guide is for users who are experts in data reduction using CASA. If you are a beginner or novice user, please review other CASA guides found at [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials VLA Tutorials]. <b> Note: This guide may take up to 2-days to complete </b><br />
|}<br />
<br />
== Overview ==<br />
<br />
This tutorial describes how to use CASA 6.5.2 to reduce spectral-line data in the low-frequency P-band of the VLA (230&ndash;470 MHz). The goal is to make an image cube containing HI 21cm absorption against the strong radio continuum of gravitationally lensed radio galaxy MG0414+0534. As a result of the high redshift of z=2.6365, the HI absorption signal in MG0414+0534 is redshifted to an observed frequency of 390.597 MHz. The HI absorption in MG0414+0534 was previously imaged with the VLA by Moore, Carilli & Menten 1999 ([http://iopscience.iop.org/article/10.1086/311818/meta ApJ, 510, 87]), before the upgrade to the WIDAR system.<br />
<br />
We would like to note that the CASAviewer (supporting tasks viewer, imview and msview) has not been maintained for a few years now and will be removed from future versions of CASA. The NRAO replacement visualization tool for images and cubes is CARTA, the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization.<br />
<br />
=== Observing strategy ===<br />
<br />
To perform P-band spectrsocopy, there are three important considerations for planning the observations:<br />
<br />
* Use a bandpass calibrator that is strong enough to accurately calibrate the frequency-dependent gain variations. This is particularly important for most HI 21cm absorption projects, which are typically performed against strong radio continuum sources. As a rule-of-thumb, use ''t''<sub>cal</sub> > ''t''<sub>obj</sub> × (''S''<sub>obj</sub> / ''S''<sub>cal</sub>)<sup>2</sup>, with ''t'' the exposure time and ''S'' the source flux density. This rule-of-thumb serves to avoid introducing excessive additional noise in the spectrum.<br />
<br />
* Additionally, if very high spectral dynamic range is needed (i.e., when expecting a ratio between the detection limit and the radio continuum of about 1:10,000 or more), consider observing a bandpass calibrator several times during your run to be able to correct for time-varying bandpass changes, which scale with the continuum emission in the target field. See the [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/calibration Calibration section] of the Guide to Observing with the VLA for more information.<br />
<br />
* Use a bandwidth that is wide enough to perform accurate self calibration. Using a wide bandwidth for self-calibration is important for fields with relatively weak continuum sources. For strong continuum sources, a narrower bandwidth can be used to avoid excessive RFI. <br />
<br />
The P-band test data on MG0414+0534 that we use in this tutorial were obtained using a large bandwidth. This is to ensure that good bandpass solutions can be procured, and that self-calibration can accurately be performed. However, due to the strong radio continuum of MG0414+0534 (3.3 Jy at 390 MHz), and the large amounts of RFI across the entire band, we only use a small fraction of the total band for data reduction and analysis in this tutorial.<br />
<br />
== Obtaining the data ==<br />
<br />
<font color=red>'''This 15 GB data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing). We are providing this starting data set, rather than the original data set for 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.We will use test data that was taken in a hybrid configuration when the VLA array was being moved from B-config to A-config. <br />
<br />
The entire data set can be downloaded from the [https://data.nrao.edu NRAO archive] by searching for the following Project Code: <br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001<br />
</pre><br />
</div><br />
<br />
This returns a long list with test-data that are publicly available. Our observations were performed on 14 Sept 2016:<br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001.sb32720781.eb32763188.57645.263958564814<br />
</pre><br />
</div><br />
<br />
Note that this observation was duplicated on 15 September 2016. <!-- This second day of observations can be found under filename:<br />
TSUB0001.sb32720781.eb32773507.57646.24443702547 --><br />
<br />
The 15 GB data set from the download has already had online flagging and Hanning smoothing applied, and the smaller data set split out from the larger data set. If you wish, you can download the SDM from the NRAO archive in order to apply the online flags and run Hanning smoothing on the large data set before splitting out the smaller data set to work on. To apply the on line flag use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd]; to apply the Hanning smoothing use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.hanningsmooth.html hanningsmooth] on scans 7 to 16 and field 3 and 4; and to split the data, use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]. For the purpose of this tutorial, we only reduce and image the first data set. Then, you will need to split only the spw 17, and only channels 20 to 485 to remove the borders. <br />
<br />
<!-- The second data set can be reduced in an identical way (pending the flagging, given that the RFI conditions most likely changed). During the imaging stage you can then combine both reduced data sets. --><br />
<br />
<!-- To download the data, fill in your email, select either the "SDM-BDF (all files)" or “MS” option, and check the box next to the data sets that you want. The practical difference between selecting the MeasurementSet (MS) and Science Data Model (SDM) is that for MS the first step in the data reduction described below, namely reading in the SDM data to save it as a MeasurementSet, is already done by the archival engine. Note that you can also opt to download the data as a tar-file by tickking the appropriate box.<br />
<br />
Optionally, you can request to discard data marked as ‘bad’ by ticking the box “Apply Telescope Flags”, which gets rid of data taken during times of instrument calibration, shadowing, slewing, etc. However, it also applies all flags on the science data that were automatically created during the observations. Therefore, a safer option is to not apply any flags before downloading the data, but first inspect and subsequently apply the flags generated during the observations using [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd], as part of the data reduction plan.<br />
<br />
Click "Get My Data" will forward you to the next page, where you should choose the delivery method (either downloading over the internet, or sending home a hard-drive with the data). If you opt to retrieve the data over the internet, wait until you get an email confirming that the data is ready for download. --><br />
<br />
== Examining the Data ==<br />
<br />
=== Loading data into CASA ===<br />
<br />
We will have to untar the 15 GB data set that you've downloaded.<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
tar -xzf MG0414_d1_data.ms.tgz<br />
</pre><br />
<br />
Please use CASA 6.5.2 for this tutorial (typing ''casa -ls'' in a linux window shows the available versions and the current version; to explicitly change the version type, e.g., ''casa -r 6.5.2-26-py3.6'')<br />
<br />
<source lang='bash'><br />
casa<br />
</source><br />
on the command line. This should start a CASA interactive python (iPython) session, and open a separate log window. To guarantee that the below mentioned procedure for data reduction and imaging works, make sure you are using CASA version 6.5.2. While older versions may work as well for the purpose of this tutorial, it is good to read instructions on how to [https://casa.nrao.edu/casa_obtaining.shtml download and install] the latest version of CASA.<br />
<!-- <br />
We will begin by importing our data from the binary format (SDM-BDF) into the MeasurementSet format, which is the standard for CASA data. For this, we use <i>importevla</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
importevla(asdm='TSUB0001.sb32720781.eb32763188.57645.263958564814', vis='MG0414_d1.ms', flagpol=False, applyflags=False, savecmds=True, outfile='flagfile.txt')<br />
</source><br />
<br />
<!-- In this case, we do not apply the flags that were created as part of the observations, but we will write them out to a <i>flagfile.txt</i> file. We will inspect and apply the flags as follows:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagcmd(vis='MG0414_d1.ms', action='plot')<br />
flagcmd(vis='MG0414_d1.ms', action='apply')<br />
</source><br />
<br />
As an alternative to <i>flagcmd</i>, given that we saved the flags to <i>flagfile.txt</i>, we can also use <br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='list', inpfile='flagfile.txt', action='apply')<br />
</source><br />
<br />
to apply the flags.<br />
<br />
One of the flag commands is to <i>clip</i> all data points that have a 0-value, as these most likely have not recorded any science data. This is normally done with the settings <i>correlation=`ABS_RR’</i> and <i>correlation=`ABS_LL’</i>. Because the VLA P-band and 4-band systems use linear XX and YY polarisation, rather than the circular RR and LL polarisation of the other VLA bands, you will encounter an error message when running <i>flagcmd</i>. We can get around this issue by manually clipping the 0-data for the XX and LL polarization with <i>flagdata</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='clip', correlation='ABS_XX,ABS_YY', clipzeros=True, action='apply')<br />
</source><br />
--><br />
<br />
It is a good practice to read the Operator Log that was created by the duty operator during the observations. This log can provide additional information on data that should be flagged manually during the data reduction stage. The Operator logs can be found at [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi Ops Logs form entry], and this is the [http://www.vla.nrao.edu/operators/logs/2016/9/2016-09-14_0620_TSUB0001.pdf direct link for the log of the observation] (in PDF format).<br />
<br />
=== Inspecting the observation info ===<br />
<br />
We will inspect the content of our data set using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs].<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms')<br />
</source><br />
<br />
The task plots an overview of the data in the CASA logger. Notice that the task returns a dictionary on the terminal screen. Using the parameter <i>listfile=`listobs.txt’</i>, this information is written out to the file <i>listobs.txt</i>: <br />
<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms', listfile='listobs.txt')<br />
</source><br />
<br />
The content is included below:<br />
<br />
<small style="font-size:80%;"><pre><br />
Observer: . Frazer Owen Project: uid://evla/pdb/1695465 <br />
Observation: EVLA<br />
Data records: 1179738 Total elapsed time = 9390 seconds<br />
Observed from 14-Sep-2016/06:43:48.0 to 14-Sep-2016/09:20:18.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
14-Sep-2016/06:43:48.0 - 06:48:42.0 7 0 3C48 37044 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
06:48:45.0 - 07:08:39.0 8 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:08:42.0 - 07:28:36.0 9 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:28:39.0 - 07:48:33.0 10 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:48:36.0 - 08:08:30.0 11 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:08:33.0 - 08:14:30.0 12 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
08:14:33.0 - 08:34:27.0 13 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:34:30.0 - 08:54:21.0 14 1 MG0414+0534 150066 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:54:24.0 - 09:14:18.0 15 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
09:14:21.0 - 09:20:18.0 16 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 NONE 3C48 01:37:41.299431 +33.09.35.13299 J2000 0 127008<br />
1 NONE MG0414+0534 04:14:37.800000 +05.34.41.99999 J2000 1 1052730<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 EVLA_P#A0C0#17 466 TOPO 386.312 15.625 7281.2 389.9453 12 XX XY YX YY<br />
Sources: 2<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C48 0 - - <br />
1 MG0414+0534 0 - - <br />
Antennas: 27:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 ea01 W24 25.0 m -107.38.49.0 +33.53.04.0 -2673.3457 -1784.6009 10.4844 -1604008.744400 -5042135.825100 3553403.710800<br />
1 ea02 W56 25.0 m -107.44.26.7 +33.49.54.6 -11333.1991 -7637.6832 15.3636 -1613255.391400 -5042613.097800 3548545.906000<br />
2 ea03 W40 25.0 m -107.41.13.5 +33.51.43.1 -6377.9680 -4286.7773 8.2312 -1607962.451800 -5042338.218100 3551324.962400<br />
3 ea04 E04 25.0 m -107.37.00.8 +33.53.59.7 102.7973 -63.7800 -2.6177 -1601068.806000 -5042051.932700 3554824.838800<br />
4 ea05 E36 25.0 m -107.33.20.2 +33.52.34.3 5761.3733 -2704.6731 33.0133 -1596127.730800 -5045193.742100 3552652.419700<br />
5 ea06 N24 25.0 m -107.37.16.1 +33.55.37.7 -290.3584 2961.8653 -12.2425 -1600930.069900 -5040316.395500 3557330.390000<br />
6 ea07 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8512 1426.6377 -9.3934 -1601061.954400 -5041175.875300 3556058.026700<br />
7 ea08 W64 25.0 m -107.46.20.1 +33.48.50.9 -14240.7524 -9606.2900 17.0885 -1616361.575500 -5042770.516600 3546911.419900<br />
8 ea09 N40 25.0 m -107.37.29.5 +33.57.44.4 -633.6056 6878.5897 -20.7984 -1600592.749000 -5038121.341300 3560574.826900<br />
9 ea10 E20 25.0 m -107.35.43.6 +33.53.29.9 2082.1759 -987.0087 9.4361 -1599340.800100 -5043150.963000 3554065.231500<br />
10 ea12 N32 25.0 m -107.37.22.0 +33.56.33.6 -441.7248 4689.9674 -16.9328 -1600781.044500 -5039347.439100 3558761.527100<br />
11 ea13 E28 25.0 m -107.34.39.3 +33.53.04.9 3732.7776 -1757.3308 21.4271 -1597899.895900 -5044068.684700 3553432.450200<br />
12 ea14 E08 25.0 m -107.36.48.9 +33.53.55.1 407.8283 -206.0315 -3.2236 -1600801.931400 -5042219.382600 3554706.429400<br />
13 ea15 N64 25.0 m -107.37.58.7 +34.02.20.5 -1382.3871 15410.1326 -40.6450 -1599855.687000 -5033332.368600 3567636.606800<br />
14 ea16 W72 25.0 m -107.48.24.0 +33.47.41.2 -17419.4641 -11760.2694 14.9442 -1619757.299900 -5042937.656400 3545120.392300<br />
15 ea17 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2042 12254.2800 -34.2710 -1600128.378100 -5035104.139200 3565024.633900<br />
16 ea18 W48 25.0 m -107.42.44.3 +33.50.52.1 -8707.9181 -5861.7682 15.5302 -1610451.901900 -5042471.123800 3550021.073100<br />
17 ea19 W16 25.0 m -107.37.57.4 +33.53.33.0 -1348.7121 -890.6209 1.2959 -1602592.853500 -5042054.992400 3554140.702800<br />
18 ea20 E16 25.0 m -107.36.09.8 +33.53.40.0 1410.0403 -673.4656 -0.7790 -1599926.104100 -5042772.977200 3554319.801100<br />
19 ea21 E24 25.0 m -107.35.13.4 +33.53.18.1 2858.1906 -1349.1352 13.7186 -1598663.082000 -5043581.391200 3553767.014100<br />
20 ea22 W32 25.0 m -107.39.54.8 +33.52.27.2 -4359.4399 -2923.1314 11.7614 -1605808.634100 -5042230.084000 3552459.197800<br />
21 ea23 E12 25.0 m -107.36.31.7 +33.53.48.5 848.6994 -411.6226 -2.7575 -1600416.518000 -5042462.430500 3554536.041700<br />
22 ea24 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1080 -272.1514 -1.5061 -1601614.083200 -5042001.656900 3554652.505900<br />
23 ea25 N08 25.0 m -107.37.07.5 +33.54.15.8 -68.9088 433.1829 -5.0674 -1601147.942500 -5041733.833600 3555235.947000<br />
24 ea26 E32 25.0 m -107.34.01.5 +33.52.50.3 4701.6503 -2209.7119 25.1976 -1597053.124400 -5044604.675000 3553058.992700<br />
25 ea27 N48 25.0 m -107.37.38.1 +33.59.06.2 -855.2719 9405.9407 -25.9485 -1600374.881000 -5036704.201700 3562667.858900<br />
26 ea28 N72 25.0 m -107.38.10.5 +34.04.12.2 -1685.6797 18861.8306 -43.5015 -1599557.928700 -5031396.353400 3570494.736800<br />
</pre></small><br />
<br />
<!-- === Hanning smoothing the data ===<br />
<br />
When plotting the data in plotms (plotting amplitude against frequency), it is immediately clear that our observing band contains lots of Radio Frequency Interference (RFI), which is unavoidable at these low frequencies. The situation actually looks worse than it is, because ‘Gibbs ringing’ causes the blending of strong RFI signal into adjacent channels (Fig.1). To reduce the effect of Gibbs ringing, we first Hanning smooth the data (please note that this can take a while to run on the entire 142 Gb data set):<br />
<br />
<source lang='python'><br />
# In CASA<br />
hanningsmooth(vis='MG0414_d1_data.ms', datacolumn='data', outputvis='MG0414_d1_hanning.ms')<br />
</source><br />
<br />
[[File:Pband_hanning.png|400px|thumb|right|Fig.1 Reducing the effects of Gibbs ringing by Hanning smoothing the data. Shown is only a small fraction of the band, both before and after Hanning smooth. The amplitude scale is the same in both plots.]]<br />
<br />
=== Splitting the data ===<br />
<br />
Upon further inspection in “plotms” (using ea01, field 0, corr xx,yy, and coloraxis baseline), it is clear that there is a lot of RFI across most of the 64 MHz (or 43,000 km/s) band that we used for the observations. Luckily, the region around the expected HI absorption line at 390.6 MHz is relatively clean of RFI. Because our target is strong enough in the continuum to perform a good self-calibration, we select this relatively clean part of the band centered around the expected HI line. Note that there were two IFs with different spectral resolution included in the observations. We need only one of the two IFs, and choose the one with the highest spectral resolution. Moreover, we only need the sources 3C48 (which we will use for bandpass, gain and flux calibration) and our target MG0414+0534, hence we select field=’3,4’. This approach has the additional advantage that we reduce our data volume a lot, bringing it down to about 15 Gb.<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_hanning.ms', outputvis='MG0414_d1_data.ms', datacolumn='data', field='3,4', spw='17:20~485', keepflags=False)<br />
</source><br />
<br />
<font color=red>'''This 15 Gb data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing), and the file can be unpacked by typing <i>tar xzf MG0414_d1_data.ms.tgz</i><br />
--><br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white;"<br />
| style="border: 1px solid darkgray;" | [[File:MG0414_plotants_5.4.0.png|350px|thumb]] || style="border: 1px solid darkgray" | [[File:Ant_logplot_6.5.2.png |350px|thumb]]<br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 1a. Plotants plot for <br />MG0414. || Figure 1b. Plotants plot <br />for MG0414 in a log scale.<br />
|}<br />
<br />
Next we look at a graphical plot of the antenna locations and save a hard copy<br />
in case you want it later using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.plotants.html plotant] (see Figures 1a and 1b). This will be useful for selecting a reference antenna. Note that the VLA was in a period of re-configuration when these MG0414 data were taken, so the antenna configuration is not a standard VLA configuration. Typically a good choice is an antenna close to the center of the array (see Figure 1b). Unless it shows problems after inspection of the data, we provisionally choose ea04. (Note: clicking on any image will open up a larger version.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='MG0414_d1_data.ms',figfile='ant_locations.png')<br />
<br />
# In CASA<br />
# If you would like to see another view of the antennas you may plot them on a log plot<br />
plotants(vis='MG0414_d1_data.ms',logpos=True,figfile='ant_logplot.png')<br />
<br />
</source><br />
<br />
=== Flagging ===<br />
<br />
<!-- NOTE: when revising for CASA release 5.3.0, EM wants to revisit how flagging is approached in the guide. Some of the flagging tasks, such as running rflag and flagging out antennas ea09, 14, and 17 should be introduced earlier - perhaps in this section - so that major flagging is done once and then the user can proceed to the self-calibration and imaging section. Tony --><br />
<br />
[[File:Pband_flagchan.png|760px|thumb|right|Figure 2. Flagging of calibrator 3C48. Shown are the XX and YY polarization on antenna ea01, both before (left) and after (right) flagging the bad channels. The colors represent the different baselines with ea01.]]<br />
<br />
We will now perform a more in-depth flagging of the bad data. Our strategy is to first focus on the calibrator source (in this case only 3C48). If the calibrator data are flagged well, we should be able to perform an accurate calibration of the target data. Later in this document we will then flag the calibrated target data using an automated flagger. <br />
<br />
When plotting amplitude vs frequency in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms], we see that there are still two ranges of channels filled with RFI throughout the observing run (see Figure 2). <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We will flag this data with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]. Because we are flagging channels on all scans of the bandpass calibrator 3C48, these channels cannot be calibrated accurately, so we flag these channels also in the data of the target.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:148~155', action='apply')<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:51~59', action='apply')<br />
</source><br />
<br />
The data on our bandpass+gain+flux calibrator 3C48 now look clean, with no dead or misbehaving antennas. We can repeat the same [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] call as above: <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We now start with the calibration.<br />
<br />
== Calibration ==<br />
<br />
Many of the steps below are based on the CASA tutorial on [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#3C129_P-band_continuum_imaging_data_reduction_tutorial reducing VLA P-band continuum data].<br />
<br />
=== <i>A priori</i> Antenna Position Corrections ===<br />
<br />
We start the calibration by obtaining the latest set of antenna-position corrections compared to the stored values that were derived at the start of the observing period. For this you need to run CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>. (Be sure to have internet connection in order to grab the antenna position corrections.)<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='antpos', caltable='antpos.cal')<br />
</source><br />
<br />
The output is a list of antenna position corrections that are written to the calibration table <i>antpos.cal</i>:<br />
<br />
<small style="font-size:85%;"><pre><br />
2017-07-25 19:54:51 INFO gencal Determine antenna position offests from the baseline correction database<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea01 : 0.00200 0.00000 0.00200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea02 : 0.00210 0.01800 0.00430<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea03 : -0.00700 0.01600 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea06 : 0.00200 -0.00200 0.00500<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea08 : -0.01290 0.01280 0.02920<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea09 : -0.01200 -0.01300 0.02400<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea15 : -0.00500 -0.01000 0.01100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea16 : 0.01100 -0.01500 -0.01200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea17 : -0.01300 0.00000 0.05000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea18 : -0.00600 0.02200 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea22 : 0.00600 0.00000 0.00000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea25 : -0.00140 0.00140 -0.00140<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea27 : -0.00400 -0.00500 0.03100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea28 : -0.02100 -0.02900 0.01900<br />
2017-07-25 19:54:52 INFO calibrater Beginning specifycal-----------------------<br />
2017-07-25 19:54:52 INFO Creating KAntPos Jones table from specified parameters.<br />
2017-07-25 19:54:52 WARN NB: This EVLA dataset appears to fall within the period<br />
2017-07-25 19:54:52 WARN + of semester 16B during which the online tropospheric<br />
2017-07-25 19:54:52 WARN + delay model was mis-applied.<br />
2017-07-25 19:54:52 WARN A correction for the online tropospheric delay model error WILL BE APPLIED!<br />
2017-07-25 19:54:52 WARN Marking antpos caltable to turn ON the trop delay correction.<br />
</pre></small><br />
<br />
Note that these observations were taken during a period in which the atmospheric delay terms were calculated incorrectly. In CASA versions 4.7.1 and up a [https://science.nrao.edu/facilities/vla/data-processing/vla-atmospheric-delay-problem correction] for this term is taken into account automatically when running CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>.<br />
<br />
=== Ionospheric calibration ===<br />
<br />
At frequencies below 5 GHz, ionospheric effects may need to be corrected. These corrections become important for frequencies < 1 GHz. CASA’s strategy is to obtain information on the total electron content (TEC) for the date of observations, which is based on data from the [https://science.nrao.edu/facilities/vlba/publications/memos/sci/gps_ion/node3 global navigation satellite system (GNSS)]. A series of CASA images in the form of a 24 hour movie of the TEC, as function of longitude and latitude, is then generated and stored as ''filename.IGS_TEC.im'', with a corresponding TEC error movie named ''filename.IGS_RMS_TEC.im'' (these movies can be viewed in CASA’s [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.viewer.html viewer] (please note that this task is deprecated, and in the future CARTA should be used for the visualizations). In order to download the data, you need to be connected to the internet:<br />
<br />
<source lang='python'><br />
# In CASA<br />
<br />
from casatasks.private import tec_maps<br />
<br />
tec_image, tec_rms_image, plotname = tec_maps.create(vis='MG0414_d1_data.ms', doplot=True)<br />
</source><br />
If, for any reason, the file cannot be retrieved from the server automatically, you can also download this specific TEC file for the tutorial [http://casa.nrao.edu/Data/EVLA/MG0414/igsg2580.16i here].<br />
<br />
<br />
The information regarding the TEC is sparse and either active or direction-dependent ionospheric conditions may not be corrected very well. Also, the online TEC information improves with time, hence the quality of these data is best about two weeks after the observations.<br />
<br />
[[File:Pband_TECIM.png|400px|thumb|right|Figure 3. Total Electron Content (TEC) as functions of time for the day and location of the observations. The time of the observing run is shown in red. We can also see this plot on the log scale, depending on the last plotants inputs.]]<br />
<br />
An ionosphere correction table is subsequently generated using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal], in which the projected line-of-sight TEC (which depends on the zenith angle) is sampled for all times in the observation and stored in a standard CASA caltable. Figure 3 shows a plot that is generated for this caltable and can be opened using [https://gitlab.com/DavidGriffith/xv xv].<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='tecim', caltable='tecim.cal',infile=tec_image)<br />
</source><br />
<br />
See the CASA Cookbook 4.7.2 for a [https://casa.nrao.edu/casa_cookbook.pdf#subsection.4.3.9 detailed description] on ionosphere corrections in CASA (thanks are due to Jason Kooi, University of Iowa, for his contributions).<br />
<br />
=== Calibration of requantizer gains ===<br />
<br />
Next we will calibrate the requantizer gain levels, which are the visibility amplitudes that were set as the input of the WIDAR correlator. Requantizer scans are added to a P-band observation to optimize the digital power in each spectral window which, in turn, maximizes the signal-to-noise of each window. Because there is a significant variation in power across the 240 MHz of P-band, and because some spectral windows may experience a high power due to strong RFI, setting the requantizer levels during the observations may improve the quality of the data, including the shape of the bandpass across multiple spectral windows. As part of the test observations of MG0414+0534, the very strong source Cygnus A was observed at the start of the run. Re-setting the requantizer levels both before observing Cygnus A and before targeting the other (much weaker) sources was essential to optimize the digital power and avoid correlation errors. Although we do not use Cygnus A as part of this tutorial, and we use only a single spectral window, performing calibration of the requantizer gains is still good practice for P-band spectral line reduction using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal].<br />
:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='rq', caltable='rq.cal')<br />
</source><br />
<br />
=== Initial absolute flux density scale calibration ===<br />
<br />
<br />
The next step is to set the absolute flux levels of our flux calibrator 3C48 (field='0' from our [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs] output), for which a well-known model exists using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.setjy.html setjy]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
setjy(vis='MG0414_d1_data.ms', field='0', scalebychan=True, standard='Perley-Butler 2017', listmodels=False, usescratch=False)<br />
</source><br />
<br />
It is crucial for spectral line work to set the parameter ''scalebychan=True'' to ensure that the absolute flux level is calculated per channel and correctly interpolated across the observing band. If ''scalebychan=False'', then only a single value per spectral window is calculated, resulting in a step function in flux between spectral windows.<br />
<br />
=== Delay calibration ===<br />
<br />
The delay of each antenna, for each polarization and each spectral window, is now determined. Doing this on a short scan of the primary calibrator is generally sufficient and will correct for both internal (e.g., electronics, cables) and external (e.g., ionosphere) effects. We select ea04 as reference antenna as it produced good data, has baselines to all other used antennas in the array, and is located in the center of the array. We also need to apply, "on-the-fly," the calibration tables for the antenna positions, the total electron content, and the requantizer levels using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]. <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
</source><br />
<br />
[[File:Pband_delaycal_5.4.0.png|500px|thumb|right|Figure 4. Delays for each antenna and each polarization. Plot made with CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms].]]<br />
The calibration solutions can be plotted using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 4):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='delays.cal',xaxis='antenna1',yaxis='delay',field='0',coloraxis='corr')<br />
</source><br />
<br />
<br />
Note that any delays deviating by more than 30 nsec should be treated with caution and, if needed, flagged.<br />
<br />
=== Bandpass calibration ===<br />
<br />
Next step is to calibrate the bandpass, which corrects for the frequency dependent gain variations. Before determining the frequency dependent gains, we first calibrate the phases in time, deriving a solution for each integration, to make sure that we can derive accurate bandpass solutions when integrating over a full scan on the bandpass calibrator 3C48. This is done using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
[[File:396px-Pband BPcal.png|1500px|thumb|right|Figure 5. Effects of bandpass calibration on the frequency dependent amplitudes (top) and phases (bottom) across the observing band. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8a below.) The various colors show the different baselines with reference antenna ea04. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing the option ''Data Column: data''.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
</source><br />
<br />
We use these phase solutions to perform the actual bandpass calibration. In this case, we have scans of our bandpass calibrator 3C48 taken at three different times during the observation. By interpolating the bandpass solutions in time, we try to minimize any possible time-varying bandpass effects and improve our spectral dynamic range. Bandpass calibration is performed in CASA by the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.bandpass.html bandpass]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
</source><br />
<br />
To interpolate between bandpass scans, it is essential to specify parameter <i>combine=' '</i>. The reason being that the default of <i>combine='scan'</i>, when coupled with the parameter <i>solint='inf'</i>, would cross the scan boundaries to form one single solution for the bandpass. Only when combining <i>solint='inf'</i> with <i>combine=' '</i> is a bandpass solution obtained for each individual scan on 3C48. The bandpass plots can be viewed using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 5).<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
=== Gain calibration ===<br />
<br />
After the bandpass calibration, we perform a phase calibration of our data. Because we apply the bandpass solutions "on-the-fly," we can use the full bandwidth to determine the phase solutions. We will create two different calibration tables to correct for the time-varying phases. First we calibrate the phases on each interval with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of ''solint'' set to ''int'': <br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
[[File:NewFig6_plot.png|500px|thumb|right|Figure 6. Effects of phase calibration. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8b below.) The various colors show the different baselines with reference antenna ea04.]]<br />
<br />
The sole purpose of generating phase solutions on each 10 second interval is to be able to accurately correct for the time-varying amplitudes as we will see below. This method, however, is not ideal for interpolating the phase solutions in time. For that we do a second phase calibration, this time averaging the signal across the phase calibrator scans with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of <i>solint='inf'</i>:<br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
Note that an alternative approach to deriving phase solutions per scan is to use the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.smoothcal.html smoothcal] to average the phase corrections obtained every 10s with <i>solin='int'</i> over the full duration of a single scan. Generate a phase plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] with the parameters below (see Figure 6):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',coloraxis='baseline')<br />
</source><br />
<br />
We have selected an arbitrarily high number for the average channel to ensure it will include all of them. It will led to a warning message on the terminal screen.<br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
[[File:NewFig7_plot.png|500px|thumb|right|Figure 7. Effects of amplitude and flux density scale calibration. The green points are the YY products on an offending antenna ea17, which we will flag in our target data. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 9 below.)]]<br />
<br />
<br />
We now perform a calibration of the amplitude variations in time. For this, we will apply the phase solution obtained in each 10 second interval via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]: <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
Normally this procedure will only calibrate the relative amplitudes, and the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.fluxscale.html fluxscale] is required to place the data on an absolute flux density scale. However, because our flux-calibrator is also our bandpass and gain calibrator, the absolute flux density scale will already be ok, so we can skip this step. Generate an amplitude gain plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 7) with the parameters below:<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',coloraxis='baseline')<br />
</source><br />
<br />
=== Applying the calibration ===<br />
<br />
We have now finished the calibration of the data. We will apply the calibration tables that were derived from 3C48 to both the calibrator 3C48 itself and our target MG0414+0354. The CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] creates a '''corrected''' data column where the calibrated data are stored.<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
Sometimes after calibrating the data it is easier to see any offending antennas or baselines. Replotting with <i>ydatacolumn='corrected'</i> will produce the corrected calibration plots (Figures 8a-d). <br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs frequency, Figures 8a and 8b<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs time, Figures 8c and 8d<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
<br />
The calibrated data of the primary calibrator 3C48 show that the YY amplitudes of ea17 are off during the second part of the run (see the green points with low values in figure 7). Because calibration solutions are antenna based, to get the best calibration, flag any poor data and re-run the calibration process. A currently known issue is that CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] will not find good solutions if any correlation, including cross-correlation, in the data is completely flagged. In this case, there is no difference between flagging only the YY polarization of ea17 or the entire antenna.<br />
Antenna ea17 will be flagged using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', antenna='ea17', action='apply')<br />
</source><br />
<br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white; vertical-align: top;"<br />
| style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_6.5.1.png|400px|thumb]] <br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 8a. Effects of bandpass calibration on the frequency dependent amplitudes across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8b. Effects of bandpass calibration on the frequency dependent phases across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8c. Effects of phase calibration on the time dependent amplitudes across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. || Figure 8d. Effects of phase calibration on the time dependent phases across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. <br />
|}<br />
<br />
<font size="+1">'''<br /><br /> '''</font> <br />
<br />
<font size="+1">'''Then run the calibration process again starting with the <i>Delay calibration</i>:'''</font> <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
[[File:Pband_ampcal_corrected_CASA5.5.0.png|thumb|500px|thumb|right|Figure 9. Effects of amplitude and flux density scale calibration. The green points (the YY products of antenna ea17 clearly seen in Figure 7) have been flagged. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected'']]<br />
<br />
<br />
<br />
The new calibration tables have overwritten the previous tables. Once you've re-run the calibration, you need to apply it. <br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<br />
And then, plot the corrected amplitudes vs time with ea17 flagged (see Figure 9):<br />
<br />
<source lang='python'><br />
# In CASA for corrected amp vs time with ea17 flagged, Figure 9<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
We now split the calibrated data of our target into a new measurement set, including only the XX and YY polarization products. Using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split] the calibrated target data are placed into the '''data''' column of the new measurement set:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_data.ms', outputvis='MG0414_d1_calibrated.ms', datacolumn='corrected', field='1', correlation='xx,yy', keepflags=False)<br />
</source><br />
<br />
== Imaging and Self-calibration ==<br />
<br />
We now have a calibrated data set that has all calibration applied except for possible self-calibration. Self-calibration relies on the target itself to better calibrate antenna-based gains (phases and amplitudes) as a function of time. It can be applied to targets that are strong in the continuum or have a strong enough spectral line to derive good phase and, if desired, also amplitude solutions on short (order of minutes) timescales. The procedure relies on an initial model of the target, which then can be used iteratively to improve the gains and hence the quality of the image itself. Here we show the various steps in self-calibrating our data based on the strong continuum emission of MG0414+0354. Please refer to a [https://casaguides.nrao.edu/index.php?title=First_Look_at_Self_Calibration_CASA_6 dedicated CASA guide] on self-calibration for further details.<br />
<br />
If strong RFI is present in the target, it may be necessary to flag your data before proceeding with self-calibration. This is not the case with MG0414+0354.<br />
<br />
We create an initial model of our target field using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. Notice that we will exclude from the continuum image the channels that we have flagged and the channels where we expected to detect the line:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_calibrated.ms', datacolumn='data', imagename='MG0414_d1_cont_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=100, threshold='1.5Jy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The information in the MODEL column consist of visibilities that present a model of the target field. CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] produces a ''.model'' image of the model that you can visualize with [https://cartavis.org/ CARTA] software. It is essential that only components that you know for sure represent the continuum in the target field are taken into account in self-calibration. If this is not the case, you probably cleaned too deep and included noise features or artifacts (e.g., from the beam-pattern) in the model. Self-calibration would permanently lock these as features in your data, so this should be avoided. On the other hand, it is equally crucial to ensure that the model is not empty, as this will result in your target being shifted to the phase center.<br />
<br />
You can see the tclean results using the CARTA tool, as we show in figure 10. Please refer to the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA documentation] on how to load the image into CARTA.<br />
<br />
[[File:CARTA-MG0414_d1_cont_R03-6.5.2.png|800px|thumb|right|Figure 10. Image obtained after the first run of tclean task (MG0414_d1_cont_R03.image), visualized with CARTA.]]<br />
<br />
Next, we derive phase corrections to this model. Because our target is strong enough to do self-calibration on it, we should get enough S/N per baseline on a 60 sec interval, using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_calibrated.ms', caltable='sc1.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='60s', combine='', minsnr=3.0)<br />
</source><br />
<br />
This creates a new phase-calibration table that we call ''sc1.gcal''. We now apply this calibration table to the calibrated data in order to improve the phase-only solutions using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_calibrated.ms', field='0', gaintable=['sc1.gcal'], interp='linear')<br />
</source><br />
<br />
Because self-calibration is an iterative process, we want to repeat this step again in order to further improve the gain calibration. For that, we first split the data calibrated with the self-calibration solutions applied to the DATA column to a new measurement set, again using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_calibrated.ms', outputvis='MG0414_d1_sc1.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
Now we can use this newly created measurement set to make a better continuum image and subsequently perform the next round of self-calibration:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc1.ms', datacolumn='data', imagename='MG0414_d1_cont_sc1.R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=500, threshold='500mJy', imsize=[256,256],cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc1.ms', caltable='sc2.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='30s', combine='', minsnr=3.0)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc1.ms', field='0', gaintable=['sc2.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc1.ms', outputvis='MG0414_d1_sc2.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc2.ms', datacolumn='data', imagename='MG0414_d1_cont_sc2_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
Now that we have a good model of the continuum in the field of MG0414+0354, we will attempt a final self-calibration using both the phases and amplitudes via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] :<br />
<br />
[[File:CARTA-MG0414_d1_cont_sc3ap_R03-6.5.2.png|800px|thumb|right|Figure 11. Image obtained after self-calibration. Compare with image shown in Figure 10.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc2.ms', caltable='sc3ap.gcal', field='0', spw='0', refant='ea04', calmode='ap', solint='30s', combine='', minsnr=3.0, solnorm=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc2.ms', field='0', gaintable=['sc3ap.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc2.ms', outputvis='MG0414_d1_sc3ap.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
[[File:MG0414_sc3ap_msview_6.5.2.png|right|thumb|800px|Figure 12. Display of time vs baseline for the MG0414+0354_d1_sc3ap.ms measurement set in [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview], with the animation axis set to 'channel'.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_cont_sc3ap_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The output continuum image from the last iteration of CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] continues to be an improvement over previous imaging, as you can see using [https://cartavis.org/ CARTA] again (Figure 11 showing results after three passes of self-calibration).<br />
<br />
<br />
However, now it also shows that we are not likely to gain further improvement with additional rounds of self-calibration (you can inspect this yourself by comparing the images created across the different iterations in [https://cartavis.org/ CARTA]). This indicates that we now have a calibrated data-set of MG0414+0354 that is almost ready for final imaging. Before imaging, we need to flag the target data to remove poor-quality data. First, we run an automated flagging routine using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] with the parameter <i>mode='rflag'</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='rflag', datacolumn='data')<br />
</source><br />
<br />
<br />
<br />
After having ran this automated flagging, we inspect the data via the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview] by displaying ''time'' vs ''channel'' for the different baselines, or you may display ''time'' vs ''baseline'' for the different channels:<br />
<br />
<source lang='python'><br />
# In CASA<br />
msview('MG0414_d1_sc3ap.ms') <br />
</source><br />
<br />
<br />
Keep in mind that when the data is properly calibrated, it is easier to recognize low-level imperfections which may have to be flagged to improve the image quality. In this case, the noisier baselines are seen with lighter colors (see Figure 12). Hovering over these baselines will report a number pair such as 8-16, 8-17, etc. in the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview]. From this we can tell that baselines 8-# and 12-# (which correspond to antennas ea09 and ea14) have significantly higher noise than the other antennas, something which was not picked up by the automated flagging routine. Additionally, for a number of baselines, the data quality looks relatively poor. We flag these antennas and baselines via the CASA [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] task before imaging the data.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea09', datacolumn='data')<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea14', datacolumn='data')<br />
</source><br />
<br />
To flag offending individual baselines, in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] you may use <i>antenna='antenna&antenna(&antenna...)'</i>. <br />
<br />
<br />
Flagging data can be an iterative process. Often, the better the data is calibrated, the easier it is to recognize low-level imperfections in it. To optimize the data reduction, you can script the calibration process, and opt to flag the data also in the original data set (i.e., before calibration), after which you run the entire calibration again.<br />
<br />
When you flag these antennas on the MS before the self calibration took place, you must go back and rerun the calibration before the final imaging, starting at the '''<i>Delay calibration</i>''' section. If you rerun the calibration you will either have to rename your measurement sets created from split during self calibration, or delete them in order to redo self calibration as split will not overwrite a ms name. <br />
<br />
We image the data using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. A 0.5Jy threshold was chosen for this command by interactively cleaning a single channel of the final self calibrated image and taking the 5σ of the noise levels once the image was cleaned. With an ideal threshold found, we can now clean all channels (this process can take hours to complete depending on the machine you are using):<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_line_sc3ap_vel_R03', spw='0', specmode='cube', outframe='bary', veltype='optical', restfreq='390.600MHz', niter=10000000, threshold='0.05Jy', imsize=[256,256], cell='1arcsec', pbcor=True, weighting='briggs', robust=0.2, perchanweightdensity=True, savemodel='none',interpolation='nearest')<br />
</source><br />
<br />
<br />
OBS: From CASA version 6.2.0 onwards, one new input parameter has been added to the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. The psfcutoff parameter allows fitting non-Gaussian PSF. The default value is 0.35, but can vary from 0.01 to 0.99. It is a parameter for advanced users, and it should rarely be changed. If a user needs to use it, the resulting fits should be carefully checked. We have used the default value in all [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] runs of this tutorial since we have not set it at any time.<br />
<br />
<br />
We can inspect the resulting line-data cube, again using [https://cartavis.org/ CARTA]. The HI absorption feature is clearly present (see Figure 14). If you did NOT re-run the calibration sequence, you should get a plot that should look similar to Figures 13 and 14. To see your spectral line, open the last image of the source. Go to a channel that shows the source, then zoom in on the source. Click the ''Point marking'' icon, find the brightest pixel in the source and click on it. Now click on the ''spectral profile tool'' button to get the single point profile of the spectrum. Here you will see a spectrum with 2 dips that drop to zero; these dips are a part of the flagging we have done. You will need to zoom in in order to notice any spectral lines due to the auto scaling; zoom in by clicking on the graph and creating a yellow box then release.<br />
<br />
The data cube contains both continuum and line emission, which can optionally be separated using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub]. In principle, this task can be used for continuum subtraction and fitting in the uv domain; however, combining spws for the continuum fitting is not yet supported in the updated [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub] in CASA 6.5.2, and for that particular functionality the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub_old.html uvcontsub_old] should be used for the time being.<br />
<br />
<br />
[[File:CARTA-cube-6.5.2.png|1250px|thumb|center|Figure 13. Test-data of the redshifted HI 21cm absorption line on top of the radio continuum in MG 0414+0354 (i.e., the continuum was not subtracted); see More, Carilli & Mention 1999 (Apj, 510, 87) for the original detection. It is the final cleaned image here displayed using CARTA. As can be read from the bottom right panel, shown is channel 115, at 388.07 MHz. The profiles on the right show a single point 1D spectrum on x and y axes.]]<br />
<br />
<br />
{{Checked 6.5.2}}<br />
<br />
<!-- NO LONGER RELEVANT, CARTA DOES EVERYTHING IN ONE, PREV. FIG. [[File:MG0414 d1 line sc3ap vel R03 recal 6.2.0.png|1100px|thumb|right|Figure 14. Left: The Single Point Spectral Profile with the auto scaling. Noticed the tip, make a tight horizontal yellow box around the main signal, like shown in figure. On right: The same after we zoom it.]]--><br />
<br />
<br />
<!--IMVIEW: Alternative Tip: You can click in the save icon (top left) in the Spectral Profile tool and export the spectral profile as a text file. And then, you can use any program you find appropriate to make the plot. You can see small differences in the continuum flux level, depending on the pixel you have selected to see the line profile. However, you should be able to identify the line in any of the bright central pixels.--><br />
<br />
<!-- --[[User:bemonts|Bjorn Emonts]] <br />
-- 5.0 corrections: [[User:kradford| Karlee Radford]] (2018-03-21)<br />
-- Edits [[User:tperreau| Tony Perreault]] (26 Apr 2018)<br />
-- Edits [[User:Hmedlin | Heidi Medlin]] (27 April 2018)<br />
-- Yet more edits [[User:tperreau| Tony Perreault]] (2 May 2018)<br />
-- And yet more edits [[User:tperreau| Tony Perreault]] (May the 4th be with you 2018)<br />
-- 5.4.0 updates: [User:kradford| Karlee Radford]] (2018-10-11)<br />
-- 5.5.0 updates: [User:asobotka| Alex Sobotka]] (3 July 2019)<br />
-- 5.7.0 updates: [User:pbeaklin| Pedro P.B. Beaklini]] (29 September 2020)<br />
-- Changed last figure: [User:pbeaklin| Pedro P.B. Beaklini]] (7 October 2020)<br />
-- 5.7.2 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Cheking tec_map (21 December 2020)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Added before and after selfcal figures (21 June 2021)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Changed task links, changed robust and added 'nearest' on last clean. (01 July 2021) <br />
-- 6.5.2 updates [User:akapinsk| Anna D Kapinska]]. Exchanged the ms.tgz file for download (error of unexpected EOF when unpacking), and exchanged some figures for clarity, plus some minor corrections. Removed imview, added CARTA. (13 Feb 2023)<br />
--></div>Akapinskhttps://casaguides.nrao.edu/index.php?title=MG0414%2B0534_P-band_Spectral_Line_Tutorial_-_CASA_6.5.2&diff=34786MG0414+0534 P-band Spectral Line Tutorial - CASA 6.5.22023-02-13T10:19:50Z<p>Akapinsk: /* Imaging and Self-calibration */</p>
<hr />
<div><!--By Bjorn Emonts--><br />
<br />
<b>This CASA Guide is for Version 6.5.2 of CASA.</b> <br />
<br />
{| class="wikitable"<br />
|-<br />
| style="background: red; color: white;" | '''DISCLAIMER'''<br />
|-<br />
| The following guide is for users who are experts in data reduction using CASA. If you are a beginner or novice user, please review other CASA guides found at [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials VLA Tutorials]. <b> Note: This guide may take up to 2-days to complete </b><br />
|}<br />
<br />
== Overview ==<br />
<br />
This tutorial describes how to use CASA 6.5.2 to reduce spectral-line data in the low-frequency P-band of the VLA (230&ndash;470 MHz). The goal is to make an image cube containing HI 21cm absorption against the strong radio continuum of gravitationally lensed radio galaxy MG0414+0534. As a result of the high redshift of z=2.6365, the HI absorption signal in MG0414+0534 is redshifted to an observed frequency of 390.597 MHz. The HI absorption in MG0414+0534 was previously imaged with the VLA by Moore, Carilli & Menten 1999 ([http://iopscience.iop.org/article/10.1086/311818/meta ApJ, 510, 87]), before the upgrade to the WIDAR system.<br />
<br />
We would like to note that the CASAviewer (supporting tasks viewer, imview and msview) has not been maintained for a few years now and will be removed from future versions of CASA. The NRAO replacement visualization tool for images and cubes is CARTA, the “Cube Analysis and Rendering Tool for Astronomy”. It is available from the [https://cartavis.org/ CARTA website]. We strongly recommend to use CARTA, as it provides a much more efficient, stable, and feature rich user experience. A comparison of the CASAviewer and CARTA, as well as instructions on how to use CARTA at NRAO is provided in the respective section of the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA docs]. This tutorial shows Figures generated with CARTA for visualization.<br />
<br />
=== Observing strategy ===<br />
<br />
To perform P-band spectrsocopy, there are three important considerations for planning the observations:<br />
<br />
* Use a bandpass calibrator that is strong enough to accurately calibrate the frequency-dependent gain variations. This is particularly important for most HI 21cm absorption projects, which are typically performed against strong radio continuum sources. As a rule-of-thumb, use ''t''<sub>cal</sub> > ''t''<sub>obj</sub> × (''S''<sub>obj</sub> / ''S''<sub>cal</sub>)<sup>2</sup>, with ''t'' the exposure time and ''S'' the source flux density. This rule-of-thumb serves to avoid introducing excessive additional noise in the spectrum.<br />
<br />
* Additionally, if very high spectral dynamic range is needed (i.e., when expecting a ratio between the detection limit and the radio continuum of about 1:10,000 or more), consider observing a bandpass calibrator several times during your run to be able to correct for time-varying bandpass changes, which scale with the continuum emission in the target field. See the [https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/calibration Calibration section] of the Guide to Observing with the VLA for more information.<br />
<br />
* Use a bandwidth that is wide enough to perform accurate self calibration. Using a wide bandwidth for self-calibration is important for fields with relatively weak continuum sources. For strong continuum sources, a narrower bandwidth can be used to avoid excessive RFI. <br />
<br />
The P-band test data on MG0414+0534 that we use in this tutorial were obtained using a large bandwidth. This is to ensure that good bandpass solutions can be procured, and that self-calibration can accurately be performed. However, due to the strong radio continuum of MG0414+0534 (3.3 Jy at 390 MHz), and the large amounts of RFI across the entire band, we only use a small fraction of the total band for data reduction and analysis in this tutorial.<br />
<br />
== Obtaining the data ==<br />
<br />
<font color=red>'''This 15 GB data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing). We are providing this starting data set, rather than the original data set for 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.We will use test data that was taken in a hybrid configuration when the VLA array was being moved from B-config to A-config. <br />
<br />
The entire data set can be downloaded from the [https://data.nrao.edu NRAO archive] by searching for the following Project Code: <br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001<br />
</pre><br />
</div><br />
<br />
This returns a long list with test-data that are publicly available. Our observations were performed on 14 Sept 2016:<br />
<br />
<div style="text-align:justify;"><br />
<pre style="background-color: #gray;"><br />
TSUB0001.sb32720781.eb32763188.57645.263958564814<br />
</pre><br />
</div><br />
<br />
Note that this observation was duplicated on 15 September 2016. <!-- This second day of observations can be found under filename:<br />
TSUB0001.sb32720781.eb32773507.57646.24443702547 --><br />
<br />
The 15 GB data set from the download has already had online flagging and Hanning smoothing applied, and the smaller data set split out from the larger data set. If you wish, you can download the SDM from the NRAO archive in order to apply the online flags and run Hanning smoothing on the large data set before splitting out the smaller data set to work on. To apply the on line flag use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd]; to apply the Hanning smoothing use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.hanningsmooth.html hanningsmooth] on scans 7 to 16 and field 3 and 4; and to split the data, use the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]. For the purpose of this tutorial, we only reduce and image the first data set. Then, you will need to split only the spw 17, and only channels 20 to 485 to remove the borders. <br />
<br />
<!-- The second data set can be reduced in an identical way (pending the flagging, given that the RFI conditions most likely changed). During the imaging stage you can then combine both reduced data sets. --><br />
<br />
<!-- To download the data, fill in your email, select either the "SDM-BDF (all files)" or “MS” option, and check the box next to the data sets that you want. The practical difference between selecting the MeasurementSet (MS) and Science Data Model (SDM) is that for MS the first step in the data reduction described below, namely reading in the SDM data to save it as a MeasurementSet, is already done by the archival engine. Note that you can also opt to download the data as a tar-file by tickking the appropriate box.<br />
<br />
Optionally, you can request to discard data marked as ‘bad’ by ticking the box “Apply Telescope Flags”, which gets rid of data taken during times of instrument calibration, shadowing, slewing, etc. However, it also applies all flags on the science data that were automatically created during the observations. Therefore, a safer option is to not apply any flags before downloading the data, but first inspect and subsequently apply the flags generated during the observations using [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagcmd.html flagcmd], as part of the data reduction plan.<br />
<br />
Click "Get My Data" will forward you to the next page, where you should choose the delivery method (either downloading over the internet, or sending home a hard-drive with the data). If you opt to retrieve the data over the internet, wait until you get an email confirming that the data is ready for download. --><br />
<br />
== Examining the Data ==<br />
<br />
=== Loading data into CASA ===<br />
<br />
We will have to untar the 15 GB data set that you've downloaded.<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
tar -xzf MG0414_d1_data.ms.tgz<br />
</pre><br />
<br />
Please use CASA 6.5.2 for this tutorial (typing ''casa -ls'' in a linux window shows the available versions and the current version; to explicitly change the version type, e.g., ''casa -r 6.5.2-26-py3.6'')<br />
<br />
<source lang='bash'><br />
casa<br />
</source><br />
on the command line. This should start a CASA interactive python (iPython) session, and open a separate log window. To guarantee that the below mentioned procedure for data reduction and imaging works, make sure you are using CASA version 6.5.2. While older versions may work as well for the purpose of this tutorial, it is good to read instructions on how to [https://casa.nrao.edu/casa_obtaining.shtml download and install] the latest version of CASA.<br />
<!-- <br />
We will begin by importing our data from the binary format (SDM-BDF) into the MeasurementSet format, which is the standard for CASA data. For this, we use <i>importevla</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
importevla(asdm='TSUB0001.sb32720781.eb32763188.57645.263958564814', vis='MG0414_d1.ms', flagpol=False, applyflags=False, savecmds=True, outfile='flagfile.txt')<br />
</source><br />
<br />
<!-- In this case, we do not apply the flags that were created as part of the observations, but we will write them out to a <i>flagfile.txt</i> file. We will inspect and apply the flags as follows:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagcmd(vis='MG0414_d1.ms', action='plot')<br />
flagcmd(vis='MG0414_d1.ms', action='apply')<br />
</source><br />
<br />
As an alternative to <i>flagcmd</i>, given that we saved the flags to <i>flagfile.txt</i>, we can also use <br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='list', inpfile='flagfile.txt', action='apply')<br />
</source><br />
<br />
to apply the flags.<br />
<br />
One of the flag commands is to <i>clip</i> all data points that have a 0-value, as these most likely have not recorded any science data. This is normally done with the settings <i>correlation=`ABS_RR’</i> and <i>correlation=`ABS_LL’</i>. Because the VLA P-band and 4-band systems use linear XX and YY polarisation, rather than the circular RR and LL polarisation of the other VLA bands, you will encounter an error message when running <i>flagcmd</i>. We can get around this issue by manually clipping the 0-data for the XX and LL polarization with <i>flagdata</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1.ms', mode='clip', correlation='ABS_XX,ABS_YY', clipzeros=True, action='apply')<br />
</source><br />
--><br />
<br />
It is a good practice to read the Operator Log that was created by the duty operator during the observations. This log can provide additional information on data that should be flagged manually during the data reduction stage. The Operator logs can be found at [http://www.vla.nrao.edu/cgi-bin/oplogs.cgi Ops Logs form entry], and this is the [http://www.vla.nrao.edu/operators/logs/2016/9/2016-09-14_0620_TSUB0001.pdf direct link for the log of the observation] (in PDF format).<br />
<br />
=== Inspecting the observation info ===<br />
<br />
We will inspect the content of our data set using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs].<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms')<br />
</source><br />
<br />
The task plots an overview of the data in the CASA logger. Notice that the task returns a dictionary on the terminal screen. Using the parameter <i>listfile=`listobs.txt’</i>, this information is written out to the file <i>listobs.txt</i>: <br />
<br />
<source lang='python'><br />
# In CASA<br />
listobs(vis='MG0414_d1_data.ms', listfile='listobs.txt')<br />
</source><br />
<br />
The content is included below:<br />
<br />
<small style="font-size:80%;"><pre><br />
Observer: . Frazer Owen Project: uid://evla/pdb/1695465 <br />
Observation: EVLA<br />
Data records: 1179738 Total elapsed time = 9390 seconds<br />
Observed from 14-Sep-2016/06:43:48.0 to 14-Sep-2016/09:20:18.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
14-Sep-2016/06:43:48.0 - 06:48:42.0 7 0 3C48 37044 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
06:48:45.0 - 07:08:39.0 8 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:08:42.0 - 07:28:36.0 9 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:28:39.0 - 07:48:33.0 10 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
07:48:36.0 - 08:08:30.0 11 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:08:33.0 - 08:14:30.0 12 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
08:14:33.0 - 08:34:27.0 13 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:34:30.0 - 08:54:21.0 14 1 MG0414+0534 150066 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
08:54:24.0 - 09:14:18.0 15 1 MG0414+0534 150444 [0] [3] [OBSERVE_TARGET#UNSPECIFIED]<br />
09:14:21.0 - 09:20:18.0 16 0 3C48 44982 [0] [3] [CALIBRATE_AMPLI#UNSPECIFIED,CALIBRATE_BANDPASS#UNSPECIFIED,CALIBRATE_FLUX#UNSPECIFIED,CALIBRATE_PHASE#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 NONE 3C48 01:37:41.299431 +33.09.35.13299 J2000 0 127008<br />
1 NONE MG0414+0534 04:14:37.800000 +05.34.41.99999 J2000 1 1052730<br />
Spectral Windows: (1 unique spectral windows and 1 unique polarization setups)<br />
SpwID Name #Chans Frame Ch0(MHz) ChanWid(kHz) TotBW(kHz) CtrFreq(MHz) BBC Num Corrs <br />
0 EVLA_P#A0C0#17 466 TOPO 386.312 15.625 7281.2 389.9453 12 XX XY YX YY<br />
Sources: 2<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C48 0 - - <br />
1 MG0414+0534 0 - - <br />
Antennas: 27:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
0 ea01 W24 25.0 m -107.38.49.0 +33.53.04.0 -2673.3457 -1784.6009 10.4844 -1604008.744400 -5042135.825100 3553403.710800<br />
1 ea02 W56 25.0 m -107.44.26.7 +33.49.54.6 -11333.1991 -7637.6832 15.3636 -1613255.391400 -5042613.097800 3548545.906000<br />
2 ea03 W40 25.0 m -107.41.13.5 +33.51.43.1 -6377.9680 -4286.7773 8.2312 -1607962.451800 -5042338.218100 3551324.962400<br />
3 ea04 E04 25.0 m -107.37.00.8 +33.53.59.7 102.7973 -63.7800 -2.6177 -1601068.806000 -5042051.932700 3554824.838800<br />
4 ea05 E36 25.0 m -107.33.20.2 +33.52.34.3 5761.3733 -2704.6731 33.0133 -1596127.730800 -5045193.742100 3552652.419700<br />
5 ea06 N24 25.0 m -107.37.16.1 +33.55.37.7 -290.3584 2961.8653 -12.2425 -1600930.069900 -5040316.395500 3557330.390000<br />
6 ea07 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8512 1426.6377 -9.3934 -1601061.954400 -5041175.875300 3556058.026700<br />
7 ea08 W64 25.0 m -107.46.20.1 +33.48.50.9 -14240.7524 -9606.2900 17.0885 -1616361.575500 -5042770.516600 3546911.419900<br />
8 ea09 N40 25.0 m -107.37.29.5 +33.57.44.4 -633.6056 6878.5897 -20.7984 -1600592.749000 -5038121.341300 3560574.826900<br />
9 ea10 E20 25.0 m -107.35.43.6 +33.53.29.9 2082.1759 -987.0087 9.4361 -1599340.800100 -5043150.963000 3554065.231500<br />
10 ea12 N32 25.0 m -107.37.22.0 +33.56.33.6 -441.7248 4689.9674 -16.9328 -1600781.044500 -5039347.439100 3558761.527100<br />
11 ea13 E28 25.0 m -107.34.39.3 +33.53.04.9 3732.7776 -1757.3308 21.4271 -1597899.895900 -5044068.684700 3553432.450200<br />
12 ea14 E08 25.0 m -107.36.48.9 +33.53.55.1 407.8283 -206.0315 -3.2236 -1600801.931400 -5042219.382600 3554706.429400<br />
13 ea15 N64 25.0 m -107.37.58.7 +34.02.20.5 -1382.3871 15410.1326 -40.6450 -1599855.687000 -5033332.368600 3567636.606800<br />
14 ea16 W72 25.0 m -107.48.24.0 +33.47.41.2 -17419.4641 -11760.2694 14.9442 -1619757.299900 -5042937.656400 3545120.392300<br />
15 ea17 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2042 12254.2800 -34.2710 -1600128.378100 -5035104.139200 3565024.633900<br />
16 ea18 W48 25.0 m -107.42.44.3 +33.50.52.1 -8707.9181 -5861.7682 15.5302 -1610451.901900 -5042471.123800 3550021.073100<br />
17 ea19 W16 25.0 m -107.37.57.4 +33.53.33.0 -1348.7121 -890.6209 1.2959 -1602592.853500 -5042054.992400 3554140.702800<br />
18 ea20 E16 25.0 m -107.36.09.8 +33.53.40.0 1410.0403 -673.4656 -0.7790 -1599926.104100 -5042772.977200 3554319.801100<br />
19 ea21 E24 25.0 m -107.35.13.4 +33.53.18.1 2858.1906 -1349.1352 13.7186 -1598663.082000 -5043581.391200 3553767.014100<br />
20 ea22 W32 25.0 m -107.39.54.8 +33.52.27.2 -4359.4399 -2923.1314 11.7614 -1605808.634100 -5042230.084000 3552459.197800<br />
21 ea23 E12 25.0 m -107.36.31.7 +33.53.48.5 848.6994 -411.6226 -2.7575 -1600416.518000 -5042462.430500 3554536.041700<br />
22 ea24 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1080 -272.1514 -1.5061 -1601614.083200 -5042001.656900 3554652.505900<br />
23 ea25 N08 25.0 m -107.37.07.5 +33.54.15.8 -68.9088 433.1829 -5.0674 -1601147.942500 -5041733.833600 3555235.947000<br />
24 ea26 E32 25.0 m -107.34.01.5 +33.52.50.3 4701.6503 -2209.7119 25.1976 -1597053.124400 -5044604.675000 3553058.992700<br />
25 ea27 N48 25.0 m -107.37.38.1 +33.59.06.2 -855.2719 9405.9407 -25.9485 -1600374.881000 -5036704.201700 3562667.858900<br />
26 ea28 N72 25.0 m -107.38.10.5 +34.04.12.2 -1685.6797 18861.8306 -43.5015 -1599557.928700 -5031396.353400 3570494.736800<br />
</pre></small><br />
<br />
<!-- === Hanning smoothing the data ===<br />
<br />
When plotting the data in plotms (plotting amplitude against frequency), it is immediately clear that our observing band contains lots of Radio Frequency Interference (RFI), which is unavoidable at these low frequencies. The situation actually looks worse than it is, because ‘Gibbs ringing’ causes the blending of strong RFI signal into adjacent channels (Fig.1). To reduce the effect of Gibbs ringing, we first Hanning smooth the data (please note that this can take a while to run on the entire 142 Gb data set):<br />
<br />
<source lang='python'><br />
# In CASA<br />
hanningsmooth(vis='MG0414_d1_data.ms', datacolumn='data', outputvis='MG0414_d1_hanning.ms')<br />
</source><br />
<br />
[[File:Pband_hanning.png|400px|thumb|right|Fig.1 Reducing the effects of Gibbs ringing by Hanning smoothing the data. Shown is only a small fraction of the band, both before and after Hanning smooth. The amplitude scale is the same in both plots.]]<br />
<br />
=== Splitting the data ===<br />
<br />
Upon further inspection in “plotms” (using ea01, field 0, corr xx,yy, and coloraxis baseline), it is clear that there is a lot of RFI across most of the 64 MHz (or 43,000 km/s) band that we used for the observations. Luckily, the region around the expected HI absorption line at 390.6 MHz is relatively clean of RFI. Because our target is strong enough in the continuum to perform a good self-calibration, we select this relatively clean part of the band centered around the expected HI line. Note that there were two IFs with different spectral resolution included in the observations. We need only one of the two IFs, and choose the one with the highest spectral resolution. Moreover, we only need the sources 3C48 (which we will use for bandpass, gain and flux calibration) and our target MG0414+0534, hence we select field=’3,4’. This approach has the additional advantage that we reduce our data volume a lot, bringing it down to about 15 Gb.<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_hanning.ms', outputvis='MG0414_d1_data.ms', datacolumn='data', field='3,4', spw='17:20~485', keepflags=False)<br />
</source><br />
<br />
<font color=red>'''This 15 Gb data set can be downloaded by clicking [https://casa.nrao.edu/Data/EVLA/MG0414/MG0414_d1_data.ms.tgz here].'''</font> The filename should be MG0414_d1_data.ms.tgz (add the ".tgz" if this is missing), and the file can be unpacked by typing <i>tar xzf MG0414_d1_data.ms.tgz</i><br />
--><br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white;"<br />
| style="border: 1px solid darkgray;" | [[File:MG0414_plotants_5.4.0.png|350px|thumb]] || style="border: 1px solid darkgray" | [[File:Ant_logplot_6.5.2.png |350px|thumb]]<br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 1a. Plotants plot for <br />MG0414. || Figure 1b. Plotants plot <br />for MG0414 in a log scale.<br />
|}<br />
<br />
Next we look at a graphical plot of the antenna locations and save a hard copy<br />
in case you want it later using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.plotants.html plotant] (see Figures 1a and 1b). This will be useful for selecting a reference antenna. Note that the VLA was in a period of re-configuration when these MG0414 data were taken, so the antenna configuration is not a standard VLA configuration. Typically a good choice is an antenna close to the center of the array (see Figure 1b). Unless it shows problems after inspection of the data, we provisionally choose ea04. (Note: clicking on any image will open up a larger version.)<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotants(vis='MG0414_d1_data.ms',figfile='ant_locations.png')<br />
<br />
# In CASA<br />
# If you would like to see another view of the antennas you may plot them on a log plot<br />
plotants(vis='MG0414_d1_data.ms',logpos=True,figfile='ant_logplot.png')<br />
<br />
</source><br />
<br />
=== Flagging ===<br />
<br />
<!-- NOTE: when revising for CASA release 5.3.0, EM wants to revisit how flagging is approached in the guide. Some of the flagging tasks, such as running rflag and flagging out antennas ea09, 14, and 17 should be introduced earlier - perhaps in this section - so that major flagging is done once and then the user can proceed to the self-calibration and imaging section. Tony --><br />
<br />
[[File:Pband_flagchan.png|760px|thumb|right|Figure 2. Flagging of calibrator 3C48. Shown are the XX and YY polarization on antenna ea01, both before (left) and after (right) flagging the bad channels. The colors represent the different baselines with ea01.]]<br />
<br />
We will now perform a more in-depth flagging of the bad data. Our strategy is to first focus on the calibrator source (in this case only 3C48). If the calibrator data are flagged well, we should be able to perform an accurate calibration of the target data. Later in this document we will then flag the calibrated target data using an automated flagger. <br />
<br />
When plotting amplitude vs frequency in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms], we see that there are still two ranges of channels filled with RFI throughout the observing run (see Figure 2). <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We will flag this data with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]. Because we are flagging channels on all scans of the bandpass calibrator 3C48, these channels cannot be calibrated accurately, so we flag these channels also in the data of the target.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:148~155', action='apply')<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', spw='0:51~59', action='apply')<br />
</source><br />
<br />
The data on our bandpass+gain+flux calibrator 3C48 now look clean, with no dead or misbehaving antennas. We can repeat the same [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] call as above: <br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',antenna='ea01',xaxis='chan',yaxis='amp',correlation='xx,yy',coloraxis='baseline', scan='7',averagedata=True, avgtime='1e9')<br />
</source><br />
<br />
We now start with the calibration.<br />
<br />
== Calibration ==<br />
<br />
Many of the steps below are based on the CASA tutorial on [https://casaguides.nrao.edu/index.php/Karl_G._Jansky_VLA_Tutorials#3C129_P-band_continuum_imaging_data_reduction_tutorial reducing VLA P-band continuum data].<br />
<br />
=== <i>A priori</i> Antenna Position Corrections ===<br />
<br />
We start the calibration by obtaining the latest set of antenna-position corrections compared to the stored values that were derived at the start of the observing period. For this you need to run CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>. (Be sure to have internet connection in order to grab the antenna position corrections.)<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='antpos', caltable='antpos.cal')<br />
</source><br />
<br />
The output is a list of antenna position corrections that are written to the calibration table <i>antpos.cal</i>:<br />
<br />
<small style="font-size:85%;"><pre><br />
2017-07-25 19:54:51 INFO gencal Determine antenna position offests from the baseline correction database<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea01 : 0.00200 0.00000 0.00200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea02 : 0.00210 0.01800 0.00430<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea03 : -0.00700 0.01600 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea06 : 0.00200 -0.00200 0.00500<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea08 : -0.01290 0.01280 0.02920<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea09 : -0.01200 -0.01300 0.02400<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea15 : -0.00500 -0.01000 0.01100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea16 : 0.01100 -0.01500 -0.01200<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea17 : -0.01300 0.00000 0.05000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea18 : -0.00600 0.02200 -0.02000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea22 : 0.00600 0.00000 0.00000<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea25 : -0.00140 0.00140 -0.00140<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea27 : -0.00400 -0.00500 0.03100<br />
2017-07-25 19:54:52 INFO gencal offsets for antenna ea28 : -0.02100 -0.02900 0.01900<br />
2017-07-25 19:54:52 INFO calibrater Beginning specifycal-----------------------<br />
2017-07-25 19:54:52 INFO Creating KAntPos Jones table from specified parameters.<br />
2017-07-25 19:54:52 WARN NB: This EVLA dataset appears to fall within the period<br />
2017-07-25 19:54:52 WARN + of semester 16B during which the online tropospheric<br />
2017-07-25 19:54:52 WARN + delay model was mis-applied.<br />
2017-07-25 19:54:52 WARN A correction for the online tropospheric delay model error WILL BE APPLIED!<br />
2017-07-25 19:54:52 WARN Marking antpos caltable to turn ON the trop delay correction.<br />
</pre></small><br />
<br />
Note that these observations were taken during a period in which the atmospheric delay terms were calculated incorrectly. In CASA versions 4.7.1 and up a [https://science.nrao.edu/facilities/vla/data-processing/vla-atmospheric-delay-problem correction] for this term is taken into account automatically when running CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal] with parameter <i>caltype='antpos'</i>.<br />
<br />
=== Ionospheric calibration ===<br />
<br />
At frequencies below 5 GHz, ionospheric effects may need to be corrected. These corrections become important for frequencies < 1 GHz. CASA’s strategy is to obtain information on the total electron content (TEC) for the date of observations, which is based on data from the [https://science.nrao.edu/facilities/vlba/publications/memos/sci/gps_ion/node3 global navigation satellite system (GNSS)]. A series of CASA images in the form of a 24 hour movie of the TEC, as function of longitude and latitude, is then generated and stored as ''filename.IGS_TEC.im'', with a corresponding TEC error movie named ''filename.IGS_RMS_TEC.im'' (these movies can be viewed in CASA’s [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.viewer.html viewer] (please note that this task is deprecated, and in the future CARTA should be used for the visualizations). In order to download the data, you need to be connected to the internet:<br />
<br />
<source lang='python'><br />
# In CASA<br />
<br />
from casatasks.private import tec_maps<br />
<br />
tec_image, tec_rms_image, plotname = tec_maps.create(vis='MG0414_d1_data.ms', doplot=True)<br />
</source><br />
If, for any reason, the file cannot be retrieved from the server automatically, you can also download this specific TEC file for the tutorial [http://casa.nrao.edu/Data/EVLA/MG0414/igsg2580.16i here].<br />
<br />
<br />
The information regarding the TEC is sparse and either active or direction-dependent ionospheric conditions may not be corrected very well. Also, the online TEC information improves with time, hence the quality of these data is best about two weeks after the observations.<br />
<br />
[[File:Pband_TECIM.png|400px|thumb|right|Figure 3. Total Electron Content (TEC) as functions of time for the day and location of the observations. The time of the observing run is shown in red. We can also see this plot on the log scale, depending on the last plotants inputs.]]<br />
<br />
An ionosphere correction table is subsequently generated using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal], in which the projected line-of-sight TEC (which depends on the zenith angle) is sampled for all times in the observation and stored in a standard CASA caltable. Figure 3 shows a plot that is generated for this caltable and can be opened using [https://gitlab.com/DavidGriffith/xv xv].<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='tecim', caltable='tecim.cal',infile=tec_image)<br />
</source><br />
<br />
See the CASA Cookbook 4.7.2 for a [https://casa.nrao.edu/casa_cookbook.pdf#subsection.4.3.9 detailed description] on ionosphere corrections in CASA (thanks are due to Jason Kooi, University of Iowa, for his contributions).<br />
<br />
=== Calibration of requantizer gains ===<br />
<br />
Next we will calibrate the requantizer gain levels, which are the visibility amplitudes that were set as the input of the WIDAR correlator. Requantizer scans are added to a P-band observation to optimize the digital power in each spectral window which, in turn, maximizes the signal-to-noise of each window. Because there is a significant variation in power across the 240 MHz of P-band, and because some spectral windows may experience a high power due to strong RFI, setting the requantizer levels during the observations may improve the quality of the data, including the shape of the bandpass across multiple spectral windows. As part of the test observations of MG0414+0534, the very strong source Cygnus A was observed at the start of the run. Re-setting the requantizer levels both before observing Cygnus A and before targeting the other (much weaker) sources was essential to optimize the digital power and avoid correlation errors. Although we do not use Cygnus A as part of this tutorial, and we use only a single spectral window, performing calibration of the requantizer gains is still good practice for P-band spectral line reduction using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gencal.html gencal].<br />
:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gencal(vis='MG0414_d1_data.ms', caltype='rq', caltable='rq.cal')<br />
</source><br />
<br />
=== Initial absolute flux density scale calibration ===<br />
<br />
<br />
The next step is to set the absolute flux levels of our flux calibrator 3C48 (field='0' from our [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.information.listobs.html listobs] output), for which a well-known model exists using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.setjy.html setjy]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
setjy(vis='MG0414_d1_data.ms', field='0', scalebychan=True, standard='Perley-Butler 2017', listmodels=False, usescratch=False)<br />
</source><br />
<br />
It is crucial for spectral line work to set the parameter ''scalebychan=True'' to ensure that the absolute flux level is calculated per channel and correctly interpolated across the observing band. If ''scalebychan=False'', then only a single value per spectral window is calculated, resulting in a step function in flux between spectral windows.<br />
<br />
=== Delay calibration ===<br />
<br />
The delay of each antenna, for each polarization and each spectral window, is now determined. Doing this on a short scan of the primary calibrator is generally sufficient and will correct for both internal (e.g., electronics, cables) and external (e.g., ionosphere) effects. We select ea04 as reference antenna as it produced good data, has baselines to all other used antennas in the array, and is located in the center of the array. We also need to apply, "on-the-fly," the calibration tables for the antenna positions, the total electron content, and the requantizer levels using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]. <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
</source><br />
<br />
[[File:Pband_delaycal_5.4.0.png|500px|thumb|right|Figure 4. Delays for each antenna and each polarization. Plot made with CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms].]]<br />
The calibration solutions can be plotted using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 4):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='delays.cal',xaxis='antenna1',yaxis='delay',field='0',coloraxis='corr')<br />
</source><br />
<br />
<br />
Note that any delays deviating by more than 30 nsec should be treated with caution and, if needed, flagged.<br />
<br />
=== Bandpass calibration ===<br />
<br />
Next step is to calibrate the bandpass, which corrects for the frequency dependent gain variations. Before determining the frequency dependent gains, we first calibrate the phases in time, deriving a solution for each integration, to make sure that we can derive accurate bandpass solutions when integrating over a full scan on the bandpass calibrator 3C48. This is done using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
[[File:396px-Pband BPcal.png|1500px|thumb|right|Figure 5. Effects of bandpass calibration on the frequency dependent amplitudes (top) and phases (bottom) across the observing band. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8a below.) The various colors show the different baselines with reference antenna ea04. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing the option ''Data Column: data''.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
</source><br />
<br />
We use these phase solutions to perform the actual bandpass calibration. In this case, we have scans of our bandpass calibrator 3C48 taken at three different times during the observation. By interpolating the bandpass solutions in time, we try to minimize any possible time-varying bandpass effects and improve our spectral dynamic range. Bandpass calibration is performed in CASA by the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.bandpass.html bandpass]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
</source><br />
<br />
To interpolate between bandpass scans, it is essential to specify parameter <i>combine=' '</i>. The reason being that the default of <i>combine='scan'</i>, when coupled with the parameter <i>solint='inf'</i>, would cross the scan boundaries to form one single solution for the bandpass. Only when combining <i>solint='inf'</i> with <i>combine=' '</i> is a bandpass solution obtained for each individual scan on 3C48. The bandpass plots can be viewed using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 5).<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
=== Gain calibration ===<br />
<br />
After the bandpass calibration, we perform a phase calibration of our data. Because we apply the bandpass solutions "on-the-fly," we can use the full bandwidth to determine the phase solutions. We will create two different calibration tables to correct for the time-varying phases. First we calibrate the phases on each interval with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of ''solint'' set to ''int'': <br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
[[File:NewFig6_plot.png|500px|thumb|right|Figure 6. Effects of phase calibration. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 8b below.) The various colors show the different baselines with reference antenna ea04.]]<br />
<br />
The sole purpose of generating phase solutions on each 10 second interval is to be able to accurately correct for the time-varying amplitudes as we will see below. This method, however, is not ideal for interpolating the phase solutions in time. For that we do a second phase calibration, this time averaging the signal across the phase calibrator scans with the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] parameter of <i>solint='inf'</i>:<br />
<br />
<source lang='python'><br />
# In CASA <br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
</source><br />
<br />
Note that an alternative approach to deriving phase solutions per scan is to use the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.smoothcal.html smoothcal] to average the phase corrections obtained every 10s with <i>solin='int'</i> over the full duration of a single scan. Generate a phase plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] with the parameters below (see Figure 6):<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',coloraxis='baseline')<br />
</source><br />
<br />
We have selected an arbitrarily high number for the average channel to ensure it will include all of them. It will led to a warning message on the terminal screen.<br />
<br />
=== Scaling the Amplitude Gains ===<br />
<br />
[[File:NewFig7_plot.png|500px|thumb|right|Figure 7. Effects of amplitude and flux density scale calibration. The green points are the YY products on an offending antenna ea17, which we will flag in our target data. (For corrections applied using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] see Figure 9 below.)]]<br />
<br />
<br />
We now perform a calibration of the amplitude variations in time. For this, we will apply the phase solution obtained in each 10 second interval via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]: <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
Normally this procedure will only calibrate the relative amplitudes, and the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.fluxscale.html fluxscale] is required to place the data on an absolute flux density scale. However, because our flux-calibrator is also our bandpass and gain calibrator, the absolute flux density scale will already be ok, so we can skip this step. Generate an amplitude gain plot using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] (see Figure 7) with the parameters below:<br />
<br />
<source lang='python'><br />
# In CASA<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',coloraxis='baseline')<br />
</source><br />
<br />
=== Applying the calibration ===<br />
<br />
We have now finished the calibration of the data. We will apply the calibration tables that were derived from 3C48 to both the calibrator 3C48 itself and our target MG0414+0354. The CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal] creates a '''corrected''' data column where the calibrated data are stored.<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
Sometimes after calibrating the data it is easier to see any offending antennas or baselines. Replotting with <i>ydatacolumn='corrected'</i> will produce the corrected calibration plots (Figures 8a-d). <br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs frequency, Figures 8a and 8b<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='amp',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', xaxis='frequency',yaxis='phase',scan='7',ydatacolumn='corrected',correlation='xx,yy', coloraxis='baseline')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA for corrected amplitude and phase vs time, Figures 8c and 8d<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='phase',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
<br />
The calibrated data of the primary calibrator 3C48 show that the YY amplitudes of ea17 are off during the second part of the run (see the green points with low values in figure 7). Because calibration solutions are antenna based, to get the best calibration, flag any poor data and re-run the calibration process. A currently known issue is that CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] will not find good solutions if any correlation, including cross-correlation, in the data is completely flagged. In this case, there is no difference between flagging only the YY polarization of ea17 or the entire antenna.<br />
Antenna ea17 will be flagged using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_data.ms', mode='manual', antenna='ea17', action='apply')<br />
</source><br />
<br />
<br />
{| style="border-spacing: 2px; border: 1px solid darkgray; float:right;"<br />
|- style="background: white; vertical-align: top;"<br />
| style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_scan7_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_amp_6.5.2.png|400px|thumb]] || style="border: 1px solid darkgray;" | [[File:Pband_BPcal_corr_phase_6.5.1.png|400px|thumb]] <br />
|- style="vertical-align: top; background: white; border: 1px solid darkgray;"<br />
| Figure 8a. Effects of bandpass calibration on the frequency dependent amplitudes across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8b. Effects of bandpass calibration on the frequency dependent phases across the observing band. The plots were made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option '' Y Data Column: corrected''. || Figure 8c. Effects of phase calibration on the time dependent amplitudes across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. || Figure 8d. Effects of phase calibration on the time dependent phases across the observing band. The various colors show the different baselines with reference antenna ea04. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected''. <br />
|}<br />
<br />
<font size="+1">'''<br /><br /> '''</font> <br />
<br />
<font size="+1">'''Then run the calibration process again starting with the <i>Delay calibration</i>:'''</font> <br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_data.ms', caltable='delays.cal', field='0', selectdata=True, timerange='06:43:48~06:48:42', solint='inf', refant='ea04', gaintype='K', gaintable=['antpos.cal','tecim.cal','rq.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='bpphase.gcal', field='0', spw='0:250~300', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintype='G', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal'])<br />
<br />
bandpass(vis='MG0414_d1_data.ms', caltable='bandpass.cal', field='0', spw='0', solint='inf', combine='', refant='ea04', solnorm=False, bandtype='B', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bpphase.gcal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='intphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='int', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='scanphase.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='inf', combine='', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal'])<br />
<br />
gaincal(vis='MG0414_d1_data.ms', caltable='amp.gcal', field='0', spw='0', selectdata=False, solint='inf', combine='', refant='ea04', calmode='ap', minsnr=3.0, gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','intphase.gcal'])<br />
</source><br />
<br />
[[File:Pband_ampcal_corrected_CASA5.5.0.png|thumb|500px|thumb|right|Figure 9. Effects of amplitude and flux density scale calibration. The green points (the YY products of antenna ea17 clearly seen in Figure 7) have been flagged. The plot was made in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casaplotms.plotms.html#casaplotms.plotms plotms] and in the ''Axes'' tab choosing option ''Y Data Column: corrected'']]<br />
<br />
<br />
<br />
The new calibration tables have overwritten the previous tables. Once you've re-run the calibration, you need to apply it. <br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_data.ms', field='0', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], parang=True, calwt=False, applymode='calflagstrict', flagbackup=True)<br />
<br />
applycal(vis='MG0414_d1_data.ms', field='1', gaintable=['antpos.cal','tecim.cal','rq.cal','delays.cal','bandpass.cal','scanphase.gcal','amp.gcal'], gainfield=['','','','0','0','0','0'], calwt=False, applymode='calflagstrict', flagbackup=True)<br />
</source><br />
<br />
<br />
And then, plot the corrected amplitudes vs time with ea17 flagged (see Figure 9):<br />
<br />
<source lang='python'><br />
# In CASA for corrected amp vs time with ea17 flagged, Figure 9<br />
plotms(vis='MG0414_d1_data.ms',field='0',antenna='ea04', correlation='xx,yy',avgchannel='1e8', xaxis='time',yaxis='amp',ydatacolumn='corrected',coloraxis='baseline')<br />
</source><br />
<br />
We now split the calibrated data of our target into a new measurement set, including only the XX and YY polarization products. Using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split] the calibrated target data are placed into the '''data''' column of the new measurement set:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_data.ms', outputvis='MG0414_d1_calibrated.ms', datacolumn='corrected', field='1', correlation='xx,yy', keepflags=False)<br />
</source><br />
<br />
== Imaging and Self-calibration ==<br />
<br />
We now have a calibrated data set that has all calibration applied except for possible self-calibration. Self-calibration relies on the target itself to better calibrate antenna-based gains (phases and amplitudes) as a function of time. It can be applied to targets that are strong in the continuum or have a strong enough spectral line to derive good phase and, if desired, also amplitude solutions on short (order of minutes) timescales. The procedure relies on an initial model of the target, which then can be used iteratively to improve the gains and hence the quality of the image itself. Here we show the various steps in self-calibrating our data based on the strong continuum emission of MG0414+0354. Please refer to a [https://casaguides.nrao.edu/index.php?title=First_Look_at_Self_Calibration_CASA_6 dedicated CASA guide] on self-calibration for further details.<br />
<br />
If strong RFI is present in the target, it may be necessary to flag your data before proceeding with self-calibration. This is not the case with MG0414+0354.<br />
<br />
We create an initial model of our target field using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. Notice that we will exclude from the continuum image the channels that we have flagged and the channels where we expected to detect the line:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_calibrated.ms', datacolumn='data', imagename='MG0414_d1_cont_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=100, threshold='1.5Jy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The information in the MODEL column consist of visibilities that present a model of the target field. CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] produces a ''.model'' image of the model that you can visualize with [https://cartavis.org/ CARTA] software. It is essential that only components that you know for sure represent the continuum in the target field are taken into account in self-calibration. If this is not the case, you probably cleaned too deep and included noise features or artifacts (e.g., from the beam-pattern) in the model. Self-calibration would permanently lock these as features in your data, so this should be avoided. On the other hand, it is equally crucial to ensure that the model is not empty, as this will result in your target being shifted to the phase center.<br />
<br />
You can see the tclean results using the CARTA tool, as we show in figure 10. Please refer to the [https://casadocs.readthedocs.io/en/stable/notebooks/carta.html CASA documentation] on how to load the image into CARTA.<br />
<br />
[[File:CARTA-MG0414_d1_cont_R03-6.5.2.png|800px|thumb|right|Figure 10. Image obtained after the first run of tclean task (MG0414_d1_cont_R03.image), visualized with CARTA.]]<br />
<br />
Next, we derive phase corrections to this model. Because our target is strong enough to do self-calibration on it, we should get enough S/N per baseline on a 60 sec interval, using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_calibrated.ms', caltable='sc1.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='60s', combine='', minsnr=3.0)<br />
</source><br />
<br />
This creates a new phase-calibration table that we call ''sc1.gcal''. We now apply this calibration table to the calibrated data in order to improve the phase-only solutions using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.applycal.html applycal]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_calibrated.ms', field='0', gaintable=['sc1.gcal'], interp='linear')<br />
</source><br />
<br />
Because self-calibration is an iterative process, we want to repeat this step again in order to further improve the gain calibration. For that, we first split the data calibrated with the self-calibration solutions applied to the DATA column to a new measurement set, again using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.split.html split]:<br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_calibrated.ms', outputvis='MG0414_d1_sc1.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
Now we can use this newly created measurement set to make a better continuum image and subsequently perform the next round of self-calibration:<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc1.ms', datacolumn='data', imagename='MG0414_d1_cont_sc1.R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=500, threshold='500mJy', imsize=[256,256],cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc1.ms', caltable='sc2.gcal', field='0', spw='0', refant='ea04', calmode='p', solint='30s', combine='', minsnr=3.0)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc1.ms', field='0', gaintable=['sc2.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc1.ms', outputvis='MG0414_d1_sc2.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc2.ms', datacolumn='data', imagename='MG0414_d1_cont_sc2_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
Now that we have a good model of the continuum in the field of MG0414+0354, we will attempt a final self-calibration using both the phases and amplitudes via CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.calibration.gaincal.html gaincal] :<br />
<br />
[[File:CARTA-MG0414_d1_cont_sc3ap_R03-6.5.2.png|800px|thumb|right|Figure 11. Image obtained after self-calibration. Compare with image shown in Figure 10.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
gaincal(vis='MG0414_d1_sc2.ms', caltable='sc3ap.gcal', field='0', spw='0', refant='ea04', calmode='ap', solint='30s', combine='', minsnr=3.0, solnorm=True)<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
applycal(vis='MG0414_d1_sc2.ms', field='0', gaintable=['sc3ap.gcal'], interp='linear')<br />
</source><br />
<br />
<source lang='python'><br />
# In CASA<br />
split(vis='MG0414_d1_sc2.ms', outputvis='MG0414_d1_sc3ap.ms', datacolumn='corrected', field='0', keepflags=False)<br />
</source><br />
<br />
[[File:MG0414_sc3ap_msview_6.5.2.png|right|thumb|800px|Figure 12. Display of time vs baseline for the MG0414+0354_d1_sc3ap.ms measurement set in [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview], with the animation axis set to 'channel'.]]<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_cont_sc3ap_R03', spw='0:4~50;60~147;156~250;350~460', specmode='mfs', niter=1000, threshold='100mJy', imsize=[256,256], cell='1arcsec', weighting='briggs', robust=0.2, savemodel='modelcolumn')<br />
</source><br />
<br />
The output continuum image from the last iteration of CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] continues to be an improvement over previous imaging, as you can see using [https://cartavis.org/ CARTA] again (Figure 11 showing results after three passes of self-calibration).<br />
<br />
<br />
However, now it also shows that we are not likely to gain further improvement with additional rounds of self-calibration (you can inspect this yourself by comparing the images created across the different iterations in [https://cartavis.org/ CARTA]). This indicates that we now have a calibrated data-set of MG0414+0354 that is almost ready for final imaging. Before imaging, we need to flag the target data to remove poor-quality data. First, we run an automated flagging routine using CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] with the parameter <i>mode='rflag'</i>:<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='rflag', datacolumn='data')<br />
</source><br />
<br />
<br />
<br />
After having ran this automated flagging, we inspect the data via the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview] by displaying ''time'' vs ''channel'' for the different baselines, or you may display ''time'' vs ''baseline'' for the different channels:<br />
<br />
<source lang='python'><br />
# In CASA<br />
msview('MG0414_d1_sc3ap.ms') <br />
</source><br />
<br />
<br />
Keep in mind that when the data is properly calibrated, it is easier to recognize low-level imperfections which may have to be flagged to improve the image quality. In this case, the noisier baselines are seen with lighter colors (see Figure 12). Hovering over these baselines will report a number pair such as 8-16, 8-17, etc. in the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.visualization.msview.html msview]. From this we can tell that baselines 8-# and 12-# (which correspond to antennas ea09 and ea14) have significantly higher noise than the other antennas, something which was not picked up by the automated flagging routine. Additionally, for a number of baselines, the data quality looks relatively poor. We flag these antennas and baselines via the CASA [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] task before imaging the data.<br />
<br />
<source lang='python'><br />
# In CASA<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea09', datacolumn='data')<br />
flagdata(vis='MG0414_d1_sc3ap.ms', mode='manual', antenna='ea14', datacolumn='data')<br />
</source><br />
<br />
To flag offending individual baselines, in CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.flagging.flagdata.html flagdata] you may use <i>antenna='antenna&antenna(&antenna...)'</i>. <br />
<br />
<br />
Flagging data can be an iterative process. Often, the better the data is calibrated, the easier it is to recognize low-level imperfections in it. To optimize the data reduction, you can script the calibration process, and opt to flag the data also in the original data set (i.e., before calibration), after which you run the entire calibration again.<br />
<br />
When you flag these antennas on the MS before the self calibration took place, you must go back and rerun the calibration before the final imaging, starting at the '''<i>Delay calibration</i>''' section. If you rerun the calibration you will either have to rename your measurement sets created from split during self calibration, or delete them in order to redo self calibration as split will not overwrite a ms name. <br />
<br />
We image the data using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. A 0.5Jy threshold was chosen for this command by interactively cleaning a single channel of the final self calibrated image and taking the 5σ of the noise levels once the image was cleaned. With an ideal threshold found, we can now clean all channels (this process can take hours to complete depending on the machine you are using):<br />
<br />
<source lang='python'><br />
# In CASA<br />
tclean(vis='MG0414_d1_sc3ap.ms', datacolumn='data', imagename='MG0414_d1_line_sc3ap_vel_R03', spw='0', specmode='cube', outframe='bary', veltype='optical', restfreq='390.600MHz', niter=10000000, threshold='0.05Jy', imsize=[256,256], cell='1arcsec', pbcor=True, weighting='briggs', robust=0.2, perchanweightdensity=True, savemodel='none',interpolation='nearest')<br />
</source><br />
<br />
<br />
OBS: From CASA version 6.2.0 onwards, one new input parameter has been added to the task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean]. The psfcutoff parameter allows fitting non-Gaussian PSF. The default value is 0.35, but can vary from 0.01 to 0.99. It is a parameter for advanced users, and it should rarely be changed. If a user needs to use it, the resulting fits should be carefully checked. We have used the default value in all [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.imaging.tclean.html tclean] runs of this tutorial since we have not set it at any time.<br />
<br />
<br />
We can inspect the resulting line-data cube, again using [https://cartavis.org/ CARTA]. The HI absorption feature is clearly present (see Figure 14). If you did NOT re-run the calibration sequence, you should get a plot that should look similar to Figures 13 and 14. To see your spectral line, open the last image of the source. Go to a channel that shows the source, then zoom in on the source. Click the ''Point marking'' icon, find the brightest pixel in the source and click on it. Now click on the ''spectral profile tool'' button to get the single point profile of the spectrum. Here you will see a spectrum with 2 dips that drop to zero; these dips are a part of the flagging we have done. You will need to zoom in in order to notice any spectral lines due to the auto scaling; zoom in by clicking on the graph and creating a yellow box then release.<br />
<br />
The data cube contains both continuum and line emission, which can optionally be separated using the CASA task [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub]. In principle, this task can be used for continuum subtraction and fitting in the uv domain; however, combining spws for the continuum fitting is not yet supported in the updated [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub.html uvcontsub] in CASA 6.5.2, and for that particular functionality the [https://casadocs.readthedocs.io/en/v6.5.2/api/tt/casatasks.manipulation.uvcontsub_old.html uvcontsub_old] should be used for the time being.<br />
<br />
<br />
[[File:CARTA-cube-6.5.2.png|1250px|thumb|left|Figure 13. Test-data of the redshifted HI 21cm absorption line on top of the radio continuum in MG 0414+0354 (i.e., the continuum was not subtracted); see More, Carilli & Mention 1999 (Apj, 510, 87) for the original detection. It is the final cleaned image here displayed using CARTA. As can be read from the bottom right panel, shown is channel 115, at 388.07 MHz. The profiles on the right show a single point 1D spectrum on x and y axes.]]<br />
<br />
<!-- NO LONGER RELEVANT, CARTA DOES EVERYTHING IN ONE, PREV. FIG. [[File:MG0414 d1 line sc3ap vel R03 recal 6.2.0.png|1100px|thumb|right|Figure 14. Left: The Single Point Spectral Profile with the auto scaling. Noticed the tip, make a tight horizontal yellow box around the main signal, like shown in figure. On right: The same after we zoom it.]]--><br />
<br />
<br />
<!--IMVIEW: Alternative Tip: You can click in the save icon (top left) in the Spectral Profile tool and export the spectral profile as a text file. And then, you can use any program you find appropriate to make the plot. You can see small differences in the continuum flux level, depending on the pixel you have selected to see the line profile. However, you should be able to identify the line in any of the bright central pixels.--><br />
<br />
<!-- --[[User:bemonts|Bjorn Emonts]] <br />
-- 5.0 corrections: [[User:kradford| Karlee Radford]] (2018-03-21)<br />
-- Edits [[User:tperreau| Tony Perreault]] (26 Apr 2018)<br />
-- Edits [[User:Hmedlin | Heidi Medlin]] (27 April 2018)<br />
-- Yet more edits [[User:tperreau| Tony Perreault]] (2 May 2018)<br />
-- And yet more edits [[User:tperreau| Tony Perreault]] (May the 4th be with you 2018)<br />
-- 5.4.0 updates: [User:kradford| Karlee Radford]] (2018-10-11)<br />
-- 5.5.0 updates: [User:asobotka| Alex Sobotka]] (3 July 2019)<br />
-- 5.7.0 updates: [User:pbeaklin| Pedro P.B. Beaklini]] (29 September 2020)<br />
-- Changed last figure: [User:pbeaklin| Pedro P.B. Beaklini]] (7 October 2020)<br />
-- 5.7.2 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Cheking tec_map (21 December 2020)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Added before and after selfcal figures (21 June 2021)<br />
-- 6.2.0 updates [User:pbeaklin| Pedro P.B. Beaklini]]. Changed task links, changed robust and added 'nearest' on last clean. (01 July 2021) <br />
-- 6.5.2 updates [User:akapinsk| Anna D Kapinska]]. Exchanged the ms.tgz file for download (error of unexpected EOF when unpacking), and exchanged some figures for clarity, plus some minor corrections. Removed imview, added CARTA. (13 Feb 2023)<br />
--> <br />
<br />
<br />
<br />
{{Checked 6.5.2}}</div>Akapinsk