https://casaguides.nrao.edu/api.php?action=feedcontributions&user=Lsjouwer&feedformat=atomCASA Guides - User contributions [en]2024-03-29T11:11:16ZUser contributionsMediaWiki 1.38.6https://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34885VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:11:48Z<p>Lsjouwer: /* D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='inf', calmode='ap')<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34884VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:11:09Z<p>Lsjouwer: /* C) Bootstrapping the Bandpass Calibrator Field Spectrum */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='inf', calmode='ap')<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34883VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:09:43Z<p>Lsjouwer: /* B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='inf', calmode='ap')<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34882VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:09:14Z<p>Lsjouwer: /* B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap')<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34881VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:06:59Z<p>Lsjouwer: /* A) Calibrating Initial Delays and Bandpass Solutions */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34880VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:05:37Z<p>Lsjouwer: /* A) Calibrating Initial Delays and Bandpass Solutions */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna'<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34879VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:04:21Z<p>Lsjouwer: /* A) Calibrating Initial Delays and Bandpass Solutions */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31'<br />
)<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna'<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34878VLA CASA Bandpass Slope-CASA6.4.12023-02-28T23:00:42Z<p>Lsjouwer: /* C) Bootstrapping the Bandpass Calibrator Field Spectrum */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im', usescratch=True);<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31'<br />
)<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna'<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp, usescratch=True);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im',usescratch=True);<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp,usescratch=True);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34332VLA CASA Bandpass Slope-CASA6.4.12023-01-25T16:34:46Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band, i.e., in the 28-40 GHz range),<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which could be important for spectral line observations or<br />
measuring the spectral index of continuum sources &mdash; may require<br />
higher signal-to-noise ratio bandpass solutions derived from either a<br />
long integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first-step delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second-step delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first steps will be to obtain, uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <download/working directory> (this tutorial uses up to 10GB in these directories)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' shortcut name used below is just an<br />
example name and can be changed to anything more descriptive and less<br />
cryptic. This is particularly useful if the original observation name<br />
has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3c84-J0319+413 (field 1,<br />
a.k.a. 3C84). Both fields have 64 spectral windows (spws); each spw<br />
consists of 128 dual (RR, LL) polarization 1 MHz wide channels, for a<br />
total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (False) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with the plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with the plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy]<br />
task in the model column in MS. Use the 'Perley-Butler 2017' standard<br />
and 3C147_A.im for Ka-band (which can be written as ''id_flx+'_A.im''<br />
because here fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator (3C147)]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea02 to ea12]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea14 to ea22]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea23 to ea28]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31'<br />
)<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna'<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3c84-J0319+413), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-step bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3c84-J0319+413, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3c84-J0319+413, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped bandpass calibrator (3c84-J0319+413) flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of the bandpass calibrator (3c84-J0319+413) as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for the bandpass calibrator (3c84-J0319+413). Shown is antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3c84-J0319+413: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34331VLA CASA Bandpass Slope-CASA6.4.12023-01-25T15:42:19Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>lantindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, xaxis='freq', field=id_flx, coloraxis='ant2', <br />
yaxis='amp', ydatacolumn='model', antenna='ea03')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', refant=id_ref, minsnr=3,<br />
field=id_bp, gaintype='G',<br />
spw='*:60~68', solint='int', calmode='p')<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', coloraxis='spw', iteraxis='antenna', yaxis='phase')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', refant=id_ref, minsnr=3,<br />
gaintable=['cal.ign'], field=id_bp,<br />
gaintype='K', spw='*:5~122', solint='inf')<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', refant=id_ref,<br />
gaintable=['cal.ign', 'cal.dly'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31'<br />
)<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna'<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', refant=id_ref, minsnr=3,<br />
gaintable=['cal.dly', 'cal.bp'], field=id_flx+','+id_bp, <br />
gaintype='G', solint='int', calmode='p')<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', refant=id_ref, minsnr=3, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], field=id_flx+','+id_bp, <br />
gaintype='G'', solint='inf', calmode='ap)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', refant=id_ref, minsnr=3, <br />
field=id_bp, gaintype='G', <br />
spw='*:60~68', solint='int', calmode='p') <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', refant=id_ref, minsnr=3, <br />
gaintable=['cal.ign.redo'], field=id_bp, <br />
gaintype='K', spw='*:5~122', solint='inf')<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', refant=id_ref, <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], field=id_bp,<br />
solnorm=False, bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='0~31')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='amp', spw='32~63')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna',<br />
yaxis='phase', spw='0~31', plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', coloraxis='spw', iteraxis='antenna', <br />
yaxis='phase', spw='32~63', plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|right|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
|}<br />
{|<br />
| [[Image:Fig_10a.c641.png|350px|thumb|left|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34316VLA CASA Bandpass Slope-CASA6.4.12023-01-24T06:08:37Z<p>Lsjouwer: /* D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|300px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|300px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:Fig_10a.c641.png|300px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|300px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34315VLA CASA Bandpass Slope-CASA6.4.12023-01-24T06:07:05Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|350px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|350px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|350px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|350px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|350px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|350px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|350px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|350px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|350px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:Fig_06a.c641.png|350px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|350px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|350px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|350px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|350px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|350px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:Fig_10a.c641.png|350px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|350px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34314VLA CASA Bandpass Slope-CASA6.4.12023-01-24T06:01:28Z<p>Lsjouwer: /* Cheat Sheet - All Commands Summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|200px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|200px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|200px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:Fig_06a.c641.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:Fig_10a.c641.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34313VLA CASA Bandpass Slope-CASA6.4.12023-01-24T05:52:10Z<p>Lsjouwer: /* Selecting a reference antenna form the array configuration */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>antindex=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|200px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|200px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|200px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:Fig_06a.c641.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:Fig_10a.c641.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_10b.c641.png&diff=34312File:Fig 10b.c641.png2023-01-24T05:33:33Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_10a.c641.png&diff=34311File:Fig 10a.c641.png2023-01-24T05:33:08Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_09b.c641.png&diff=34310File:Fig 09b.c641.png2023-01-24T05:32:16Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_09a.c641.png&diff=34309File:Fig 09a.c641.png2023-01-24T05:31:54Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_08.c641.png&diff=34308File:Fig 08.c641.png2023-01-24T05:31:37Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_07.c641.png&diff=34307File:Fig 07.c641.png2023-01-24T05:31:19Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_06b.c641.png&diff=34306File:Fig 06b.c641.png2023-01-24T05:30:46Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_06a.c641.png&diff=34305File:Fig 06a.c641.png2023-01-24T05:30:29Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_05b.c641.png&diff=34304File:Fig 05b.c641.png2023-01-24T05:27:04Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_05a.c641.png&diff=34303File:Fig 05a.c641.png2023-01-24T05:26:36Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_04.c641.png&diff=34302File:Fig 04.c641.png2023-01-24T05:26:10Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_03c.c641.png&diff=34301File:Fig 03c.c641.png2023-01-24T05:25:36Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_03b.c641.png&diff=34300File:Fig 03b.c641.png2023-01-24T05:25:14Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_03a.c641.png&diff=34299File:Fig 03a.c641.png2023-01-24T05:24:30Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_02.c641.png&diff=34298File:Fig 02.c641.png2023-01-24T05:23:21Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_01b.c641.png&diff=34297File:Fig 01b.c641.png2023-01-24T05:19:02Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=File:Fig_01a.c641.png&diff=34296File:Fig 01a.c641.png2023-01-24T05:18:05Z<p>Lsjouwer: </p>
<hr />
<div></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34295VLA CASA Bandpass Slope-CASA6.4.12023-01-24T05:13:41Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range,<br />
so be aware when using CASA installed on the NRAO machines that are current.<br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
For the purpose of this tutorial it is also safe to ignore any<br />
annoying messages about the "leap second table" being "out of date"..<br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
{|<br />
| [[Image:Fig_01a.c641.png|200px|thumb|left|Figure 1a: Antenna locations logarithmic-scale plotted with plotants() task.]]<br />
| [[Image:Fig_01b.c641.png|200px|thumb|right|Figure 1b: Antenna locations linear-scale plotted with plotants() task.]]<br />
|}<br />
<br />
As can be seen (Figure 1), either with the logarithmic-scale or<br />
possibly after zooming in with the magnifying glass icon on the<br />
linear-scale, for example antenna "ea05" (with ID 3) is located close<br />
to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:Fig_02.c641.png|200px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10, ea13 and ea19<br />
(ea04 was not part of the array configuration). Click on the green<br />
arrows to pass through the plots for the other antennas. Also note<br />
that the reference antenna (ea05 here) has all phases equal to zero<br />
degrees, which they should be by definition for the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 10, not 1-9 as the antenna with index 7 is not present<br />
# as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~10', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='11~19', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='20~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_03a.c641.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:Fig_03b.c641.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:Fig_03c.c641.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:Fig_04.c641.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_05a.c641.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:Fig_05b.c641.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:Fig_06a.c641.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:Fig_06b.c641.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
<!-- Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078 --><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308677 (freq=32.5128 GHz) spidx: a_1 (spectral index) =-0.538798 +/- 0.00882989<br />
<br />
</pre><br />
<br />
[[Image:Fig_07.c641.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:Fig_08.c641.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:Fig_09a.c641.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_09b.c641.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:Fig_10a.c641.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:Fig_10b.c641.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34294VLA CASA Bandpass Slope-CASA6.4.12023-01-24T04:32:43Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
==== 1) Frequency setup, calibrator intents, scan listing, etc ====<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
=== 2) Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 1: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 1), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== 3) Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 2: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 2):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34195VLA CASA Bandpass Slope-CASA6.4.12023-01-20T18:06:07Z<p>Lsjouwer: /* 1) Frequency setup, calibrator intents, scan listing, etc */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
==== 1) Frequency setup, calibrator intents, scan listing, etc ====<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
=== 2) Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== 3) Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34194VLA CASA Bandpass Slope-CASA6.4.12023-01-20T17:57:16Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
=== 1) Frequency setup, calibrator intents, scan listing, etc ===<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
=== 2) Selecting a reference antenna form the array configuration ===<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
=== 3) Setting the Model of the Flux Density Calibrator ===<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34188VLA CASA Bandpass Slope-CASA6.4.12023-01-20T17:52:32Z<p>Lsjouwer: /* Cheat Sheet - All Commands Summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''#''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
###<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34186VLA CASA Bandpass Slope-CASA6.4.12023-01-20T17:51:04Z<p>Lsjouwer: /* Cheat Sheet - All Commands Summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''&num;&nbsp;''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre style="background-color: #d4d4d4;"><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre><br />
<br />
Have fun!<br />
<pre><nowiki />###</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34179VLA CASA Bandpass Slope-CASA6.4.12023-01-20T17:47:38Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''&num;&nbsp;''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre style="background-color: #d4d4d4;"><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre><br />
<br />
Have fun!<br />
#&nbsp;#&nbsp;#&nbsp;</div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34177VLA CASA Bandpass Slope-CASA6.4.12023-01-20T17:36:41Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or CASA update may provide a different model than used<br />
here, in particular in Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz]<br />
either by clicking on the link or by using operating system tools like <tt>wget</tt> (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
cd <working directory> (this tutorial uses up to 10GB in this directory)<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (the exact name of the installed versions to<br />
choose from can be obtained by typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# the same way by using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023), restructured in steps<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added a cheat sheet too.<br /><br />
--><br />
<br />
== Cheat Sheet - All Commands Summarized ==<br />
<br />
In the tutorial above, these commands were used. Apart from the<br />
''%cpaste'' section (that requires typing the double dash '''--''' to<br />
end the section), all commands are intended to be single-line commands<br />
and the space-indented line commands are informational (mostly plots)<br />
rather than essential. Obviously, lines starting with a hash-tag, the<br />
octothorp '''&num;''', are comment lines and need not be issued.<br />
<br />
Note that the automatic formatting by the browser may introduce some<br />
weirdness in displaying the pre-formatted text and single line<br />
commands; be aware when copy/pasting that the line is complete, i.e.,<br />
the task commands must be ending with the closing parenthesis and/or<br />
semicolon.<br />
<br />
<pre style="background-color: #d4d4d4;"><br />
# in a terminal, outside of CASA<br />
wget http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside CASA, on command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# *** Step A) ***<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# *** Step B) ***<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# *** Step C) ***<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# *** Step D) ***<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre><br />
<br />
Have fun!<br />
###</div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34160VLA CASA Bandpass Slope-CASA6.4.12023-01-19T23:30:36Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added cheat sheet too. <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
(Note that the automatic formatting here may introduce some weirdness in displaying the pre-formatted text and single line commands; be aware when copy/pasting that the line is complete, i.e., ending with the closing parenthesis and/or semicolon.)<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# Step A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# Step B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# Step C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# Step D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34159VLA CASA Bandpass Slope-CASA6.4.12023-01-19T23:20:19Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added cheat sheet too. <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
(Note that the automatic formatting here may introduce some weirdness in displaying the pre-formatted text and single line commands.)<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# Step A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# Step B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# Step C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# Step D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34158VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:49:10Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables. Added cheat sheet too. <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# Step A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='1~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# Step B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# Step C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# Step D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34157VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:44:41Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #cccccc;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34156VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:44:08Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #aa66bb;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34155VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:42:44Z<p>Lsjouwer: /* A) Calibrating Initial Delays and Bandpass Solutions */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p1.png')<br />
</source><br />
<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p2.png')<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw', plotfile=visbase+'_cal.ign_p3.png')<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #bbddbb;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34154VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:38:48Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p1.png', width=1300, height=800)<br />
</source><br />
* <tt>width=1300</tt> and <tt>height=800</tt> specify the output PNG pixel dimensions.<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p2.png', width=1300, height=800)<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p3.png', width=1300, height=800)<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #bbddbb;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png')<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34153VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:32:28Z<p>Lsjouwer: /* Cheat Sheet - all commands summarized */</p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p1.png', width=1300, height=800)<br />
</source><br />
* <tt>width=1300</tt> and <tt>height=800</tt> specify the output PNG pixel dimensions.<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p2.png', width=1300, height=800)<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p3.png', width=1300, height=800)<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #99ddbb;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png',width=1300,height=800)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png',width=1300,height=800)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png',width=1300,height=800)<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34152VLA CASA Bandpass Slope-CASA6.4.12023-01-19T22:29:22Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics for these standard calibrators,<br />
resulting in improved calibration solutions that therefore more<br />
accurately represent the instrumental and atmospheric<br />
corrections. These VLA standard calibrators, however, exhibit a<br />
negative spectral index (i.e., flux density decreasing with increasing<br />
frequency) and become relatively weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrator alternatives are used. Unfortunately, the spectral<br />
characteristics of these sources will be undetermined, and no<br />
''a-priori'' flux density model is available. If not accounted for,<br />
using undetermined spectral behavior will introduce bias in the delay<br />
and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-offs one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator (which contamination will be taken out in the next step, C).<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index, of the bandpass calibrator. <br />
D) With this flux density and spectral index model, determine a new, second order delay<br />
and bandpass calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator, which then can be used as if it were a standard.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here, G192-BP.ms, can be downloaded<br />
directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name; the ''my-vis'' used below is just an example name and<br />
can be changed to anything more descriptive and less cryptic. This is<br />
particularly useful if the original observation name has it's full<br />
extent like ''TVER0004.sb14459364.eb14492359.56295.26287841435'', for<br />
example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA, set the necessary paths appropriately and<br />
start up a logger window on the desktop. Starting CASA will also create<br />
<!-- two files; one is ''ipython-<unique-timestamp>.log'' which contains a record of all the text entered at the CASA prompt, and another as ''casapy-<unique-timestamp>.log'' --><br />
a file ''casa-<date-time>.log''<br />
which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
log files intact as a reminder of the steps completed in the data<br />
reduction. The most recent (i.e., current) log file may also be<br />
helpful when submitting a helpdesk ticket.<br />
<br />
For convenience, the logger window can be rescaled and the font size<br />
can be changed as desired; see the options under the '''View'''<br />
menu. More easily, remove clutter columns by moving the mouse to the<br />
logger window and press "Ctrl-N", "Ctrl-Y","Ctrl-E", ('''N'''ew<br />
'''Y'''ears '''E'''ve is one way to remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources with their intents, and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the actual ''G192-BP.ms'' name string<br />
of the MS directory will be replaced by the variable value stored in<br />
''id_ms'' (identify-the-MS). This makes the instructions below less<br />
dependent on the actual name of the data root so that if another<br />
measurement set name is used, only the definition here needs to be<br />
edited to the other file name. In order to do that first define these<br />
parameters as variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has,<br />
like "my-vis" above - without the ".ms" !)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS (the summary mode of [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.vishead.html vishead] does not reveal calibrator intents by default):<br />
<source lang="python"><br />
# In CASA, dump the MS listing into a file in the working directory:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
* Note the use of a semicolon (i.e., '';'') ending the command after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(''!'')''' before the<br />
command, such as <tt>cat</tt>, <tt>less</tt>, or<br />
<tt>more</tt>. Preferably use an editor and keep it on the desktop for<br />
frequent consultation with e.g. <tt>emacs</tt>, <tt>vi</tt>, or<br />
<tt>gedit</tt>, etc.:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array (for the most compact D-configuration<br />
select an antenna that is unlikely to get shadowed, i.e., in the<br />
outskirts of the array). Futhermore, it needs to have valid calibrator<br />
data on all baselines with the least amount of data flagged. The array<br />
can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms, antindex=True, logpos=True)<br />
</source><br />
* <tt>logpos=True</tt> also labels the antennas with their ID number (in parenteses).<br />
* <tt>logpos=True</tt> shows a logarithmic plot to emphasize the center distribution, useful for picking a reference antenna in extended configurations - use the default (blank) for compact configurations to emphasize the outlyer stations. <br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
As can be seen (Figure 2), possibly after zooming in with the<br />
magnifying glass icon, for example antenna "ea05" (with ID 3) is<br />
located close to the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata]<br />
task with mode='summary' it can be seen that "ea05" has a low<br />
percentage of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a standard descriptive variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (below, in step C<br />
mentioned above), insert the spectral and angular models for the flux<br />
density calibrator, here 3C147 (field 0), with the<br />
<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency for baselines to this antenna. Selecting another<br />
antenna for the plot will slightly change the curves. Also, a<br />
different CASA version or other update (or picking the wrong<br />
sourceName_frequencyBand model) would show a different behavior.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this entire bandpass calibration procedure with a phase-only,<br />
time-dependent (self-)calibration solution for the bandpass<br />
calibrator using the parameter ''gaintype='G' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal], which should be easy for these supposedly bright<br />
sources. Note that the calibration solutions are written to a<br />
calibration table, <tt>cal.ign</tt>, where 'ign' after the<br />
standardized calibration table prefix name (''cal'')stands for<br />
per-integration gain. This table is not a variable but a<br />
file/directory name in the working directory so it needs to be quoted<br />
in the input parameter. Solutions for each integration will remove<br />
most of the (phase) decorrelation of the signal allowing for the<br />
delay/bandpass calibration to succeed. For best results, the phase<br />
variations will be derived from a narrow range of channels near the<br />
centers of each spw (say 60~68 here, out of the 128 available per<br />
spw), narrow enough to not be affected by uncorrected delay (i.e.,<br />
reduce possible decorrelation by excluding any large phase differences<br />
due to a phase slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions, colored by spw, are smoothly varying,<br />
supposedly reflecting the changing phases due to atmospheric effects<br />
(i.e., for these high frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', iteraxis='antenna', coloraxis='spw')<br />
</source><br />
<br />
Note that the first plot showing the results for antenna ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are in the format of their extention in the<br />
<tt>plotfile</tt> parameter, in this case PNG files, and if the<br />
parameter is set to create output in the working directory, can be<br />
viewed at any occasion using CASA by executing an external viewer<br />
program, e.g., <tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running<br />
an image viewing application such as xv, Preview, Gimp, Photoshop,<br />
etc., external to CASA at the operating system level. Note that the<br />
hardcopy only shows the first page, requiring three <tt>plotms</tt><br />
instances of 3x3 plots to cover all antennas in the MS.<br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges<br />
# (antenna-ID 1 to 11, not 1-9 as the antennas with index 7 and 10 are not<br />
# present as can be noticed in the MS summary <visbase>_list.txt.<br />
# Unlike anything else in CASA-python indexing, antenna IDs start at one<br />
# instead of zero):<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='1~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p1.png', width=1300, height=800)<br />
</source><br />
* <tt>width=1300</tt> and <tt>height=800</tt> specify the output PNG pixel dimensions.<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of<br />
the iteraxis and there unfortunately seems to be no possibility to switch that off;<br />
to get the file name as specified in the plotfile-parameter one would edit the file<br />
name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
# second page batch (next nine antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p2.png', width=1300, height=800)<br />
<br />
# third page batch (remaining six antennas)<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p3.png', width=1300, height=800)<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and store the solutions in the <tt>cal.dly</tt> table (''dly'' for<br />
''delay''). Note that this currently does not do a global<br />
fringe-fitting solution for delays. Instead it determines a<br />
baseline-based delay solution per spw for all baselines to the<br />
reference antenna, treating these as antenna-based delays. In most<br />
cases, with high enough S/N to get baseline-based delay solutions,<br />
this will suffice. Avoid the edge channels of each spectral window by<br />
de-selecting them (say, select channels 5~122 here, from the 128<br />
available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw' '' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal]<br />
and run the task for each baseband separately (here, in four groups of<br />
16 spw). The solutions from the second and following runs can be<br />
appended to the same calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays as a function of antenna index (using one colored<br />
dot for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt> (''bp'' for ''bandpass''):<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-80,80])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral behavior. This information is then used to<br />
re-determine the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only self-calibration solution with the<br />
preliminary determined delay and bandpass calibration in the previous<br />
step, A), this time for both the bandpass and the flux density<br />
calibrator (which need to be separated by a comma) and store the<br />
solutions in <tt>cal.ign2pha</tt> (use the ''2pha'' to distinguish it<br />
as the second stage for phase-only). This will correct for short-term<br />
phase decorrelation of the signals. Similarly to avoid decorrelation<br />
due to a wide frequency range, use the narrow center channel range<br />
(which was channel 60~68):<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected (biased) with the delay and bandpass of the bandpass<br />
calibrator. Store the solutions in <tt>cal.ign2</tt> (use the ''2'' to<br />
distinguish it as the second pass gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With full, phase '''and amplitude''' gain solutions for both the flux<br />
density and bandpass calibrators, now use<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
to scale the gain amplitudes of the bandpass calibrator using those of<br />
the flux density calibrator. Store the solutions in <tt>cal.bpflx</tt><br />
and the flux density results for the bandpass calibrator in<br />
<tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.bpflx', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.bpflx'</tt>: this is the output scaled gain table containing the flux density of the bandpass calibrator as function of frequency. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows, using the default model supplied with this CASA version:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of ipython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end. This stops (exits) the copy/paste prompt and will return the CASA command line prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,63)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux == None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale]<br />
is used to fill the ''<tt>MODEL</tt>'' column with the bandpass<br />
source's spectral information using<br />
[https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy].<br />
With ''standard='fluxscale' '', we can directly use the<br />
<tt>flux_bp</tt> python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Creating a New Bandpass using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information<br />
as if it were a standard flux density calibrator. Although the<br />
commands are the same as issued earlier, keep in mind that the model<br />
values for the bandpass calibrator have changed and, therefore, the<br />
results of these calibration calculations accordingly will differ if<br />
the specral index differs significanlty from the spectral index of the<br />
flux density calibrator:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
As in this particualr observation the spectral indices for the flux<br />
density calibrator (3C147: -0.696, standard) and the bandpass<br />
calibrator (3C84: -0.626, derived here) are very similar, the<br />
solutions look virtually unchanged from the previous solutions with<br />
the exception that the amplitude scaling is corrected for the spectrum<br />
of the bandpass calibrator. These steps yielded the final version of<br />
the delay and bandpass calibration tables, '''cal.dly.redo''' and<br />
'''cal.bp.redo''', which now would be used for all subsequent<br />
calibration steps.<br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--><br />
<br />
== Cheat Sheet - all commands summarized ==<br />
<br />
<pre style="background-color: #aaaaaa;"><br />
# in a terminal, outside of CASA<br />
tar -xzf G192-BP.ms.tar.gz <br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
<br />
# inside of CASA, CASA command line<br />
visbase='G192-BP'<br />
id_ms=visbase+'.ms'<br />
listobs(vis=id_ms,listfile=visbase+'_list.txt');<br />
id_flx='3C147'<br />
id_bp='3c84-J0319+413'<br />
plotants(vis=id_ms,antindex=True,logpos=True)<br />
id_ref='ea05'<br />
setjy(vis=id_ms,field=id_flx,scalebychan=True,standard='Perley-Butler 2017',model=id_flx+'_A.im');<br />
plotms(vis=id_ms,field=id_flx,antenna='ea03',xaxis='freq',yaxis='amp',ydatacolumn='model',coloraxis='ant2')<br />
<br />
# A) ---<br />
gaincal(vis=id_ms,caltable='cal.ign',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',iteraxis='antenna',coloraxis='spw')<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='0~11',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p1.png',width=1300,height=800)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='12~20',gridrows=3,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p2.png',width=1300,height=800)<br />
plotms(vis='cal.ign',xaxis='time',yaxis='phase',antenna='21~26',gridrows=2,gridcols=3,iteraxis='antenna',coloraxis='spw',plotfile=visbase+'_cal.ign_p3.png',width=1300,height=800)<br />
gaincal(vis=id_ms,caltable='cal.dly',field=id_bp,spw='*:5~122',gaintype='K',gaintable=['cal.ign'],refant=id_ref,solint='inf',minsnr=3)<br />
plotms(vis='cal.dly',xaxis='ant1',yaxis='delay',coloraxis='spw')<br />
bandpass(vis=id_ms,caltable='cal.bp',gaintable=['cal.ign','cal.dly'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
<br />
# B) ---<br />
gaincal(vis=id_ms,caltable='cal.ign2pha',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp'],gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3)<br />
gaincal(vis=id_ms,caltable='cal.ign2',field=id_flx+','+id_bp,gaintable=['cal.dly','cal.bp','cal.ign2pha'],gaintype='G',refant=id_ref,calmode='ap',solint='inf',minsnr=3)<br />
<br />
# C) ---<br />
flux_bp=fluxscale(vis=id_ms,caltable='cal.ign2',fluxtable='cal.bpflx',reference=id_flx,transfer=id_bp,listfile=visbase+'_'+id_bp+'_fluxinfo.txt',fitorder=1)<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
pl.clf()<br />
pl.plot(freq,bootstrapped_fluxes,'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
<br />
setjy(vis=id_ms,field=id_bp,scalebychan=True,standard='fluxscale',fluxdict=flux_bp);<br />
plotms(vis=id_ms,field=id_bp,antenna='ea05&ea02',xaxis='freq',yaxis='amp',ydatacolumn='model')<br />
<br />
# D) ---<br />
gaincal(vis=id_ms,caltable='cal.ign.redo',field=id_bp,spw='*:60~68',gaintype='G',refant=id_ref,calmode='p',solint='int',minsnr=3) <br />
gaincal(vis=id_ms,caltable='cal.dly.redo',gaintable=['cal.ign.redo'],field=id_bp,spw='*:5~122',gaintype='K',refant=id_ref,solint='inf',minsnr=3)<br />
bandpass(vis=id_ms,caltable='cal.bp.redo',gaintable=['cal.ign.redo','cal.dly.redo'],field=id_bp,refant=id_ref,solnorm=False,bandtype='B',solint='inf')<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='amp',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,0,15])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='0~31',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
plotms(vis='cal.bp.redo',xaxis='freq',yaxis='phase',spw='32~63',iteraxis='antenna',coloraxis='spw',plotrange=[-1,-1,-80,80])<br />
</pre></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34109VLA CASA Bandpass Slope-CASA6.4.12023-01-18T23:39:07Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Purpose Background and Method Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics, resulting in improved<br />
calibration solutions that therefore more accurately represent the<br />
instrumental and atmospheric corrections. These VLA standard<br />
calibrators, however, exhibit a negative spectral index (i.e., flux<br />
density decreasing with increasing frequency) and become relatively<br />
weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good delay and bandpass determination<br />
&mdash; which is important for spectral line observations or measuring<br />
the spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrators are used. Unfortunately, the spectral characteristics of<br />
these sources will be undetermined, and no ''a-priori'' flux density<br />
model is available. If not accounted for, using undetermined spectral<br />
behavior will introduce bias in the delay and bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-off one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the delay and bandpass<br />
solutions for such an effect using alternative bandpass calibrator<br />
sources. For that follow these four general steps (below) to obtain a<br />
delay and bandpass calibration as determined from a non-standard<br />
bandpass calibrator source, and avoid including the (higher) noise of<br />
the flux density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
A) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
B) Use this first order delay and bandpass solution to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator.<br />
C) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index of the bandpass calibrator. <br />
D) With this spectral index model, determine a new, second order delay and bandpass<br />
calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the (Tutorial-Modified) Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here can be downloaded directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, prepare the measurement set:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name. This is particularly useful if the original observation<br />
name has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# OPTIONAL !<br />
# in a terminal, outside of CASA, rename (shorten) the MS to a link:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the default package:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA, start the specific package:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA and set the necessary paths appropriately.<br />
This will also create two files; one is<br />
''ipython-<unique-timestamp>.log'' which contains a record of all the<br />
text entered at the CASA prompt, and another as<br />
''casapy-<unique-timestamp>.log'' which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
these log files intact as a reminder of the steps completed in the<br />
data reduction. These log files may also be helpful when submitting a<br />
helpdesk ticket.<br />
<br />
Once CASA has started, a logger window will appear. Note that this<br />
window can be rescaled and the font size can be changed as desired;<br />
see the options under the '''View''' menu. I personally like to remove<br />
clutter columns by moving the mouse to the logger window and press<br />
"Ctrl-N", "Ctrl-Y","Ctrl-E", (''N''ew ''Y''ears ''E''ve is one way to<br />
remember).<br />
<br />
== Examining the Measurement Set (MS) and Pre-Defining Variables ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as captured in the data set. Typical pieces of information<br />
to look for are 1) the calibrator sources (with their intents), and 2)<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to 3) set the flux model for the<br />
standard flux density calibrator, although that can be done at later<br />
stages too; it is done here to finish up the preparations before doing<br />
the actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the ''G192-BP.ms'' name in the<br />
directory will be replaced by the variable value stored in ''id_ms''<br />
(identify-the-MS). This makes the instructions below less dependent on<br />
the actual name of the data root so that if another measurement set<br />
name is used, only the definition here needs to be edited to the other<br />
file name. In order to do that first define these parameters as<br />
variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the data root and MS:<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has, like "my-vis" above)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''1) Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS:<br />
<source lang="python"><br />
# In CASA, dump the MS listing in a file:<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
<br />
*Note the use of a semicolon (i.e., '';'') after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(!)''' before the command,<br />
such as <tt>cat</tt>, <tt>less</tt>, or <tt>more</tt>. Preferably use<br />
an editor and keep it on the desktop for frequent consultation with<br />
e.g. <tt>emacs</tt>, <tt>vi</tt>, or <tt>nedit</tt>:<br />
<br />
<source lang="python"><br />
# In CASA, view the file with the MS listing, e.g.:<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1, here named<br />
''3c84-J0319+413''). Both fields have 64 spectral windows (spws); each<br />
spw consists of 128 dual (RR, LL) polarization 1 MHz wide channels,<br />
for a total bandwidth of 128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't strings so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define field identifiers using standard variable names:<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''2) Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array. Futhermore, it needs to have valid<br />
calibrator data on all baselines with the least amount of data<br />
flagged. The array can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA, plot antenna locations:<br />
plotants(vis=id_ms)<br />
</source><br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna locations plotted with plotants() task.]]<br />
<br />
<br />
Although the plot is a bit crowded (Figure 2), zooming in with the<br />
magnifying glass icon shows that antenna "ea05" is located close to<br />
the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata] task with mode='summary' it can be seen that "ea05" has<br />
small number of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA, define the reference antenna identifier using a standard name:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
'''3) Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (in step C above),<br />
insert the spectral and angular models for the flux density<br />
calibrator, here 3C147 (field 0), with the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA, insert the the flux density calibrator model in the MS model column:<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
<br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output for model amplitudes as function of freqency for the flux density calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA, plot the model amplitude as function of frequency<br />
# for baselines to antenna ea03:<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency.<br />
<br />
== A) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this procedure with a phase-only, time-dependent<br />
(self-)calibration solution for the bandpass calibrator, which should<br />
be easy for these supposedly bright sources. Note that the calibration<br />
solutions are written to a calibration table, <tt>cal.ign</tt>, where<br />
'ign' stands for per-integration gain. This table is not a variable<br />
but a string/name so it needs to be quoted in the input<br />
parameter. Solutions for each integration will remove most of the<br />
(phase) decorrelation of the signal allowing for the delay/bandpass<br />
calibration to succeed. For best results, the phase variations will be<br />
derived from a narrow range of channels (say 60~68 here, out of the<br />
128 available per spw) near the centers of each spw, narrow enough to<br />
not be affected by uncorrected delay (i.e., reduce possible<br />
decorrelation by excluding any large phase differences due to a phase<br />
slope over the frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA, do a phase-only self-calibration on the bandpass calibrator<br />
# (self-calibrating amplitudes is premature before determining a<br />
# preliminary bandpass calibration and will be done in a later step):<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
<br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Check that the phase solutions (using full phase range -180 to 180<br />
instead of autorange) are smoothly varying, supposedly reflecting the<br />
changing phases due to atmospheric effects (i.e., for these high<br />
frequencies due to the troposphere):<br />
<br />
<source lang="python"><br />
# In CASA, plot phase solutions as function of time, displaying one-for-one<br />
# a plot for baselines to each antena:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
iteraxis='antenna', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
Note that antenna the first plot showing the results for ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are PNG files and can be viewed at any<br />
occasion using CASA by executing an external viewer program, e.g.,<br />
<tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running an image viewing<br />
application such as xv, Preview, Gimp, Photoshop, etc., external to<br />
CASA at the operating system level. <!-- (Note that the hardcopy only<br />
shows the first page): --><br />
<br />
<source lang="python"><br />
# In CASA, dump images of multi-panel plots for different antenna-ID ranges:<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='0~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p1.png', width=1300, height=800)<br />
</source><br />
<br />
* <tt>width=1300</tt> and <tt>height=800</tt> specify the output PNG pixel dimensions.<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of the iteraxis and there unfortunately seems to be no possibility to switch that off; to get the file name as specified in the plotfile-parameter one would edit the file name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p2.png', width=1300, height=800)<br />
<br />
#<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p3.png', width=1300, height=800)<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] and store the solutions in the <tt>cal.dly</tt> table. Note<br />
that this currently does not do a global fringe-fitting solution for<br />
delays. Instead it determines a baseline-based delay solution per spw<br />
for all baselines to the reference antenna, treating these as<br />
antenna-based delays. In most cases, with high enough S/N to get<br />
baseline-based delay solutions, this will suffice. Avoid the edge<br />
channels of each spectral window by de-selecting them (say select<br />
channels 5~122 here, from the 128 available per spw):<br />
<br />
<source lang="python"><br />
# In CASA, determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that this applies the initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw''' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] and run the task for each baseband separately. The solutions<br />
from the second and following runs can be appended to the same<br />
calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based delays after running gaincal().]]<br />
<br />
Now plot the delays, in nanoseconds, as a function of antenna index<br />
(you will get one for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA, display the delay solutions for each spw as function of antenna-ID:<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt>:<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA, display the bandpass solutions for amplitude and phase for<br />
# the different (2x 4GHz) spw ranges; first range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== B) Applying the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral index. This information is then used to<br />
recalibrate the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only calibration solution, this time for both<br />
the bandpass and the flux density calibrator (which need to be<br />
separated by a comma) and store the solutions in <tt>cal.ign2pha</tt><br />
(use the ''2pha'' to distinguish it as the second stage for<br />
phase-only). This will correct for short-term phase decorrelation of<br />
the signals. Similarly to avoid decorrelation due to a wide frequency<br />
range, use the narrow center channel range (which was channel 60~68)<br />
and apply the bandpass and delay calibration tables:<br />
<br />
<source lang="python"><br />
# In CASA, phase-only self-calibrate the flux density and bandpass calibrators<br />
# using the obtained first-order bandpass calibration above:<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected with the delay and bandpass of the bandpass. Store the<br />
solutions in <tt>cal.ign2</tt> (use the ''2'' to distinguish it as the<br />
second stage gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA, now self-calibrate the phase-corrected amplitudes as well:<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
## In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
##<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== C) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With gain solutions for the flux density and bandpass calibrators, now use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] to scale the gain amplitudes of the bandpass calibrator using those of the flux density calibrator. Store the solutions in <tt>cal.flx2</tt> and the model for the bandpass calibrator in <tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA, determine the bandpass calibrator fluxes as function of frequency by<br />
# using the fluxes set for the flux density calibrator with setjy earlier and<br />
# store the output dictionary with these values in the variable flux_bp:<br />
flux_bp = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.flx2', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux_bp = fluxscale(...)</tt>: the Python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux_bp</tt> variable. Inspect the dictionary flux_bp by typing "print flux_bp" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux_bp as it is going to be used below<br />
* <tt>fluxtable='cal.flx2'</tt>: this is the output scaled gain table. Since this is only used to find the spectral index of the bandpass calibrator source field, this table is not used further.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux_bp</tt> dictionary, the derived spectrum can be plotted (Figure 7); for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
<pre style="background-color: #AAffff;"><br />
Note that the use of IPython in the command line requires the use of "%cpaste" to allow<br />
copy/pasting of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the<br />
end, this stops (or exits) the copy/paste prompt and will return you to the CASA prompt.<br />
</pre><br />
<br />
<source lang="python"><br />
# In CASA, use python code to plot the model spectrum of the bandpass calibrator:<br />
<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux_bp['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux_bp['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
The model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] is used to fill the ''<tt>MODEL</tt>'' column with the banpass source's spectral information using [https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy]. With ''standard='fluxscale''', we can directly use the <tt>flux_bp</tt> Python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA, insert the spectral information for the bandpass calibrator field:<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux_bp);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA, display the spectral model of the bandpass calibrator field, in this<br />
# case for a specific baseline (which should be identical for all baselines<br />
# for a point-like source, otherwise it will depend on baseline length):<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== D) Create a New Bandpass Using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, redo the previous calibration using this new model information. Although the commands are the same as issued earlier, keep in mind that the model values for the bandpass calibrator have changed and, therefore, the results of these calibration calculations accordingly will differ if the specral index differs significanlty from zero:<br />
<br />
<source lang="python"><br />
# In CASA, redo a phase-only self-calibration on the bandpass calibrator:<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA, re-determine residual delays from the bandpass calibrator scans:<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA, re-determine the bandpass from the bandpass calibrator scans:<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA, display and check the bandpass solutions; first range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
# second range, amplitude:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
# first range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
# second range, phase:<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
They look virtually unchanged from the previous solutions with the exception that the amplitude scaling is corrected for the spectrum of the bandpass calibrator. These steps yielded the final version of the delay and bandpass calibration tables, '''cal.dly.redo''' and '''cal.bp.redo''', which now would be used for all subsequent calibration steps. <br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--></div>Lsjouwerhttps://casaguides.nrao.edu/index.php?title=VLA_CASA_Bandpass_Slope-CASA6.4.1&diff=34054VLA CASA Bandpass Slope-CASA6.4.12023-01-18T17:37:11Z<p>Lsjouwer: </p>
<hr />
<div><b>This CASA Guide is for CASA version 6.4.1</b><br />
<br />
<pre style="background-color: #AAffff;"><br />
If new to CASA, or to VLA data reduction in CASA,<br />
</pre> <br />
it is '''strongly''' recommended to start with<br />
the [https://casaguides.nrao.edu/index.php?title=Getting_Started_in_CASA Getting Started in CASA] guide,<br />
the [https://casaguides.nrao.edu/index.php/VLA_high_frequency_Spectral_Line_tutorial_-_IRC%2B10216-CASA6.5.2 IRC+10216 spectral line tutorial],<br />
or the [https://casaguides.nrao.edu/index.php/VLA_Continuum_Tutorial_3C391-CASA6.4.1 VLA 3C391 Continuum Tutorial]<br />
<pre style="background-color: #AAffff;"><br />
before proceeding with this tutorial.<br />
</pre> <br />
Also note that this guide is meant to be used with monolithic CASA and not pip-wheel, because the GUIs have not been validated.<br />
<pre style="background-color: #98FB98;"><br />
This tutorial uses the default calibrator model distributed with this version.<br />
A different CASA version or update may include a different model than used here,<br />
in particular in the Ka-band (a.k.a. A-band), i.e., in the 28-40 GHz range. <br />
The plots and results will be different than in this guide in those cases.<br />
</pre><br />
<br />
<br />
<br />
== Overview ==<br />
<br />
For the standard VLA flux density calibrators 3C138, 3C147, 3C286 and<br />
3C48, the CASA distribution includes angular and spectral models that<br />
are referenced during calibration (but see the note in bright lime<br />
green at the top of this tutorial). The models account for the<br />
observational source characteristics, resulting in improved<br />
calibration solutions that therefore more accurately represent the<br />
instrumental and atmospheric corrections. These VLA standard<br />
calibrators, however, exhibit a negative spectral index (i.e., flux<br />
density decreasing with increasing frequency) and become relatively<br />
weak at high frequencies.<br />
<br />
Although the standard VLA flux density calibrators are usually still<br />
sufficiently bright enough for absolute flux density calibration even<br />
at the higher frequency bands, a good bandpass determination &mdash;<br />
which is important for spectral line observations or measuring the<br />
spectral index of continuum sources &mdash; may require higher<br />
signal-to-noise ratio bandpass solutions derived from either a long<br />
integration time or a very bright source (refer to the<br />
[https://science.nrao.edu/facilities/vla/docs/manuals/obsguide/modes/line#section-8 Spectral Line (Bandpass Setup) section within the Guide to Observing with the VLA]).<br />
Generally, instead of a long integration on a fainter source,<br />
additional observations of non-standard, but bright bandpass<br />
calibrators are used. Unfortunately, the spectral characteristics of<br />
these sources will be undetermined, and no ''a-priori'' flux density<br />
model is available. If not accounted for, using undetermined spectral<br />
behavior will introduce bias in the bandpass calibration.<br />
<br />
Whereas there are different ways of doing this depending on the<br />
trade-off one chooses to make, here, instead of using a bandpass<br />
determined from the standard flux density calibrator that might be<br />
noisier and transferring this noise to the target source, a less noisy<br />
bandpass from a different source is applied. To avoid bias to an<br />
undesired and initially unknown spectral index of that source, one<br />
needs to determine and model its spectral behavior so that it can be<br />
taken out during the determination of the bandpass using this brighter<br />
(higher signal-to noise) source.<br />
<br />
This tutorial describes how to determine the spectral characteristics<br />
for a point like (!) source and how to correct the bandpass solution<br />
for such an effect using alternative bandpass calibrator sources. For<br />
that follow these four general steps (below) to obtain a bandpass and<br />
delay calibration as determined from a non-standard bandpass<br />
calibrator source, and avoid including the (higher) noise of the flux<br />
density calibrator in the bandpass:<br />
<br />
<pre style="background-color: #fffacd;"><br />
1) After a phase-only self-calibration iteration, determine a good delay and bandpass<br />
calibration using the alternative bandpass calibrator.<br />
2) Use this first order bandpass calibration to calibrate the standard flux densty<br />
calibrator using the the non-standard bandpass calibrator source. This will bias the<br />
standard flux density calibrator observations with the spectral features of the<br />
bandpass calibrator.<br />
3) Compare the newly self-calibrated and initial bandpass-corrected non-standard bandpass<br />
calibrator fluxes (as function of frequency) with the self-calibrated and initial<br />
bandpass-corrected standard flux density calibrator. Fitting these fluxes will yield<br />
the spectral characteristics, including the spectral index of the bandpass calibrator. <br />
4) With this spectral index model, determine a new, second order delay and bandpass<br />
calibration using the non-standard bandpass calibrator source.<br />
<br />
This method thus does not use the flux density calibrator for bandpass calibration; the<br />
flux density calibrator is only used for obtaining the model spectral behavior of the<br />
alternative bandpass calibrator.<br />
</pre><br />
<br />
These resulting delay and bandpass solution tables then can be applied<br />
to the rest of the (target) data.<br />
<br />
<br />
== Obtaining the Data and Starting CASA ==<br />
<br />
The data used in this guide are taken for a target field in Ka-band<br />
with four 2-GHz basebands paired to two chunks of 4 GHz contiguous<br />
frequency coverage centered at 29 and 36.5 GHz for a total of 8 GHz<br />
frequency coverage. That is, each baseband consists of a series of 16<br />
consecutive 128-MHz subbands "attached" to another baseband for a<br />
total of 64 individual spectral windows.<br />
<br />
As this tutorial only concerns bandpass calibration, all scans on<br />
fields other than the flux density and bandpass calibrator fields were<br />
removed from the measurement set (MS). All pre-calibration steps<br />
including flagging, antenna position offsets, requantizer gains,<br />
opacity corrections, and gain-elevation curves were applied. The<br />
original data<br />
(<tt>TVER0004.sb14459364.eb14492359.56295.26287841435</tt>) can be<br />
obtained through the [https://data.nrao.edu NRAO archive] and has a<br />
raw size of 57.04 GB.<br />
<br />
The trimmed measurement set used here can be downloaded directly from<br />
[http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz http://casa.nrao.edu/Data/EVLA/G192/G192-BP.ms.tar.gz] (dataset size: 3.4 GB).<br />
<br />
The first step will be to uncompress and untar the file in a terminal<br />
(before starting CASA):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
tar -xzf G192-BP.ms.tar.gz <br />
</pre><br />
<br />
Then move to the working directory (if not the same as the location of<br />
the raw data) and optionally move/copy or link the data to a preferred<br />
shortcut name. This is particularly useful if the original observation<br />
name has it's full extent like<br />
''TVER0004.sb14459364.eb14492359.56295.26287841435'', for example:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
ln -s <path-to-data>/G192-BP.ms my-vis.ms <br />
</pre><br />
<br />
To start CASA, type:<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
casa<br />
</pre><br />
<br />
or better, to make sure to be running the CASA version for which this<br />
tutorial was designed (list the installed versions to choose from by<br />
typing ''casa -ls''):<br />
<br />
<pre style="background-color:lightgrey;"><br />
# in a terminal, outside of CASA:<br />
casa -r 6.4.1-12-pipeline-2022.2.0.64<br />
</pre><br />
<br />
This will initialize CASA and set the necessary paths appropriately.<br />
This will also create two files; one is<br />
''ipython-<unique-timestamp>.log'' which contains a record of all the<br />
text entered at the CASA prompt, and another as<br />
''casapy-<unique-timestamp>.log'' which will contain all the messages<br />
that are printed to the CASA logger window. It is recommended to keep<br />
these log files intact as a reminder of the steps completed in the<br />
data reduction. These log files may also be helpful when submitting a<br />
helpdesk ticket.<br />
<br />
Once CASA has started, a logger window will appear. Note that this<br />
window can be rescaled and the font size can be changed as desired;<br />
see the options under the '''View''' menu. I personally like to remove<br />
clutter columns by moving the mouse to the logger window and press<br />
"Ctrl-N", "Ctrl-Y","Ctrl-E", (''N''ew ''Y''ears ''E''ve is one way to<br />
remember).<br />
<br />
== Examining the Measurement Set (MS) ==<br />
<br />
In order to proceed it is important to know the details of the<br />
observation as capruted in the data set. Typical pieces of information<br />
to look for are the calibrator sources (with their intents), and<br />
finding a reference antenna, next to the overal structure of the<br />
frequency setup and sequence of observing scans (fields). Furthermore,<br />
at this stage it is also useful to set the flux model for the standard<br />
flux density calibrator, although that can be done at later stages<br />
too; it is done here to finish up the preparations before doing the<br />
actual bandpass calibration procedure.<br />
<br />
From here on in this tutorial, the ''G192-BP.ms'' name in the<br />
directory will be replaced by the variable value stored in ''id_ms''<br />
(identify-the-MS). This makes the instructions below less dependent on<br />
the actual name of the data root so that if another measurement set<br />
name is used, only the definition here needs to be edited to the other<br />
file name. In order to do that first define these parameters as<br />
variables inside of CASA:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA<br />
visbase = 'G192-BP' (or whatever base name the data set or link to be used has, like "my-vis" above)<br />
id_ms = visbase + '.ms' (this should match and find the measurement set created earlier)<br />
</pre><br />
<br />
'''Frequency setup, calibrator intents, scan listing, etc'''<br />
<br />
Use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.information.listobs.html listobs] to summarize the MS:<br />
<source lang="python"><br />
# In CASA: listobs on the initial data set<br />
listobs(vis=id_ms, listfile=visbase+'_list.txt');<br />
</source><br />
<br />
*Note the use of a semicolon (i.e., '';'') after the parentheses. This will prevent the return dictionary to be printed in the terminal.<br />
<br />
This will write the ''listobs'' output of the input MS (stored as the<br />
variable id_ms) to a file called <tt><visbase>_list.txt</tt>, which<br />
can be examined using various operating system tools in a terminal, or<br />
within CASA by using an explanation mark '''(!)''' before the command,<br />
such as <tt>cat</tt>, <tt>less</tt>, or <tt>more</tt>. Preferably use<br />
an editor and keep it on the desktop for frequent consultation with<br />
e.g. <tt>emacs</tt>, <tt>vi</tt>, or <tt>nedit</tt>:<br />
<br />
<source lang="python"><br />
# In CASA, e.g.<br />
!emacs <visbase>_list.txt<br />
</source><br />
<br />
<pre style="background-color: #fffacd;"><br />
================================================================================<br />
MeasurementSet Name: <path-to-data>/<visbase>.ms MS Version 2<br />
================================================================================<br />
Observer: Dr. Observer Project: uid://evla/pdb/7303457 <br />
Observation: EVLA<br />
Data records: 1769355 Total elapsed time = 4563 seconds<br />
Observed from 03-Jan-2013/06:31:48.0 to 03-Jan-2013/07:47:51.0 (UTC)<br />
<br />
ObservationID = 0 ArrayID = 0<br />
Date Timerange (UTC) Scan FldId FieldName nRows SpwIds Average Interval(s) ScanIntent<br />
03-Jan-2013/06:31:48.0 - 06:36:42.0 6 0 3C147 704865 [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5.94, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_FLUX#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
07:40:27.0 - 07:47:51.0 64 1 3c84-J0319+413 1064490 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63] [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6] [CALIBRATE_BANDPASS#UNSPECIFIED,OBSERVE_TARGET#UNSPECIFIED]<br />
(nRows = Total number of rows per scan) <br />
Fields: 2<br />
ID Code Name RA Decl Epoch SrcId nRows<br />
0 E 3C147 05:42:36.137916 +49.51.07.23356 J2000 0 704865<br />
1 F 3c84-J0319+413 03:19:48.160102 +41.30.42.10305 J2000 1 1064490<br />
Spectral Windows: (64 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_KA#A1C1#2 128 TOPO 34476.000 1000.000 128000.0 34539.5000 10 RR LL<br />
1 EVLA_KA#A1C1#3 128 TOPO 34604.000 1000.000 128000.0 34667.5000 10 RR LL<br />
2 EVLA_KA#A1C1#4 128 TOPO 34732.000 1000.000 128000.0 34795.5000 10 RR LL<br />
3 EVLA_KA#A1C1#5 128 TOPO 34860.000 1000.000 128000.0 34923.5000 10 RR LL<br />
<snip><br />
13 EVLA_KA#A1C1#15 128 TOPO 36140.000 1000.000 128000.0 36203.5000 10 RR LL<br />
14 EVLA_KA#A1C1#16 128 TOPO 36268.000 1000.000 128000.0 36331.5000 10 RR LL<br />
15 EVLA_KA#A1C1#17 128 TOPO 36396.000 1000.000 128000.0 36459.5000 10 RR LL<br />
16 EVLA_KA#A2C2#18 128 TOPO 36476.000 1000.000 128000.0 36539.5000 11 RR LL<br />
17 EVLA_KA#A2C2#19 128 TOPO 36604.000 1000.000 128000.0 36667.5000 11 RR LL<br />
18 EVLA_KA#A2C2#20 128 TOPO 36732.000 1000.000 128000.0 36795.5000 11 RR LL<br />
<snip><br />
29 EVLA_KA#A2C2#31 128 TOPO 38140.000 1000.000 128000.0 38203.5000 11 RR LL<br />
30 EVLA_KA#A2C2#32 128 TOPO 38268.000 1000.000 128000.0 38331.5000 11 RR LL<br />
31 EVLA_KA#A2C2#33 128 TOPO 38396.000 1000.000 128000.0 38459.5000 11 RR LL<br />
32 EVLA_KA#B1D1#34 128 TOPO 26976.000 1000.000 128000.0 27039.5000 13 RR LL<br />
33 EVLA_KA#B1D1#35 128 TOPO 27104.000 1000.000 128000.0 27167.5000 13 RR LL<br />
34 EVLA_KA#B1D1#36 128 TOPO 27232.000 1000.000 128000.0 27295.5000 13 RR LL<br />
<snip><br />
45 EVLA_KA#B1D1#47 128 TOPO 28640.000 1000.000 128000.0 28703.5000 13 RR LL<br />
46 EVLA_KA#B1D1#48 128 TOPO 28768.000 1000.000 128000.0 28831.5000 13 RR LL<br />
47 EVLA_KA#B1D1#49 128 TOPO 28896.000 1000.000 128000.0 28959.5000 13 RR LL<br />
48 EVLA_KA#B2D2#50 128 TOPO 28976.000 1000.000 128000.0 29039.5000 14 RR LL<br />
49 EVLA_KA#B2D2#51 128 TOPO 29104.000 1000.000 128000.0 29167.5000 14 RR LL<br />
50 EVLA_KA#B2D2#52 128 TOPO 29232.000 1000.000 128000.0 29295.5000 14 RR LL<br />
<snip><br />
61 EVLA_KA#B2D2#63 128 TOPO 30640.000 1000.000 128000.0 30703.5000 14 RR LL<br />
62 EVLA_KA#B2D2#64 128 TOPO 30768.000 1000.000 128000.0 30831.5000 14 RR LL<br />
63 EVLA_KA#B2D2#65 128 TOPO 30896.000 1000.000 128000.0 30959.5000 14 RR LL<br />
<br />
Sources: 128<br />
ID Name SpwId RestFreq(MHz) SysVel(km/s) <br />
0 3C147 0 - - <br />
0 3C147 1 - - <br />
0 3C147 2 - - <br />
<snip><br />
0 3C147 61 - - <br />
0 3C147 62 - - <br />
0 3C147 63 - - <br />
1 3c84-J0319+413 0 - - <br />
1 3c84-J0319+413 1 - - <br />
1 3c84-J0319+413 2 - - <br />
<snip><br />
1 3c84-J0319+413 61 - - <br />
1 3c84-J0319+413 62 - - <br />
1 3c84-J0319+413 63 - - <br />
<snip><br />
Antennas: 22:<br />
ID Name Station Diam. Long. Lat. Offset from array center (m) ITRF Geocentric coordinates (m) <br />
East North Elevation x y z<br />
1 ea02 N56 25.0 m -107.37.47.9 +34.00.38.4 -1105.2071 12254.3069 -34.2426 -1600128.383400 -5035104.146500 3565024.672100<br />
2 ea03 N16 25.0 m -107.37.10.9 +33.54.48.0 -155.8511 1426.6436 -9.3827 -1601061.956000 -5041175.880700 3556058.037600<br />
3 ea05 W08 25.0 m -107.37.21.6 +33.53.53.0 -432.1184 -272.1472 -1.5070 -1601614.092200 -5042001.650900 3554652.508900<br />
<snip><br />
</pre><br />
<br />
This redacted MS contains only scans on the flux density calibrator<br />
3C147 (field 0) and the bandpass calibrator 3C84 (field 1). Both<br />
fields have 64 spectral windows (spws); each spw consists of 128 dual<br />
(RR, LL) polarization 1 MHz wide channels, for a total bandwidth of<br />
128 MHz per spw.<br />
<br />
As the intents for these fields are clearly included in the scan<br />
listing (''CALIBRATE_FLUX'' and ''CALIBRATE_BANDPASS''), for<br />
convenience now introduce new variables to recall the general use of<br />
these intents without having to remember their details like field ID<br />
numbers or name strings &mdash; variable names aren't string-values so<br />
therefore using them also avoids typing the quotes when filling in<br />
task parameters (as will be seen in most of the below):<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA<br />
id_flx = '3C147' (or '0' for using the field name or field ID respectively)<br />
id_bp = '3c84-J0319+413' (or '1')<br />
</pre><br />
<br />
<br />
'''Selecting a reference antenna form the array configuration'''<br />
<br />
As a first step, a reference antenna for all phase calibrations needs<br />
to be specified. Since observations were performed with the VLA in the<br />
most extended A-configuration, it is desirable to use an antenna that<br />
is near the center of the array. Futhermore, it needs to have valid<br />
calibrator data on all baselines with the least amount of data<br />
flagged. The array can be mapped with<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html plotants]:<br />
<br />
<source lang="python"><br />
# In CASA: plotting antenna locations<br />
plotants(vis=id_ms)<br />
</source><br />
<br />
Although the plot is a bit crowded (Figure 2), zooming in with the<br />
magnifying glass icon shows that antenna "ea05" is located close to<br />
the center. Using the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotants.html flagdata] task with mode='summary' it can be seen that "ea05" has<br />
small number of flags. Therefore, this antenna can be used relatively<br />
safely as the reference antenna; for convenience (and for people with<br />
memory issues) introduce a variable name for it:<br />
<br />
<pre style="background-color: #d8bfd8;"><br />
# In CASA:<br />
id_ref = 'ea05' (or '3' or 'W08' which are the antenna ID number or pad name for ea05)<br />
</pre><br />
<br />
<br />
[[Image:plotG192_plotants.png|200px|thumb|right|Figure 2: Antenna<br />
locations plotted with plotants() task.]]<br />
<br />
'''Setting the Model of the Flux Density Calibrator'''<br />
<br />
<br />
To start preparing for a flux comparison later (in step 3 above),<br />
insert the spectral and angular models for the flux density<br />
calibrator, here 3C147 (field 0), with the<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] task. Use the 'Perley-Butler 2017' standard and 3C147_A.im for<br />
Ka-band (which can be written as ''id_flx+'_A.im'' because here<br />
fortunately id_flx and the model name agree):<br />
<br />
<source lang="python"><br />
# In CASA: model for the flux density calibrator<br />
setjy(vis=id_ms, field=id_flx, scalebychan=True,<br />
standard='Perley-Butler 2017', model=id_flx+'_A.im');<br />
</source><br />
<br />
* <tt>scalebychan=True</tt>: If ''scalebychan=False'' [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.imaging.setjy.html setjy] would use a single value per spectral window.<br />
<br />
[[Image:PlotG192_setjy.png|200px|thumb|right|Figure 1: plotms() output<br />
for model amplitudes as function of freqency for the flux density<br />
calibrator 3C147]]<br />
<br />
Inspecting the logger report shows that the flux density calibrator<br />
(3C147 here) has amplitudes ranging from about 1.0 to about 1.5 Jy<br />
across the spws. (Note the output sorting in increasing spw number,<br />
not in frequency.)<br />
<br />
The model data can be plotted, e.g. for antenna 'ea03', using<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.visualization.plotms.html plotms] (Figure 1):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=id_ms, field=id_flx, antenna='ea03', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model',coloraxis='ant2')<br />
</source><br />
<br />
This plot shows baselines to antenna "ea03". Since both a spectral and<br />
an angular model for this well resolved calibrator was provided, each<br />
baseline has a somewhat different amplitude and phase behavior as<br />
function of frequency.<br />
<br />
== 1) Calibrating Initial Delays and Bandpass Solutions ==<br />
<br />
Start this calibration with a phase-only, time-dependent (self-)calibration<br />
solution for the bandpass calibrator, which should be easy for these<br />
supposedly bright sources. Note that the calibration solutions are<br />
written to a calibration table, <tt>cal.ign</tt>, where 'ign' stands<br />
for per-integration gain. This table is not a variable but a<br />
string/name so it needs to be quoted in the input parameter. Solutions<br />
for each integration will remove most of the (phase) decorrelation of<br />
the signal. For best results, the phase variations will be derived<br />
from a narrow range of channels (say 60~68 here, out of the 128<br />
available per spw) near the centers of each spw, narrow enough to not<br />
be affected by uncorrected delay (i.e., reduce possible decorrelation<br />
by excluding any large phase differences due to a phase slope over the<br />
frequency range of the spw):<br />
<br />
<source lang="python"><br />
# In CASA: phase only calibration<br />
gaincal(vis=id_ms, caltable='cal.ign', <br />
field=id_bp, spw='*:60~68',<br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3)<br />
</source><br />
<br />
* <tt>refant=id_ref</tt> : Use the variable identifying the reference antenna (ea05 here) as the reference antenna.<br />
* <tt>solint='int'</tt> : Do a per-integration solve (every 6 seconds, which is the time-averaging applied to the data for this tutorial).<br />
* <tt>minsnr=3</tt> : Apply a minimum signal-to-noise cutoff of three. Solutions with less signal-to-noise than this value will be flagged.<br />
* <tt>gaintable</tt> is not set here as earlier calibrations (to prepare for this tutorial have already been applied.<br />
<br />
<br />
Plot the phase solutions (using full phase range -180 to 180 instead<br />
of autorange):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
iteraxis='antenna', plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
Note that antenna the first plot showing the results for ea01 is empty<br />
as ea01 previously was fully flagged, and so were ea10 and ea19. Click<br />
on the green arrows to pass through the plots for the other<br />
antennas. Also note that the reference antenna (ea05 here) has all<br />
phases equal to zero degrees, which they should be by definition for<br />
the reference antenna.<br />
<br />
Multipanel plots of the phase solutions can be written to output files<br />
as well as to the screen display (Figures 3a, 3b, & 3c). The output<br />
files that are generated are PNG files and can be viewed at any<br />
occasion using CASA by executing an external viewer program, e.g.,<br />
<tt>!xv <visbase>_cal.ign_p1*.png</tt>; or by running an image viewing<br />
application such as xv, Preview, Gimp, Photoshop, etc., external to<br />
CASA at the operating system level. <!-- (Note that the hardcopy only<br />
shows the first page): --><br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase',<br />
antenna='0~11', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p1.png', width=1300, height=800)<br />
</source><br />
<br />
* <tt>width=1300</tt> and <tt>height=800</tt> specify the output PNG pixel dimensions.<br />
<br />
<pre style="background-color: #98FB98;"><br />
Note that recently the name of the output file gets appended with the selection of the iteraxis and there unfortunately seems to be no possibility to switch that off; to get the file name as specified in the plotfile-parameter one would edit the file name using the operating system tools.<br />
</pre><br />
<br />
<source lang="python"><br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='12~20', gridrows=3, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p2.png', width=1300, height=800)<br />
<br />
#<br />
plotms(vis='cal.ign', xaxis='time', yaxis='phase', <br />
antenna='21~26', gridrows=2, gridcols=3, iteraxis='antenna',<br />
coloraxis='spw',<br />
plotfile=visbase+'_cal.ign_p3.png', width=1300, height=800)<br />
<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_phasecal_G0p1.png|200px|thumb|left|Figure 3a: Gain phase calibration solutions for antennas ea01 to ea11]]<br />
| [[Image:plotG192_phasecal_G0p2.png|200px|thumb|center|Figure 3b: Gain phase calibration solutions for antennas ea12 to ea20]]<br />
| [[Image:plotG192_phasecal_G0p3.png|200px|thumb|right|Figure 3c: Gain phase calibration solutions for antennas ea21 to ea26]]<br />
|}<br />
<br />
<br />
The next step is to solve for the residual delays using the parameter<br />
''gaintype='K' ''option in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] and store the solutions in the <tt>cal.dly</tt> table. Note<br />
that this currently does not do a global fringe-fitting solution for<br />
delays. Instead it determines a baseline-based delay solution per spw<br />
for all baselines to the reference antenna, treating these as<br />
antenna-based delays. In most cases, with high enough S/N to get<br />
baseline-based delay solutions, this will suffice. Avoid the edge<br />
channels of each spectral window by de-selecting them (say select<br />
channels 5~122 here, from the 128 available per spw):<br />
<br />
<source lang="python"><br />
# In CASA: residual delays<br />
gaincal(vis=id_ms, caltable='cal.dly', <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
gaintable=['cal.ign'],<br />
refant=id_ref, solint='inf', minsnr=3)<br />
</source><br />
<br />
Note that we are now applying our initial phase table <tt>cal.ign</tt><br />
to reduce decorrelation due to short-term phase fluctuations (as they<br />
will be corrected by the solutions in ''cal.ign'').<br />
<br />
Alternatively, one can derive a delay across all spws of a<br />
baseband. If this is desired, use parameter ''combine='spw''' in<br />
[https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.gaincal.html gaincal] and run the task for each baseband separately. The solutions<br />
from the second and following runs can be appended to the same<br />
calibration table via parameter ''append=True''.<br />
<br />
[[Image:plotG192_delays.png|200px|thumb|right|Figure 4: Antenna based<br />
delays after running gaincal().]]<br />
<br />
Now plot the delays, in nanoseconds, as a function of antenna index<br />
(you will get one for each spw and polarization):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='cal.dly', xaxis='ant1', yaxis='delay', coloraxis='spw')<br />
</source><br />
<br />
The delays range from around -5 to 4 nanoseconds (Figure 4).<br />
<br />
Now solve for the antenna bandpasses using the previously generated<br />
tables <tt>cal.ign</tt> and <tt>cal.dly</tt> correcting for possible<br />
decorrelation due to phase and delay inaccuracies, and store the<br />
solutions in <tt>cal.bp</tt>:<br />
<br />
<source lang="python"><br />
# In CASA: antenna bandpasses<br />
bandpass(vis=id_ms, caltable='cal.bp', <br />
gaintable=['cal.ign', 'cal.dly'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
'''WARNING''': Set <tt>solnorm=False</tt> here; otherwise there will<br />
be some offsets seen later between spws due to the way the amplitude<br />
scaling adjusts weights internally during solving.<br />
<br />
<br />
Expect to see solutions failing due to "Insufficient unflagged<br />
antennas" &mdash; these are for bad channels that have been<br />
pre-flagged.<br />
<br />
Plot the amplitude and phase soutions of this new bandpass. Note that<br />
the first panel with ea01 is empty as it is completely<br />
flagged. Proceed to ea06 to see the plots as shown in Figures 5a, 5b,<br />
6a, and 6b:<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
#<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
#<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
#<br />
plotms(vis='cal.bp', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.png|200px|thumb|left|Figure 5a: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31.]]<br />
| [[Image:plotG192_amp_B0a2.png|200px|thumb|center|Figure 5b: Gain amplitude bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
| [[Image:plotG192_phase_B0p1.png|200px|thumb|center|Figure 6a: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 0 to 31]]<br />
| [[Image:plotG192_phase_B0p2.png|200px|thumb|right|Figure 6b: Gain phase bandpass calibration solutions for antenna ea06 in spectral windows from 32 to 63.]]<br />
|}<br />
<br />
== 2) Apply the Initial Bandpass Solutions to the Flux Density Calibrator ==<br />
<br />
<br />
Since there is no ''a priori'' spectral information for the chosen<br />
bandpass calibrator (here 3C84), bootstrapping it is needed to<br />
determine its spectral index. This information is then used to<br />
recalibrate the bandpass in order to avoid folding the intrinsic<br />
spectral shape of the bandpass calibrator into the bandpass<br />
calibration.<br />
<br />
First, repeat the phase-only calibration solution, this time for both<br />
the bandpass and the flux density calibrator (which need to be<br />
separated by a comma) and store the solutions in <tt>cal.ign2pha</tt><br />
(use the ''2pha'' to distinguish it as the second stage for<br />
phase-only). This will correct for short-term phase decorrelation of<br />
the signals. Similarly to avoid decorrelation due to a wide frequency<br />
range, use the narrow center channel range (which was channel 60~68)<br />
and apply the bandpass and delay calibration tables:<br />
<br />
<source lang="python"><br />
# In CASA: flux and bandpass calibrators gain<br />
gaincal(vis=id_ms, caltable='cal.ign2pha', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp'], <br />
gaintype='G', refant=id_ref, calmode='p', solint='int', minsnr=3)<br />
</source><br />
<br />
This again allows to calibrate both phase and gain for each scan, now<br />
corrected with the delay and bandpass of the bandpass. Store the<br />
solutions in <tt>cal.ign2</tt> (use the ''2'' to distinguish it as the<br />
second stage gain calibration):<br />
<br />
<source lang="python"><br />
# In CASA: flux and bandpass calibrators gain<br />
gaincal(vis=id_ms, caltable='cal.ign2', field=id_flx+','+id_bp, <br />
gaintable=['cal.dly', 'cal.bp','cal.ign2pha'], <br />
gaintype='G', refant=id_ref, calmode='ap', solint='inf', minsnr=3)<br />
</source><br />
<br />
<!--<br />
Let's have a look at the phase and amplitude solutions, iterating over antenna. We will look at the flux density calibrator (3C147, id_flx) and bandpass calibrator (3C84, id_bp) individually since they're widely separated in time:<br />
<source lang="python"><br />
# In CASA<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_flx, iteration='antenna')<br />
#<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='amp', <br />
field=id_bp, iteration='antenna')<br />
#<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_flx)<br />
#<br />
plotcal(caltable='cal.ign2', xaxis='time', yaxis='phase', <br />
iteration='antenna', plotrange=[-1,-1,-180,180], <br />
field=id_bp)<br />
</source><br />
<br />
The solutions all look reasonable and relatively constant with time. <br />
--><br />
<br />
== 3) Bootstrapping the Bandpass Calibrator Field Spectrum ==<br />
<br />
With gain solutions for the flux density and bandpass calibrators, now use [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] to scale the gain amplitudes of the bandpass calibrator using those of the flux density calibrator. Store the solutions in <tt>cal.flx2</tt> and the model for the bandpass calibrator in <tt><visbase>+'_'+id_bp+'_fluxinfo.txt'</tt>:<br />
<br />
<br />
<source lang="python"><br />
# In CASA: bandpass calibrator gain amplitudes scaling<br />
flux1 = fluxscale(vis=id_ms, caltable='cal.ign2', <br />
fluxtable='cal.flx2', reference=id_flx, transfer=id_bp, <br />
listfile=visbase+'_'+id_bp+'_fluxinfo.txt', fitorder=1)<br />
</source><br />
* <tt>flux1 = fluxscale(...)</tt>: the Python dictionary returned by the [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] task will be stored in the <tt>flux1</tt> variable. Inspect the dictionary flux1 by typing "print flux1" at the CASA command line. Alternatively, when not interested in the dictionary type ''fluxscale(...);'' with a semicolon after the parentheses and not assigning it to a variable. This will prevent the dictionary to be printed in the terminal. Here however the dictionary is captured in flux1 as it is going to be used below<br />
* <tt>fluxtable='cal.flx2'</tt>: this is the output scaled gain table. Since we are only using this to find the spectral index of the bandpass calibrator source field, we won't be using this table.<br />
* <tt>listfile=visbase+'_'+id_bp+'_fluxinfo.txt'</tt>: an output file that contains the derived flux values and fit information.<br />
* <tt>fitorder=1</tt>: only find a (linear) spectral index, ignoring curvature in the spectrum.<br />
* <tt>reference=id_flx</tt>: the reference field ''from'' which the flux scaling is transferred (here: the flux density calibrator 3C147, field 0, assigned by id_flx)<br />
* <tt>transfer=id_bp</tt>: the target field ''to'' which the flux scaling is transferred (here: the bandpass calibrator 3C84, field 1, assigned by id_bp)<br />
<br />
<br />
The last line in the file (and displayed in the logger) shows:<br />
<pre style="background-color: #fffacd;"><br />
Fitted spectrum for 3c84-J0319+413 with fitorder=1: Flux density = 29.0286 +/- 0.0308709 (freq=32.5128 GHz) spidx=-0.538803 +/- 0.00883078<br />
</pre><br />
<br />
[[Image:PlotG192-3C84-fluxspec-4.5.png|200px|thumb|right|Figure 7: Bootstrapped 3C84 flux density spectrum.]]<br />
<br />
Using the information in the returned <tt>flux1</tt> dictionary, we can plot the derived spectrum seen in Figure 7; for that the two loops below fill the parameter variables used in the plotting:<br />
<br />
(Note, IPython 5.1.0 requires the use of "%cpaste" to allow the copy/paste of loops, conditions, etc.. Press "Enter" (or "Return") after "--" at the end, this stops (or exits) the copy/paste prompt and will return you to the CASA prompt.) <br />
<br />
<source lang="python"><br />
# In CASA<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
freq = flux1['freq'] / 1e9<br />
spw_list = range(0,64)<br />
spw_str = []<br />
for i in spw_list:<br />
thisspw = str(i)<br />
spw_str.append(thisspw)<br />
--<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
bootstrapped_fluxes = []<br />
for j in spw_str:<br />
thisflux = flux1['1'][j]['fluxd'][0]<br />
if thisflux ==None:<br />
continue<br />
else:<br />
bootstrapped_fluxes.append(thisflux)<br />
--<br />
</source><br />
<br />
<source lang="python"><br />
# In CASA - this section creates the plot seen in Figure 7<br />
import matplotlib.pyplot as pl<br />
%cpaste<br />
<br />
# Press Enter or Return, then copy/paste the following:<br />
pl.clf()<br />
pl.plot(freq, bootstrapped_fluxes, 'bo')<br />
pl.xlabel('Frequency (GHz)')<br />
pl.ylabel('Flux Density (Jy)')<br />
pl.title(id_bp)<br />
pl.show()<br />
--<br />
</source><br />
<br />
We can use the model from [https://casadocs.readthedocs.io/en/v6.4.1/api/tt/casatasks.calibration.fluxscale.html fluxscale] to fill the MODEL column with the banpass source's spectral information using [https://casadocs.readthedocs.io/en/v6./4.1api/tt/casatasks.imaging.setjy.html setjy]. With ''standard='fluxscale''', we can directly use the <tt>flux1</tt> Python dictionary as input via ''fluxdict'':<br />
<br />
[[Image:ScreenshotPlotG192-setjy-bp-4.5.png|200px|thumb|right|Figure 8: Model amplitude of 3C84 as a function of frequency.]]<br />
<br />
<source lang="python"><br />
# In CASA: spectral information<br />
setjy(vis=id_ms, field=id_bp, scalebychan=True, <br />
standard = 'fluxscale', fluxdict=flux1);<br />
</source><br />
<br />
Check with plotms that the data have been appropriately filled (Figure 8):<br />
<br />
<source lang="python"><br />
# In CASA<br />
plotms(vis=id_ms, field=id_bp, antenna='ea05&ea02', <br />
xaxis='freq', yaxis='amp', ydatacolumn='model')<br />
</source><br />
<br />
== 4) Create a New Bandpass Using the Bandpass Calibrator Spectral Model ==<br />
<br />
Next, we redo the previous calibration using this new model information. Although the commands are the same as issued earlier, keep in mind that the model values for the bandpass calibrator have changed and, therefore, the results of these calibration calculations will differ:<br />
<br />
<source lang="python"><br />
# In CASA: phase only recalibration<br />
gaincal(vis=id_ms, caltable='cal.ign.redo', <br />
field=id_bp, spw='*:60~68', <br />
gaintype='G', refant=id_ref, calmode='p', <br />
solint='int', minsnr=3) <br />
<br />
# In CASA: residual delays recalibration<br />
gaincal(vis=id_ms, caltable='cal.dly.redo', <br />
gaintable=['cal.ign.redo'], <br />
field=id_bp, spw='*:5~122', gaintype='K', <br />
refant=id_ref, solint='inf', minsnr=3)<br />
<br />
# In CASA: antenna bandpasses recalibration<br />
bandpass(vis=id_ms, caltable='cal.bp.redo', <br />
gaintable=['cal.ign.redo', 'cal.dly.redo'], <br />
field=id_bp, refant=id_ref, solnorm=False, <br />
bandtype='B', solint='inf')<br />
</source><br />
<br />
Finally, we inspect these solutions (Figures 9a, 9b, 10a, and 10b; again note that antenna ea01 is fully flagged):<br />
<br />
<source lang="python"><br />
# In CASA - Figure 9a<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw')<br />
<br />
#<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='amp', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw')<br />
<br />
#<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='0~31', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
<br />
#<br />
plotms(vis='cal.bp.redo', xaxis='freq', yaxis='phase', <br />
spw='32~63', iteraxis='antenna', coloraxis='spw', <br />
plotrange=[-1,-1,-180,180])<br />
</source><br />
<br />
{|<br />
| [[Image:plotG192_amp_B0a1.b.png|200px|thumb|left|Figure 9a: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_amp_B0a2.b.png|200px|thumb|center|Figure9b: Calibration solutions for the bootstrapped bandpass amplitudes for 3C84. Shown is antenna ea06 and spectral windows spw=32~63.]]<br />
| [[Image:plotG192_phase_B0p1.b.png|200px|thumb|center|Figure 10a: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=0~31.]]<br />
| [[Image:plotG192_phase_B0p2.b.png|200px|thumb|right|Figure 10b: Calibration solutions for the bootstrapped bandpass phases for 3C84. Shown is antenna ea06 and spectral windows spw=32-63.]]<br />
|}<br />
<br />
They look virtually unchanged from the previous solutions with the exception that the amplitude scaling is corrected for the spectrum of the bandpass calibrator. We have the final version of our delay and bandpass calibration tables, '''cal.dly.redo''' and '''cal.bp.redo''', which can be used for all subsequent calibration steps. <br />
<br />
{{Checked 6.4.1}}<br />
<!--<br />
-- Original: Miriam Hartman (full G192 guide) <br /><br />
-- Modifications: Jose Salcido (4.5.2. 2016/04/14) <br /><br />
-- Topical Guide: Juergen Ott (4.5.2, 2016/04/14) <br /><br />
-- Edits to Guide: Tony Perreault (4.5.2, 2016/05/18) <br /><br />
-- Edits to Guide: Heidi Medlin (5.0.0, 2017/07/20) <br /><br />
-- Edits to Guide: Alex Sobotka (5.4.0, 2018/10/10) <br /><br />
-- Edits to Guide: Anna Kapinska (5.5.0, 2019/06/28) <br /><br />
-- Edits to Guide: Trent Seelig (6.2.0, 2021/07/08) <br /><br />
-- Version for CASA 6.4.1, Lorant (Jan 2023),<br />
including more background explanation and now also defining<br />
standard variables for parameters: id_* for identifiers and<br />
cal.* for calibration tables <br /><br />
--></div>Lsjouwer