%-----------------------------------------------------------------------
%;  Copyright (C) 2010-2017
%;  Associated Universities, Inc. Washington DC, USA.
%;
%;  This program is free software; you can redistribute it and/or
%;  modify it under the terms of the GNU General Public License as
%;  published by the Free Software Foundation; either version 2 of
%;  the License, or (at your option) any later version.
%;
%;  This program is distributed in the hope that it will be useful,
%;  but WITHOUT ANY WARRANTY; without even the implied warranty of
%;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%;  GNU General Public License for more details.
%;
%;  You should have received a copy of the GNU General Public
%;  License along with this program; if not, write to the Free
%;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
%;  MA 02139, USA.
%;
%;  Correspondence concerning AIPS should be addressed as follows:
%;          Internet email: aipsmail@nrao.edu.
%;          Postal address: AIPS Project Office
%;                          National Radio Astronomy Observatory
%;                          520 Edgemont Road
%;                          Charlottesville, VA 22903-2475 USA
%-----------------------------------------------------------------------

\APPEN{Handling EVLA Data in \AIPS}{Special Considerations for EVLA
       Data Calibration and Imaging in \AIPS}{EVLAdata}
\renewcommand{\Chapt}{25}

\renewcommand{\titlea}{31-December-2017 (revised 22-November-2017)}
\renewcommand{\Rheading}{\AIPS\ \cookbook:~\titlea\hfill}
\renewcommand{\Lheading}{\hfill \AIPS\ \cookbook:~\titlea}
\markboth{\Lheading}{\Rheading}

The old VLA with its once state of the art, but now dated, correlator
and electronics has been turned off.  The new electronics and
correlator of the \Indx{EVLA}\footnote{Now officially called the Karl
G. Jansky Very Large Array, but called the EVLA here.} have been
turned on and made available to users.  Observing is now on the
customary terms although a ``Resident shared risk'' program is still
available for certain esoteric, not fully commissioned, capabilities.
Data may have many thousands of spectral channels and up to 8 GHz of
bandwidth per polarization.  \AIPS\ software is capable of handling
these data.

The EVLA has already produced amazing scientific results although the
large data volume has created difficulties.  Delays are sometimes not
set accurately, causing the data analysis to begin with the ``VLBI''
task {\tt FRING} needed to correct large slopes in phase across the
bandpass.  The flagging information known to the on-line system
(telescope off source and the like) is now available in the data
format and so can reach \AIPS\ either as an initial flag table or as
already flagged data.  Substantial flagging effort may therefore still
be required, particularly to deal with RFI which inevitably occurs in
the wide bandwidths.  System temperatures and gains are now
transferred, but should be applied with caution to scale the
visibilities and to compute data weights.  The data weights without
this adjustment reflect only integration time.  The weather table is
available with the data so that reasonable opacities may be determined.
However, the ``over-the-top'', table which is used in determining
antenna positions, the frequency offset table, used in managing
Doppler tracking, and the {\tt CQ} table, used to correct amplitudes
for spectral averaging in the presence of non-zero delays, are not
available if the data come to \AIPS\ via CASA\@.  The {\tt OT} table
is now provided when the data are read using the {\tt \tndx{OBIT}}
package, but astrometric data used to compute accurate projected
spacings are just now becoming available.

The following guide will not assume that all issues have been fixed.
Steps that can be omitted or simplified when they are will be
described.  This appendix is written with the assumption that the
reader is moderately familiar with \AIPS\ as described in the
preceding chapters.  It is also written with the assumption that you
are using current versions of the {\tt 31DEC11} or later releases of
the software.

\Sects{Getting your data into \AIPS}{bdf2aips}

Your \Indx{EVLA} data are stored as an ``ALMA Science Data Model''
(ASDM) format file in ``SDMBDF'' (Science Data Model Binary Data
Format) in the NRAO archive.  They may be read out of the archive in
that format, a CASA measurement set format, or in an \AIPS-friendly
uvfits format.  This last is produced by the CASA uvfits writing
software.  Go the the web page\\
      \centerline{{\tt http://archive.cv.nrao.edu/}}\\
and select the Advanced Query Tool.  Fill out enough of the form to
describe your data and submit the query.  If the data are not yet
public, you will need the Locked Project Access Key which may be
obtained from the NRAO data analysts.  To avoid the need for this key,
you may log in to {\tt my.nrao.edu} after which it will know if you
are entitled to access particular locked projects.  The query will
return a list of the data sets which meet your specifications.  {\it
(Users logged in to an NRAO Socorro computer should use a variant of
these instructions; see below.)}  On this form, enter your e-mail
address, choose AIPS Friendly names (almost certainly does not work),
AIPS FITS under the EVLA-WIDAR section and choose the desired time
averaging.  If the delays are not accurately known, spectral averaging
can be damaging to the data amplitudes.  However, the data are
often recorded at one-second intervals which is rather short, making
the data voluminous.  Judicious averaging can help with data set size
and processing times without compromising the science.  Choose the
data set(s) you wish to receive and submit the request.  You will be
told an estimate of the output data set sizes and the amount of time
you will need to wait for the format translation to occur.  A 19 Gbyte
SDMBDF file run as a test with no averaging was estimated to produce a
UVFITS file of 30.26 Gbytes and to take 103 minutes to prepare for
download.  That time assumes that your download job is the only one
being performed.  If your download fails, you will probably be told
erroneously by e-mail that it worked.  The output file will however be
missing or incomplete.  Try again before contacting NRAO for help.

If you are logged into an NRAO Socorro computer --- and perhaps if you
are not, --- you may find a better route to acquire your data with
useful additional information not available via CASA\@.  Try
requesting your data in SDMBDF format instead of uvfits and also
uncheck the ``Create tar file'' box {\it only if you are on a Socorro
computer}.  (Remote users will need to have the archive load the
SDMBDF file into ``tar'' form in the public ftp area for copying to
their home machine.)  If you have enough disk space, direct the data
to a directory on your machine, {\it after you have made that
directory world writable} ({\tt chmod 777}{\it directory-name}).  The
downloading of the SDMBDF file is quite efficient compared to having
the archive computer do all the file translation.  When you are told
that the SDMBDF file is ready, you may run {\tt AIPS} and load the
data via the verbs {\tt \tndx{BDFLIST}} and {\tt \tndx{BDF2AIPS}}\@.
These verbs run programs in the {\tt \tndx{OBIT}} software package to
load your data directly into \AIPS\ including flag ({\tt FG}), index
({\tt NX}), calibration ({\tt CL}), over-the-top ({\tt OT}), SysPower
({\tt SY}), and CalDevice ({\tt CD}) tables which you will not get
from CASA\@.  If you use this approach, you may skip the {\tt UVLOD}
and {\tt INDXR} steps described below.  Note that these verbs require
that {\tt OBIT} be installed on your computer --- as it is in Socorro
--- and that {\tt ObitTalk} be in your {\tt \$PATH}\@.  {\tt OBIT} is
relatively easy to install and may be obtained from {\tt
bcotton@nrao.edu}.

Unlocked files will be downloaded to the NRAO public ftp site\\
    \centerline{{\tt ftp://ftp.aoc.nrao.edu/e2earchive/}}\\
by default and you may then use ftp to copy the file to your computer.
Locked files will go to a protected ftp site and you must use ftp to
download those, even within NRAO\@.  The instructions for downloading
will be e-mailed to you.  Be sure to specify {\it binary} for the
copy.  If you are located in the AOC in Socorro, you may set an
environment variable to the archive location, \eg\
\displx{export E2E=/home/ftp/pub/e2earchive \CR}{for bash
       shells}
\displx{setenv E2E /home/ftp/pub/e2earchive \CR}{for C shells
       such as tcsh}
\dispe{and simply read unlocked data files directly from the public
download area.  Note that the file will be deleted automatically after
48 hours in both public and protected data areas.\Iodx{EVLA}}

SDMBDF files may be read into \AIPS\ using {\tt \Tndx{BDFLIST}} to
learn what is in your data set and then {\tt \Tndx{BDF2AIPS}} to
translate the data.  Thus
\dispt{DEFAULT\qs 'BDF2AIPS'; INP \CR}{to initialize all relevant
        adverbs.}
\dispt{DOWAIT\qs 2 ; DOCRT\qs 1 \CR}{to wait for the verbs to finish
        and to display the log file on the terminal after the {\tt
        OBIT} task finishes.  {\tt DOWAIT\qs 1} displays the messages
        as they are generated but is insensitive to returned error
        conditions from the {\tt OBIT} tasks.  Be sure to set {\tt
        DOWAIT\qs -1} after using {\tt BDF2AIPS}\@.}
\dispt{ASDMF(1)\qs = '{\it path\_to\_asdm\_dir} \CR}{to set the
        full path name into the adverb.  Note the lack of close quote
        so that case is preserved.  If the name is too long ($> 64$
        characters), put part of the name in {\tt ASDMF(1)} and the
        rest in {\tt ASDMF(2)}\@.  Trailing blanks in {\tt ASDMF(1)}
        will be ignored.}
\dispt{BDFLIST \CR}{to list the contents of the SDMBDF\@.  Note
        particularly the ``configuration'' numbers.}
\dispt{OUTNA\qs '{\it myname\/}' \CR}{to set the \AIPS\ name.}
\dispt{OUTCL\qs ' ' \CR}{to take default ({\tt UVEVLA}) class.}
\dispt{OUTDI\qs 3 \CR}{to write the data to disk 3 (one with enough
       space).}
\dispt{DOUVCOMP\qs FALSE \CR}{to write visibilities in uncompressed
       format.  There are no weights at present, so there is no
       loss of information in compressed format, but the conversion
       from compressed format costs more than reading the larger
       data files.}
\dispt{FOR\qs CONFIG = 0:100 ; BDF2AIPS; END \CR}{to load all of the
       configurations in your data, terminating with error messages on
       the first configuration number not present in your data (when
       {\tt DOWAIT} is 2).}
\dispe{There are other adverbs --- {\tt NCHAN}, {\tt NIF}, {\tt BAND},
and {\tt CALCODE} --- available if needed to limit which data are
read.  {\tt CONFIG} is frequently all that is needed to select data,
but these others may be needed if more complicated modes of observing
were used.}

The uvfits data file may be read from disk into \AIPS\ using {\tt
\tndx{UVLOD}} or {\tt \tndx{FITLD}}, using:
\dispt{DEFAULT\qs 'UVLOD' ; INP \CR}{to initialize and review the
        inputs needed.}
\dispt{DATAIN\qs 'E2E:{\it filename\/}' \CR}{where {\it filename\/}
       is the disk file name in logical area {\tt E2E}; (see
       \Sec{fitsdisk}).}
\dispt{OUTNA\qs '{\it myname\/}' \CR}{to set the \AIPS\ name.}
\dispt{OUTCL\qs ' ' \CR}{to take default ({\tt UVDATA}) class.}
\dispt{OUTSEQ\qs 0 \CR}{to take next higher sequence \#.}
\dispt{OUTDI\qs 3 \CR}{to write the data to disk 3 (one with enough
       space).}
\dispt{DOUVCOMP\qs FALSE \CR}{to write visibilities in uncompressed
       format.  There are no weights at present, so there is no
       loss of information in compressed format, but the conversion
       from compressed format costs more than reading the larger
       data files.}
\dispt{INP \CR}{to review the inputs.}
\dispt{GO \CR}{to run the program when you're satisfied with inputs.}

Watch the messages from {\tt UVLOD} to see where your data set goes
and whether the task ran properly.  When it is finished, check the
output header:
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{\tndx{IMHEAD}\qs \CR}{to examine the header.}
\dispe{Note that the header does not show the usual complement of
\AIPS\ extension files.  CASA translates the on-line data into its
internal format and then writes the uvfits file read by \AIPS\@.
Since CASA does not have files comparable to \AIPS\ index and {\tt CL}
tables, it does not provide them.  To build index and calibration
tables, use;\Iodx{EVLA}}
\dispt{TASK\qs '\tndx{INDXR}' ; INP \CR}{to select the task and review
       its inputs.}
\dispt{INFILE\qs '\qs' ; PRTLEV = 0 \CR}{to be sure not to use an
       input text file and to avoid excess messages.}
\dispt{CPARM = 0 , 0 , 1/2 \CR}{to make a {\tt CL} table 1 with a
       30-second interval.}
\dispt{BPARM\qs $\tau$ , 0 \CR}{to take default EVLA gains and a zenith
       opacity of $\tau$.  Set $\tau = -1$ for no opacity correction.
       You may set $\tau = 0$, which is now recommended, to get {\it
       new} default opacities.  These are based on a detailed model
       predicting the opacity at any frequency from that at 22 GHz.
       The combination of weather and seasonal model long used by
       {\tt FILLM} and {\tt INDXR} is now used solely to estimate the
       22 GHz opacity.}
\dispt{GO \CR}{to run the task after checking the inputs.}
\dispe{{\tt INDXR} now uses new EVLA gains information which includes
some frequency dependence within the new wide bands.  OBIT's
application of weather and gains appears to have errors --- re-create
the {\tt CL} table 1 and index table with {\tt INDXR} even if you got
your data via OBIT\@.}

It is a good idea to list the structure of your data set and your
antenna locations on the printer and to keep those listings next
to your work station for reference:
\dispt{DEFAULT\qs LISTR ; INP \CR}{to initialize the {\tt \tndx{LISTR}}
       inputs and review them.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{OPTYPE\qs 'SCAN' ; DOCRT\qs -1 \CR}{to choose a scan listing on
       the printer.}
\dispt{GO ; GO\qs \tndx{PRTAN} \CR}{to print the scan listing and the
       antenna file contents.}
\dispe{Read these with care.  There have sometimes been problems with
antenna identifications, with the order of the IF frequencies, and
even with identification of sources by scan.  Task {\tt \Tndx{SUFIX}}
may be used to correct the last problem and, if desired, {\tt FLOPM}
may be used to reverse the frequency order.  Oddly ordered IFs may
require {\tt UVCOP} to split them apart followed by {\tt
\tndx{VBGLU}} to paste them back together.  You may have to use {\tt
SETJY} or {\tt TABPUT} to change the {\tt CALCODE} of some sources if
your calibration sources have a blank calibrator code or your target
sources have a non-blank calibrator code.}

\Sects{Initial calibration --- {\tt VLANT}, {\tt FRING}}{EVLAfring}

As with the VLA, NRAO maintains text files describing any changes
which are made to our estimate of the antenna locations.  Users may
wish to apply these changes if their data were taken between the time
when antennas were moved to their current stations and the time that
the corrections were entered into the on-line control data base.  Task
{\tt VLANT} works for both VLA and EVLA data, reading these text files
and performing the needed changes to the {\tt CL} table, writing a new
one.  Thus
\dispt{DEFAULT\qs \tndx{VLANT} ; INP \CR}{to initialize the {\tt
       VLANT} inputs and review them.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{GO\qs \CR}{to run the task, writing {\tt CL} table 2.}

We have had difficulty setting all of the delays in the \Indx{EVLA} to
values which are sufficiently accurate.  If the delay is not set
correctly, the interferometer phase will vary linearly with frequency,
potentially wrapping through several turns of phase within a single
spectral window (``IF band'').  We hope that bad delays will not arise
in future, allowing you to skip this section, but use {\tt POSSM} to
check for phase slopes.  However, even very modest delay errors may
matter over the very wide bandwidths of the EVLA\@.  Note that {\tt
FRING} computes its values around the center of each spectral window
but then writes a phase correction appropriate to the frequency
reference pixel.  Use {\tt IMHEADER} to see what this is in your data
set.  Traditionally it has been 1.0, but $N_{\rm chan} / 2 + 1$ is a
better choice.  New task {\tt \tndx{CENTR}}, or numerous other tasks
with adverb {\tt FQCENTER}, will convert your data set to this
reference.  Note that this conversion requires re-scaling the $u, v,
w$ values and adjusting some {\tt FQ} table values; it is not just a
simple change in the header.

Delay errors are problem familiar to VLBI users and \AIPS\ has a
well-tested method to correct the problem.  Using your {\tt LISTR}
output, select a time range of about one minute {\it toward the end of
a scan} on a strong point-source calibrator, usually your bandpass
calibrator.  Then
\dispt{DEFAULT\qs \tndx{FRING} ; INP \CR}{to initialize the {\tt FRING}
       inputs and review them.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{SOLINT\qs 1.05 * $x$ \CR}{to set the averaging interval in
       minutes slightly longer than the data interval ($x$)
       selected.}
\dispf{TIMERANG\qs {\it db} , {\it hb} , {\it mb} , {\it sb} , {\it
       de},  {\it he} , {\it me} , {\it se} \CR}{to specify the
       beginning day, hour, minute, and second and ending day, hour,
       minute, and second (wrt {\tt REFDATE}) of the data to be
       included.  Too much data will cause trouble.}
\dispt{DPARM(9) = 1 \CR}{to fit only delay, not rate.  {\it This is
       very important.}}
\dispt{DPARM(4) = $t$ \CR}{to help the task out by telling it the
       integration time $t$ in seconds.  Oddities in data sample times
       may cause {\tt FRING} to get a very wrong integration time
       otherwise.}
\dispt{INP \CR}{to check the voluminous inputs.}
\dispt{GO}{to run the task, writing {\tt SN} table 1 with delays for
       each antenna, IF, and polarization.}
\dispe{The different IFs in current \Indx{EVLA} data sets may come
from different basebands and therefore have different residual
delays.  The option {\tt APARM(5) = 3} to force the first $N_{if}/2$
IFs to have one delay solution while the second half of the IFs has
another is strongly recommended, but only when the first half all come
from one of the ``AC'' or ``BD'' basebands (hardware IFs) and the
second half come from the other.  The 3-bit data path of the EVLA
actually has four hardware IFs, so {\tt APARM(5) = 4} produces four
delay solutions, dividing the IFs in quarters.  Note that, at low
frequencies, the phases may also be affected by dispersion (phase
differences proportional to wavelength).  {\tt FRING} now offers {\tt
APARM(10)} to enable solving for a single delay plus dispersion from
the fitted single-IF delays.  This {\tt SN} table will need to be
applied to the main {\tt CL} table created by {\tt INDXR} or {\tt
OBIT}\@.}
\dispt{TASK\qs '\tndx{CLCAL}' ; INP \CR}{to look at the necessary
       inputs.}
\dispt{TIMERANG\qs 0 \CR}{to reset the time range.}
\dispt{GAINUSE 0 ; GAINVER 0 \CR}{to select the highest {\tt CL}
       table as input and write one higher as output (version 2 and 3,
       resp.~in this case).}
\dispt{SNVER 1 ; INVER 1 \CR}{to use only the {\tt SN} table just
       created.}
\dispt{INP \CR}{to review the inputs.}
\dispt{GO \CR}{to make an updated calibration table.}
\dispe{Be sure to apply this (or higher) {\tt CL} table with {\tt
DOCALIB\qs 1} in all later steps.}

\sects{Initial editing}

You should use the tools below to flag out obviously bad data.  The
tasks which automatically flag data for you, however, depend on
meaningful amplitudes and flat spectral shapes.  Therefore, flagging
and calibration are an iterative process.  Do the obvious flagging
without spending a lot of time on it.  Then do an initial calibration
of bandpass, amplitude, and phase.  Use that calibration to run {\tt
\tndx{RFLAG}} and/or other auto-flagging tasks.  Then throw away all
{\tt CL} tables following {\tt VLANT} and begin again with {\tt
FRING}, {\tt BPASS}, {\tt CALIB}, etc.

There will be data validity information prepared both by the on-line
control software and by the WIDAR correlator and most of this
information is available as an initial flag table.  The tasks above
will have applied this table for you by default since {\tt FLAGVER\qs
0}.  On-line flags may already have caused data to be flagged within
your data set (but {\it not} deleted) by CASA\@.  Unfortunately, a
flag table is present only via the {\tt OBIT} route.  {\tt UVFLG} will
be needed to add flags for shadowing ({\tt APARM(5)=25} or so) to a
flag table.  We still need to look at the data to flag out whatever
remains of the time off source not flagged using on-line flagging
information.  There have also been drop outs in which the visibility
is pure zero, typically for all channels and IFs and a single
integration.  The drop outs should now be handled by {\tt OBIT}, {\tt
UVLOD}, and {\tt FITLD}\@.  Note, however, that CASA and {\tt FITLD}
pass along all data samples, including those that are fully flagged.
This makes the data set rather larger than one might wish.  Use {\tt
UVCOP} (or {\tt TYAPL} --- see \Sec{SysPower}) to remove all fully
flagged data samples.  Before doing this, use {\tt TVFLG}
(\Sec{tvflg}) to look for any more data samples that might need to be
flagged fully.  Check especially samples at the beginnings and ends of
scans.  Try\Iodx{EVLA}
\dispt{DEFAULT\qs \tndx{TVFLG} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs -1 \CR}{to apply the delay calibration.
       If a bandpass has been determined, use {\tt DOBAND\qs 3} or 1
       to apply it.}
\dispt{BCHAN\qs $c1$ ; ECHAN\qs $c2$ \CR}{to average across a range of
       channels --- not as flexible as {\tt ICHANSEL} but probably
       okay here.}
\dispt{NCHAV\qs ECHAN-BCHAN+1 \CR}{to average all the channels into
       one number.}
\dispt{BIF\qs $j$ ; EIF\qs BIF \CR}{to edit one IF only, which will
       suffice for problems that are not IF dependent, such as drop
       outs, antenna not on source, etc.  Choose an IF that is
       reasonably free of RFI\@.}
\dispt{CALCODE\qs '*' \CR}{to do just calibrators for the moment.}
\dispt{DPARM(6)\qs $\Delta\ t$ \CR}{to do no time averaging in the
       work file set $\Delta\ t$ to the data interval in seconds.}
\dispt{GO \CR}{to start the task.}
\dispe{The default smoothing time shown in the display will probably
be some multiple of $\Delta\ t$.  Change the smoothing time to one
times the basic interval in order to edit in detail; {\tt TVFLG} will
break up your data into overlapping ``groups'' which you may edit is
sequence.  Remember to change the initial setup so that the flags
apply to all channels and all IFs.  See \Sec{tvflg} for more
information.  The EVLA has shown a tendency to produce periods of data
which are too low in amplitude to be normal noise, but which are not
zero.  Use {\tt TVFIDDLE} or {\tt TVTRANSF} functions to enhance the
brightness of the amplitudes to make sure that apparently black
regions really are black (flagged already).}\Iodx{EVLA}

We note here that some users feel that the data need to be inspected
more carefully than with just an average of most of the channels.
{\tt POSSM} (below) may be of use to find RFI\@.  Avoiding the worst
of that, you may still wish to run {\tt TVFLG} to look at the average
of a few channels at a time.  Use {\tt NCHAV} and {\tt CHINC}
appropriately.  Task {\tt SPFLG} (\Sec{spflg}) is the ultimate weapon
when looking for channel-dependent difficulties and is even capable of
normalizing by source flux including spectral index.  However, it is
onerous when there are many baselines.  {\tt FTFLG} is similar to {\tt
SPFLG} but displays all baselines together.  It would be a quick way
to look for wide-spread RFI\@.  These more onerous tools should
probably not be used at this preliminary stage; use them after some of
the auto-flagging tasks have been run.

\Sects{Basic calibration}{EVLAcal}

For data taken with the new low-band receivers (frequencies rather
less than 1 GHz), spectral windows may cover a frequency range so wide
that the sources vary quite a bit across the individual window.  Such
wide windows may be convenient for taking the data, but later data
reduction will be more reliable with narrower spectral windows.  The
task {\tt \Tndx{MORIF}} in {\tt 31DEC12} may be used to increase the
number of spectral windows by a user-specified factor.  To avoid
having to use {\tt \tndx{NOIFS}} ahead of {\tt MORIF}, task {\tt
\tndx{REIFS}} was written.  It is more flexible in placing the new
IFs, including allowing them to include data from more than one input
IF\@.

For {\it both} continuum and line observations, we must begin by
determining which spectral channels are reliable and which are
affected by the inevitable loss of signal-to-noise at band edges or
are degraded by radio-frequency interference (RFI)\@.  Use {\tt
\tndx{POSSM}} to display spectra from the shorter baselines on the TV:
\dispt{DEFAULT\qs POSSM ; INP}{to set the task name and clear the
      adverbs.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{SOURCE\qs '{\it bandpass\_cal\/}' \CR}{to select the strong
       bandpass calibrator.}
\dispt{DOTV\qs 1 ; NPLOTS\qs 1 \CR}{to plot only on the TV, one
       baseline at a time.}
\dispt{ANTEN\qs {\it n1 , n2 , n3 , n4} \CR}{to select the antennas
       nearest the center of the array or the maintenance areas.}
\dispt{BASELINE\qs ANTEN \CR}{and only them.}
\dispt{DOCAL\qs 1 ; APARM\qs 0 \CR}{to apply the {\tt FRING}
       solutions and display vector averaged spectra.  Scalar averaged
       spectra will turn up at the edges reflecting the decreased
       signal to noise in the outer channels.}
\dispt{APARM(9)=1 \CR}{to plot all IFs in a single plot.}
\dispt{GO \CR}{to run the task.  Make notes of the desirable channels
       IF by IF\@.}
\dispe{If there is no RFI, then you may be able to use the same
channel range for all IFs.  If the RFI is particularly pernicious, you
may have to edit it out of your data before continuing; see
\Sec{EVLAflag}.  The first time through this section, you should
accept but perhaps try to avoid the worst of the RFI\@.  After the
detailed editing, that RFI should be gone.}

{\tt POSSM} may reveal extensive ringing in your spectra due to narrow
RFI signals.  Try {\tt SMOOTH=1,0} to apply Hanning smoothing.  If
this proves beneficial, you should apply this {\tt SMOOTH}, plus the
initial flag table and calibration to the data once and for all with
{\tt SPLAT}\@.  Using {\tt SMOOTH} in all operations can produce
errors in bandpass functions (if you forget it once in a while) and
will produce especially strange results when you use the
channel-dependent auto-flagging routines such as {\tt RFLAG}\@..

For polarization calibration, it is assumed that the phase difference
between the right and left polarizations of your calibration is stable
with time.  Thus, if polarization is important, it is {\it critical}
to find a reference antenna with a stable right minus left phase.
Use {\tt CALIB} with {\tt SOLMODE 'P'} and as short a time interval as
possible on your strongest calibration sources.  Use {\tt SNPLT} with
{\tt STOKES 'DIFF'} and {\tt OPTYPE 'PHAS'} to look at the right minus
left phases in the {\tt SN} table produced by {\tt CALIB}\@.  Find the
one that is the most stable and use that as {\tt REFANT} henceforth.
To avoid later confusion, delete the {\tt SN} used for this
determination with {\tt EXTDEST}\@.

The basic \Indx{EVLA} calibration is much like that described in
detail in \Rchap{cal} except that bandpass calibration is now {\it
required} rather than merely {\it recommended}.  Having chosen those
channels which may be reliably used to normalize the bandpass
functions,
\dispt{DEFAULT\qs \tndx{BPASS} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 \CR}{to apply the delay calibration --- {\it very
       important}.}
\dispt{CALSOUR\qs '{\it bandpass\_cal\/}' \CR}{to select the strong
       bandpass calibrator.}
\dispt{SOLINT\qs 0 \CR}{to find a bandpass solution for each scan
       on the BP calibrator.}
\dispf{ICHANSEL\qs $c11, c12, 1, if1, c21, c22, 1, if2, c31, c32, 1,
       if3, \ldots\/$ \CR}{to select the range(s) of channels which
       are reliable for averaging in each IF\@.  Use the central 30\%\
       of the channels if your calibrators are all very strong or
       more like 90\%\ if they are not.  Remember these values
       --- you will use them again.}
\dispt{BPASSPRM(5)\qs 1 ; BPASSPRM(10)\qs 3 \CR}{to normalize the
       results only after the solution is found using the channels
       selected by {\tt ICHANSEL}\@.  Use {\tt BPASSP(5)=-1} if your
       phases are not stable within each scan.}
\dispt{GO \CR}{to make a bandpass ({\tt BP}) table.}
\dispe{Do not use spectral smoothing at this point unless you want to
use the same smoothing forever after.  Apply the flag table.  A model
for the calibrator may be used; see \Sec{vlacalmodels}.}

{\tt BPASS} now contains the adverbs {\tt SPECINDX} and {\tt SPECURVE}
through which the \indx{spectral index} and its curvature (to higher
order than is known for any source) may be entered.  For the standard
amplitude calibrators 3C286, 3C48, 3C147, and 3C138, these parameters
are known and will be provided for you by {\tt BPASS}\@.  For other
sources, you may provide these parameters, but {\tt BPASS} will fit
the fluxes in the {\tt SU} table for a spectral index (including
curvature optionally) if you do not.  Note that, if no spectral index
correction is applied, the spectral index of the calibration source
will be frozen into the target source.  Bandwidths on the EVLA are
wide enough that this is a serious problem.  If you do not know the
spectral index of your calibration source, {\tt BPASS} itself or the
new task {\tt \Tndx{SOUSP}} may be used to determine the spectral
indices from the {\tt SU} table.  Of course, that means that {\tt
GETJY} must already have been run.  Since {\tt BPASS} must usually be
run before {\tt CALIB} and hence {\tt GETJY}, this suggests that one
may have to iterate this whole process at least once.  {\tt SOUSP} now
offers the option of correcting one or more {\tt SN} tables after it
adjusts the source fluxes for the spectral index it determined.  This
may reduce the need for further iterations.

Note that the bandpass parameters shown above assume that the phases
are essentially constant through each scan of the bandpass calibrator.
This may not be true, particularly at higher frequencies.  In this
case, you have two choices.  One is to set {\tt BPASSPRM(5)} to 0
which will determine the vector average of the channels selected by
{\tt ICHANSEL} at every integration and divide that into the data of
that integration.  This will remove all continuum phase fluctuations,
but runs a risk of introducing a bias in the amplitudes since they do
not have Gaussian statistics.  {\tt BPASSPRM(5) = -1} now applies a
phase-only correction on a record-by-record basis.  A better
procedure, which is rather more complicated, is as follows.  Use {\tt
SPLIT} to separate the bandpass calibrator scans into a separate
single-source file applying any flags and delay calibration and the
like.  Then run {\tt CALIB} on this data set with a short {\tt SOLINT}
to determine and apply a phase-only self-calibration.  On the $uv$
data set written out by {\tt CALIB}, run {\tt BPASS} using the
parameters described in the previous paragraph.  Finally, use {\tt
TACOP} to copy the {\tt BP} table back to the initial data set.

In {\tt 31DEC16}, there is a new TV graphical editing task called {\tt
\Tndx{BPEDT}}\@.  It looks a lot like {\tt EDITA}, displaying multiple
antennas at a time, but the horizontal axis is spectral channel rather
than time and the data displayed are the solutions from the {\tt BP}
table.  This task is particularly suited to identifying and flagging
residual RFI in the bandpass calibrator scans after the first pass(es)
of {\tt RFLAG}.  Repeat {\tt BPASS} if you generate any flags with
{\tt BPEDT}\@.

You now need to run {\tt SETJY} with {\tt OPTYPE\qs 'CALC'} and
{\tt SOURCES} set to point at your primary flux calibration sources.
You should load the models for these sources that apply to your data
with {\tt CALRD}; see \Sec{vlacalmodels}.  Then run {\tt CALIB} with
the model once for each primary flux calibrator:\Iodx{EVLA}
\dispt{DEFAULT\qs \tndx{CALIB} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{IN2DI\qs {\it n2\/}; GET2N\qs {\it m2\/} \CR}{to select the
       model image on disk $n2$ and catalog number $m2$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3\CR}{to apply the delay and bandpass
       calibration --- very important.}
\dispt{SOLINT\qs 0 ; NMAPS\qs 1 \CR}{to compute a solution for each
       calibration scan and use the source model.}
\dispt{CALSOUR\qs '{\it flux\_cal\/}' \CR}{to select the primary flux
       calibrator by whatever form of its name appears in your {\tt
       LISTR} output.}
\dispf{ICHANSEL\qs $c11, c12, 1, if1, c21, c22, 1, if2, c31, c32, 1,
       if3, \ldots\/$ \CR}{to select the range(s) of channels which
       are reliable for averaging in each IF\@.  These {\it must} be
       the same values that you used in {\tt BPASS}\@.}
\dispt{SNVER\qs 2 \CR}{to put all {\tt CALIB} solutions in solution
       table 2.}
\dispt{GO\qs \CR}{to find the complex gains for the flux calibrator.}
\dispe{Read the output closely.  If solutions fail, examine your data
closely for bad things.  The primary flux calibrator should work
without failure.  After you have done each primary flux calibrator for
which you have models, run {\tt CALIB} on the remaining calibration
sources:}
\dispt{CALSOUR\qs '{\it other\_cal1\/}', '{\it other\_cal2\/}'
       \CR}{to select the secondary calibrators by whatever names
       appear in your {\tt LISTR} output.}
\dispt{CLR2NAME ; NMAPS\qs 0 \CR}{to do no models.}
\dispt{GO \CR}{to find the remaining complex gains.}
\dispe{Again, examine the output messages closely.  There may be a few
failures but there should not be many in a good data set.  The {\tt
RUN} file procedure {\tt VLACALIB} (see \Sec{vlacalmodels}) may be
used but it does not offer the {\tt ICHANSEL} option which may be
required by your data.  It also does a scalar averaging for the
amplitudes.  This averaging is now a vector average of the spectral
channels followed by a scalar average over time.  Scalar averaging
suffers from Ricean bias in the amplitudes and so should be used only
when the calibration source is very strong or when the atmospheric
phases are very unstable.}

At this point it is necessary to calibrate the fluxes of the secondary
calibration sources using your {\tt SN} table:
\dispt{TASK\qs '\tndx{GETJY}' ; INP \CR}{to set the task name without
       changing other adverbs.}
\dispt{SOURCE\qs CALSOUR \CR}{to select the secondary sources by the
       list of name you just used.}
\dispt{CALSOUR\qs '{\it flux\_cal\/}' \CR}{to select the primary flux
       calibrator by whatever form of its name appears in your {\tt
       LISTR} output.}
\dispt{INP \CR}{to check the inputs closely; remember to do all times,
       IFs, etc.~with {\tt SNVER 2}.}
\dispt{GO \CR}{to adjust the gains in the {\tt SN} table and the
       fluxes in the {\tt SU} (source) table.}
\dispe{Look at the messages with care --- the fluxes in the various
IFs should be consistent and the error bars should be reasonably
small ($<10\%$ at high frequencies, smaller at low frequencies).  If
not, look at your {\tt SN} table with {\tt SNPLT} to see if there are
bad solutions.  If there are, delete {\tt SN} table 2, do more
flagging with {\tt TVFLG} or {\tt SPFLG}, and repeat the process.}

Use the interactive TV task {\tt \tndx{EDITA}} to examine the values
in your {\tt SN} table.  There may be bad solutions which will require
additional flagging of your calibration data.  If there is a
significant amount of flagging, you should repeat the calibration
process to avoid the influence of bad data on the gains and {\tt
GETJY} results.  Rather than edit each antenna/IF tediously, use {\tt
EDITA} or {\tt SNPLT} to determine allowed ranges of amplitude and
phase gains and then use {\tt \tndx{SNFLG}} with {\tt OPTYPE 'A\&P'}
to do the flagging.\Iodx{EVLA}

Although it may be better to wait until after detailed flagging,
you may wish to iterate at this point, determining the spectral
indices of your bandpass calibrators with {\tt SOUSP} and re-doing
{\tt BPASS}, {\tt CALIB}, and {\tt GETJY}\@.  If the result is a
seriously changed \indx{spectral index} for your secondary sources you
may have to iterate further.

If your calibration source consists of a single spectral line, you may
use CALIB to determine the gains in that IF, limited to the
appropriate channels.  The new task {\tt \tndx{SNP2D}} will convert
this {\tt SN} table from a valid phase in only one IF into delays and
phases in all IFs on the assumption that the observed phase is in fact
a delay.

Finally, apply the gain solutions to your calibration table:
\dispt{DEFAULT\qs \tndx{CLCAL} ; INP \CR}{to clear the adverbs.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{CALCODE\qs '*' \CR}{to select all calibration sources.}
\dispt{SNVER\qs 2; INVERS\qs SNVER \CR}{to select your solution table
       from {\tt CALIB}\@.  Do {\it not} include the {\tt SN} table
       from {\tt FRING} a second time!}
\dispt{GO \CR}{to apply {\tt SN} table 2 to {\tt CL} table 3,
       creating {\tt CL} table 4.}
\dispe{Check the result using {\tt POSSM} and/or {\tt VPLOT}\@.}

\Sects{Detailed flagging}{EVLAflag}

The calibration you have done to this point has been degraded by RFI
which has not yet been flagged.  However, you need to do the above in
order to bring all spectral channels and all antennas and sources into
the same flux scale.  Now automatic tasks may be used --- and they are
needed for the large volumes of data produced by the \Indx{EVLA}\@.

In {\tt 31DEC17}, the task {\tt \Tndx{FGSPW}} may be used to flag IFs
(aka `spectral windows'') that have been rendered useless by RFI or
other problems.  It performs a scalar average of the amplitudes in all
spectral channels on a per IF per polarization per basdeline per scan
basis.  Those IFs where amplitudes have overflowed the hardware due to
RFI tend to stand out with this statistic.  {\tt LISTR} with {\tt
OPTYPE='MATX'\qs DPARM=1,1} will also compute and print this statistic
to let you determine what are reasonable values and what are not.

A very promising relatively new tool flags RFI on the assumption that
it is either quite variable in time or in frequency.  This task,
called {\tt \Tndx{RFLAG}}, computes the rms over short time intervals
in each spectral channel and IF individually and flags the interval
whenever the rms exceeds a user-controlled threshold.  Optionally, it
will also use a sliding median window of user-specified width over the
spectral channels to the real and imaginary parts of the visibility
separately.  Any channel deviating from the median in either part by
more than a user-specified amount will also be flagged.  If {\tt
DOPLOT}$> 0$, {\tt RFLAG} will make plots of normal and cumulative
histograms and of the mean and rms of the time and spectral
computations as a function of channel.  It will also make a flag table
only if requested ({\tt DOFLAG}$ > 0$).  These plots will suggest
threshold parameters and allow you to choose values to use.  A flag
table is made for any value of {\tt DOFLAG} if no plots are requested
({\tt DOPLOT}$\leq 0$).

In detail, {\tt \Tndx{RFLAG}} is run using
\dispt{DEFAULT\qs \tndx{RFLAG} ; INP \CR}{to clear and review the adverbs.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{SOURCES\qs '{\it source\_1}', '{\it source\_2}', $\ldots$
       \CR}{to select sources of similar flux level.}
\dispt{DOCALIB\qs 1 ; DOBAND\qs 1 \CR}{to apply continuum and bandpass
       calibration.}
\dispt{STOKES\qs 'FULL' \CR}{to examine all polarizations.}
\dispt{DOPLOT\qs 15 ; DOTV\qs 1 \CR}{to examine all kinds of plots on
       the TV.}
\dispt{FPARM\qs 3 , $x$ , -1, -1 \CR}{to examine spectral rms over 3
       time intervals each a bit longer than $x$ seconds.  The $-1$'s
       cause the program to use other adverbs for the cutoffs and to
       do a spectral solution as well as the time one.}
\dispt{FPARM(9) = 4.0 ; FPARM(10) = 4. \CR}{to set the cutoff values
       as 4 times the median rms plus deviation found in the spectral
       plots as a function of IF\@.  The default is 5.}
\dispt{FUNCTYPE\qs 'LG' \CR}{to plot the histograms on a log scale.}
\dispt{NBOXES\qs 1000 \CR}{to use 1000 boxes in the histograms.}
\dispt{INP\qs \CR}{to re-examine the inputs.  {\tt VPARM} will let you
       control aspects of the plotting.}
\dispt{GO}{to run the program.}
\dispe{This will produce plots and set cutoff levels in adverbs {\tt
NOISE} and {\tt SCUTOFF}\@.  Another run, with {\tt DOPLOT = 0} will
apply these cutoffs and create a new flag table.  Note that the flux
cutoff levels may depend on the source flux, calling for different
levels for strong calibrators, weak calibrators, and very weak target
sources.  Different cutoff levels for {\tt STOKES='RRLL'} and {\tt
STOKES = 'RLLR'} may also be needed.  A strong, resolved target source
may require different levels for different {\tt UVRANGE}s.  If so, you
will need to break up wide bandwidth data into separate files each
containing only one IF so that {\tt UVRANGE} is applied properly.
{\tt VBGLU} may be used later to put the IFs back together.  {\tt
RFLAG} is a new task, so experiment a bit.  Note that, if you set {\tt
DOFLAG=1}, the creation of a new flag table will happen after the
plots in the same execution of {\tt RFLAG}\@.  If a channel is found
bad at a time in any one polarization, all polarizations are flagged.
If you have a significant spectral line signal in your data, use {\tt
DCHANSEL} to have the affected channels ignored throughout {\tt
RFLAG}\@.\Iodx{EVLA}}

There are a lot of adverbs to {\tt RFLAG}\@.  {\tt FPARM(5)} allows
you to speed up the spectral part of the flagging by testing more than
just the central channel in the sliding median filter.  {\tt FPARM(6)}
allows you to expand all flags to adjacent channels.  {\tt FPARM(7)},
8, 11, and 12 control the extending of flags to additional channels,
baselines, or antennas if too large a fraction of channels, baselines,
or baselines to an antenna are flagged in the basic time and spectral
operations.  Similar adverbs also occur in the new task {\tt
\Tndx{REFLG}} whose job it is to compress the enormous flag tables
generated generated by {\tt RFLAG}\@.  {\tt REFLG} does not handle
flags generated by {\tt CLIP}, {\tt TVFLG}, and {\tt SPFLG} since they
vary with polarization.  {\tt REFLG} can extend a flag to all times if
too large a fraction of time is flagged for a given channel, baseline,
etc.  {\tt REFLG} may not reduce your flag table enough, although it
is inexpensive to run and so worth the effort.  The application of 10
million flag entries to a data set repetitively is rather expensive.
Copying the data, applying the flags once and for all, is the best
solution.  {\tt UVCOP} has been the traditional method to do this.
However, {\tt TYAPL} which needs to be run next and must make a new
copy of the data has been given the option of applying a large flag
table to avoid having to copy the data set twice.  Task {\tt
\Tndx{FGCNT}} lets you see how much of your data is flagged by any
particular flag table.

A new tool which may help identify bad data at this early stage is the
task {\tt REWAY} described in \Sec{evlaSplit}.  It checks the data for
spectral windows with particularly low and particularly high rms
levels.  It must copy the selected data to a new file, so it is not
particularly recommended at this point.  Run it with no flagging of
the output for bad values of the spectral rms.  Then plot the weights
with {\tt VPLOT} or {\tt ANBPL} to look for weights that are seriously
abnormal (high or low).  Those data may need to be flagged.  High
weights mean that the data are of abnormally low amplitude, whilst low
weights mean that the data are very noisy.  {\tt REWAY} uses robust
methods to find the rms and so a few channels of RFI may not cause
very low weights, but lots of RFI or receiver failures will make the
weights abnormally low.  {\tt REWAY} now displays statistical
information to help you assess what weights are ``high'' and ``low''.

{\tt POSSM} may be used again to see if serious RFI remains after {\tt
RFLAG} and it may be appropriate to run {\tt TVFLG} to look at groups
of a small number of spectral channels (or even every channel) on your
calibration source.  Task {\tt FLGIT} (\Sec{lineasses}) is an older
task that attempts to flag RFI that is both channel- and
time-dependent in a non-interactive fashion.  {\tt SPFLG}
(\Sec{spflg}) is labor and time intensive but would be the most
reliable method to deal with the problem.  {\tt \tndx{FTFLG}} is like
{\tt SPFLG} except that all baselines are added together in a single
plot (per polarization).  It probably is not good for much flagging,
but will provide a quick and sensitive way to look for widely
distributed RFI\@.  {\tt \tndx{CLIP}} will flag particularly high
amplitudes and is capable of running in a normalized fashion dividing
by source flux including spectral index (and curvature if desired).
({\tt UVPLT} also has the {\tt DOSCALE} option, letting you see the
normalized visibilities prior to flagging with {\tt CLIP}\@.)
However, {\tt RFLAG} should get the high fluxes in most realistic
cases and even has a clip option ({\tt FPARM(13)})\@.

The auto-editing task {\tt FLAGR} is also of some use here.  It
averages the spectral channels to get an estimate of the mean and rms
and uses those numbers evaluated over time and baseline in a variety
of algorithms to further flag the data.  RFI which is rather wide
spectrally and long lived may be found in this way.

\Sects{Calibration with the SysPower table}{SysPower}

Having done a more careful job with your editing, it is now time to
discard with {\tt EXTDEST} the bandpass ({\tt BP}) tables and all {\tt
CL} tables after the one written by {\tt VLANT}\@.  Discard all {\tt
SN} tables, but keep the highest numbered flag ({\tt FG}) table.
\Iodx{EVLA}

Because of its wide dynamic range, the EVLA does not normalize its
output visibilities.  To calibrate gains it records the total power
when the switched noise tube is on and when it is off.  These data,
taken in synchronism with the visibilities, are recorded in the
\Indx{SysPower} table of the ASDM\@.  The {\tt \tndx{OBIT}} program
{\tt BDFIn}, available to \AIPS\ users in the new verb {\tt
\tndx{BDF2AIPS}}, reads this table and creates an \AIPS\ {\tt SY}
table.  The columns of this table contain {\tt POWER DIF} ($Gain
\times (P_{on} - P_{off}$), {\tt POWER SUM} ($Gain \times (P_{on} +
P_{off}$), and {\tt POST GAIN} ($Gain$) columns for right and left
polarizations with values for each IF\@.

This table is accessible to \AIPS\ users with a number of tasks.
Begin with task {\tt \Tndx{PRTSY}} to view the table statistically
over time on a per IF, per antenna basis or to view scan or source
median averages of one or more of the {\tt SY} table parameters.  Then
to examine its contents in more detail in various ways, use {\tt
\tndx{SNPLT}} with {\tt OPTYPE}s {\tt 'PDIF'}, {\tt 'PSUM'}, {\tt
'PGN'}, {\tt 'PON'}, {\tt 'POFF'}, {\tt 'PSYS'}, {\tt 'PDGN'}, or {\tt
'PSGN'}\@.  You could use {\tt OPTYPE = 'MULT'} to examine more than
one of these at one time, comparing any oddities in \eg\ Psum and
Pdif.  Note that {\tt PSYS} is especially interesting since
$P_{sum}/P_{dif}/2*T_{cal} = T_{sys}$, the system temperature.  It
should reflect changes in elevation and strength of the observed
source, but should be immune to adjustments to the gain of the
telescope.  It determines data weights in {\tt TYAPL} while
$\sqrt{P_{dif_i} P_{dif_j}}$ divides into the visibilities.  You may
use {\tt \tndx{EDITA}} (\Sec{edita}) to edit your $uv$ data on the
basis of the contents of the {\tt SY} table.  Editing may be based on
Psum, Pdif, Pgain, Tsys, and on the differences between these
parameters and a running median of these parameters.  One may also
edit the {\tt SY} table itself with {\tt \tndx{SNEDT}}; the same
parameters are available.  {\tt LISTR} can even display the {\tt SY}
table Psum, Pdif,  system temperatures, and gain factors with {\tt
OPTYPE 'GAIN'} and {\tt DPARM(1)} set to 17, 18, 15, or 16,
respectively.

More importantly, the {\tt SY} table can be used to do an initial
calibration of the visibility data.  Use the display programs to
decide if your {\tt SY} table is fine as is or needs editing.  The
tasks {\tt \tndx{TYSMO}} and  {\tt \tndx{TYAPL}} (\Sec{VLATY}) may be
used with \Indx{EVLA} data having an {\tt SY} table.  {\tt TYSMO}
flags {\tt SY} samples on the basis of Pdif, Psum, Pgain, and Tsys and
then smooths Psum, Pdif and Pgain to replace the flagged samples
and/or reduce the noise.  You may want to do this to remove outlying
bad points and to reduce the jitter in these measurements.  {\tt
TYSMO} even applies a flag table to the {\tt SY} before its clipping
and smoothing operations.  Be sure to plot the results to make sure
that the task did what you wanted.  Then use {\tt TYAPL} to remove a
previously applied {\tt SY} table (if any) and to apply the {\tt SY}
table you have prepared.  The result should be data scaled nearly
correctly in Jy and weights in $1/{\rm Jy}^2$ in all IFs.  The {\tt
CUTOFF} option allows you to use obviously good values from the {\tt
SY} table while passing the data from antennas with poor {\tt SY}
values along unchanged.  If the {\tt SY} values from some
polarizations or IFs are bad due to RFI while others are good, you
may copy the good values to replace the bad values using task {\tt
\tndx{TYCOP}}\@.  The wide-band, 3-bit mode of the EVLA has serious
non-linearities in the Pdif measurements which are not yet fully
understood.  For such data, use {\tt OPTYPE='PGN'} to apply only the
post-detection gains to the data.  This will remove abrupt jumps due
to changes in those gains (which will be more common with 3-bit data).
Note that {\tt TYSMO} and {\tt TYAPL} also require a table of the Tcal
values which {\tt OBIT} provides in an \AIPS\ {\tt CD} table.
Amplitude calibrations are not applied to EVLA data weights until they
have been made meaningful by {\tt TYAPL} or {\tt REWAY}\@.  Set {\tt
FLAGVER} in {\tt TYAPL} if you want to apply your flag table once and
for all.

If you have observations of the Sun, do not use {\tt TYAPL}; use {\tt
\tndx{SYSOL}} instead.  This task does the usual {\tt TYAPL} operation
on non-Solar scans, but, for Solar scans, it must determine the
average gain and weight factors on those antennas having solar Tcals
and then apply those averages to all antennas not equipped with Solar
Tcals.  Use a well-edited {\tt SY} table if possible.  This Solar
capability was made available in {\tt OBIT} (version 567) and \AIPS\
in mid-June 2017.

Now return to \Sec{EVLAcal} to repeat the bandpass and continuum
calibrations with correctly scaled data with most of the RFI removed.

\Sects{Polarization calibration --- {\tt RLDLY}, {\tt PCAL}, and {\tt RLDIF}}{evlaPCAL}

You may skip this section unless you have cross-hand
\indx{polarization} data and wish to make use of them.  Although there
have been major improvements in \AIPS\ polarization routines, they
still do not correct parallel hand visibilities for polarization
leakage.  Thus you need to calibrate polarization only if you wish to
make images of target source Q and U Stokes parameters.  Polarization
calibration is discussed extensively in \Sec{polcal}; we will discuss
changes made because of the wide bandwidths and other aspects of the
\Indx{EVLA}\@.

Frequently, the delay difference between right- and left-hand
polarizations must be determined even if {\tt FRING} was not required
for the parallel-hand data.  Use {\tt POSSM} to plot the RL and LR
spectra to see of there are significant slopes in phase.  If so, use a
calibration source with significant polarization, although the EVLA D
terms are often large enough to provide a usable signal in the absence
of a real polarized signal.  Note that 3C286 is significantly
polarized and is likely to be the best source to use for this purpose.
Then
\dispt{TASK\qs '\Tndx{RLDLY}' ; INP \CR}{to look at the necessary
       inputs.}
\dispt{BCHAN\qs $c_1$ ; ECHAN\qs $c_2$ \CR}{to select channels free of
       edge effects.}
\dispt{DOCAL\qs 1 ;\qs GAINUSE\qs 0 \CR}{to apply the {\tt FRING}
       results and all other current calibrations.}
\dispt{REFANT\qs $n_r$ \CR}{to select a reference antenna - only
       baselines to this antenna are used so select carefully.
       Alternatively, {\tt REFANT 0} will loop over all possible (not
       necessarily good) reference antennas, averaging the result.}
\dispt{DOIFS\qs $j$ \CR}{to set the adverb to the value of {\tt
       APARM(5)} used in {\tt FRING} (\Sec{EVLAfring}.  The IFs are
       done independently ($\leq 0$), all together ($= 1$), in halves
       ($= 2$), or more generally in $N$ groups ($= N$).}
\dispf{TIMERANG\qs {\it db} , {\it hb} , {\it mb} , {\it sb} , {\it
       de},  {\it he} , {\it me} , {\it se} \CR}{to specify the
       beginning day, hour, minute, and second and ending day, hour,
       minute, and second (wrt {\tt REFDATE}) of the data to be
       included.  Use an interval not unlike the one you used in {\tt
       FRING}.}
\dispt{INP \CR}{to check the inputs.}
\dispt{GO \CR}{to produce a new {\tt SN} table with a suitable left
       polarization delay.}
\dispe{Note that {\tt RLDLY} now always creates an {\tt SN} table and
may be run with multiple calibrator scans.  If there is only one
calibrator scan and {\tt APARM(2)}$\leq 0$, it will also copy the {\tt
CL} table which was applied to the input data through {\tt GAINUSE} to
a new {\tt CL} table applying the correction to the L polarization
delay.  For all other cases, you must apply the added L polarization
delays with {\tt CLCAL}\@.\Iodx{EVLA}}

It is probably better to determine a continuum solution for source
polarization and antenna D terms before doing the lower
signal-to-noise spectral solutions.  To find an average solution for
each IF:
\dispt{DEFAULT\qs \Tndx{PCAL} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{CALSOUR\qs '{\it pol\_cal1\/}', '{\it pol\_cal2\/}'  \CR}{to
       select the polarization calibrator(s) by whatever form of their
       names appears in your {\tt LISTR} output.  These sources must
       have I polarization fluxes in the source table.}
\dispf{ICHANSEL\qs $c11, c12, 1, if1, c21, c22, 1, if2, c31, c32, 1,
       if3, \ldots\/$ \CR}{to select the range(s) of channels which
       are reliable for averaging in each IF\@.  These probably should
       be the same values that you used in {\tt BPASS}\@.}
\dispt{DOMODEL\qs -1; SPECTRAL\qs -1 \CR}{to solve for source
       polarization in a continuum manner.}
\dispt{PRTLEV\qs 1 \CR}{to see the answers and uncertainties on an
       antenna and IF basis.}
\dispt{CPARM\qs 0,1 \CR}{to update the source table with the calibrator
       source Q and U found.}
\dispt{INP  \CR}{to review the inputs.}
\dispt{GO \CR}{to find the antenna leakage terms and the source Q and
       U values on an IF-dependent basis.}
\dispe{{\tt PCAL} will write the antenna leakage terms in the antenna
file and the source Q and U terms in the source table (if {\tt
CPARM(2)} $> 0$).  {\tt DOMODEL} may be set to true only if the model
has ${\tt Q} = {\tt U} = 0$ since {\tt PCAL} cannot solve for the
right minus left phase difference.  If {\tt SOLINT=0}, {\tt PCAL} will
break up a single scan into multiple intervals, attempting to get a
solution even without a wide range of parallactic angles.}

Having prepared a continuum solution for Q and U, you must also
correct it for the difference in phase between R and L polarizations
which normally varies considerably between IFs.  The task {\tt RLDIF}
will correct the antenna, source, and calibration tables for this
difference using observations of a source with known ratio of Q to
U\@.  3C286 is by far the best calibrator for this purpose.
\dispt{DEFAULT\qs \Tndx{RLDIF} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{DOPOL\qs 1 \CR}{to apply the polarization calibration.}
\dispt{BCHAN\qs $c_1$; ECHAN\qs $c_2$ \CR}{to average data from
       channels $c_1$ through $c_2$ only.}
\dispt{SOURC\qs '{\it pol\_cal1\/}', '{\it pol\_cal2\/}'  \CR}{to
       select the polarization calibrator(s) by whatever form of their
       names appears in your {\tt LISTR} output.  These sources must
       have known polarization angles.}
\dispt{SPECTRAL\qs 0 \CR}{to do the correction in continuum mode.}
\dispt{DOAPPLY\qs 1 \CR}{to apply the solutions to a {\tt CL} table
       (making a new modified one) and to the {\tt AN} and {SU}
       tables, updating them in place.}
\dispt{DOPRINT\qs 0 \CR}{to omit all the possible printing.}
\dispt{INP\qs \CR}{to review the inputs.}
\dispt{GO \CR}{to determine and apply the corrections.}

\begin{figure}
\centering
%\resizebox{\hsize}{!}{\gname{PDpcal}}
\resizebox{\hsize}{!}{\gbb{703,462}{PDpcal}}
\caption[Example antenna D term spectrum]{Example spectrum showing D
term solutions for one antenna in right and left polarizations
covering about 2 GHz at C band}
\label{fig:PCALspec}
\end{figure}

The EVLA polarizers appear to be very stable in time, but to have
significant variation with frequency.  See Figure~\ref{fig:PCALspec}.
Serious polarimetry with the EVLA will {\it require} solving for the
antenna \indx{polarization} leakage as a function of frequency.  To
compute a spectral solution, assuming you already did the process in
the preceding paragraph: \todx{PCAL}\Iodx{EVLA}
\dispt{TGET\qs PCAL \CR}{to retrieve the {\tt PCAL} adverbs.}
\dispt{SPECTRAL\qs 1 \CR}{to do the channel-dependent mode.}
\dispt{DOMODEL\qs 0 \CR}{to solve for Q and U as a function of
       frequency.  Because {\tt PCAL} does not solve for a right-left
       phase difference and that difference is a function of spectral
       channel, you must solve for a source polarization.}
\dispt{INTPARM\qs $p_1, p_2, p_3$\qs \CR}{to smooth the data after
       all calibration has been done while honoring {\tt ICHANSEL}.}
\dispt{SPECPARM\qs 0 \CR}{to determine the calibration source I, Q,
       and U spectral indices from fluxes in the source table.  If you
       use {\tt PMODEL} you must provide spectral indices for the
       model that apply in the frequency range of the data (curvature
       cannot be specified).\iodx{spectral index}}
\dispt{INP \CR}{to review the inputs, the task will take a while to
       run.}
\dispt{GO\qs \CR}{to run the task writing a {\tt PD} table of spectral
       leakages (``D terms'') and, if {\tt DOMODEL} $\leq 0$, a {\tt
       CP} table of source Q and U spectra.}
\dispe{If the combination of flagging, {\tt ICHANSEL}, and {\tt
INTPARM} results in no solutions for some channels, the solutions from
nearby channels will be interpolated or extrapolated so that all
channels get solutions.}

After running {\tt \Tndx{PCAL}} in spectral mode, you may examine the
resulting {\tt PD} (\indx{polarization} D terms) table with {\tt
\tndx{POSSM}} using {\tt APARM(8)=6} and {\tt \tndx{BPLOT}} using {\tt
INEXT = 'PD'}\@.  If a {\tt CP} table (calibrator polarization) was
written, you may also use {\tt POSSM} with {\tt APARM(8) = 7} or 8 and
{\tt BPLOT} with {\tt INEXT = 'CP'} to examine the results.

You are almost, but not quite done.  The combination of {\tt CALIB}
and {\tt BPASS} has produced a good calibration for everything except
the phase difference between right and left polarizations.  This is
now a function of spectral channel and needs to be corrected.  The
task {\tt \Tndx{RLDIF}} has been modified to determine a continuum or
spectral right minus left phase difference and to modify the {\tt CL}
or {\tt BP} table, respectively, to apply a phase change to the left
polarization on an IF or channel, respectively, basis.  Thus
\Iodx{EVLA}
\dispt{DEFAULT\qs \Tndx{RLDIF} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{DOPOL\qs 1 \CR}{to apply the polarization calibration, spectral
       if present.}
\dispt{INTPARM\qs $p_1, p_2, p_3$\qs \CR}{to smooth the data after
       all calibration has been done.}
\dispt{BCHAN\qs $c_1$; ECHAN\qs $c_2$ \CR}{to use solutions from
       channels $c_1$ through $c_2$ only, extrapolating solutions to
       channels outside this range.\Iodx{EVLA}}
\dispt{SOURC\qs '{\it pol\_cal1\/}', '{\it pol\_cal2\/}'  \CR}{to
       select the polarization calibrator(s) by whatever form of their
       names appears in your {\tt LISTR} output.  These sources must
       have known polarization angles.}
\dispt{POLANGLE\qs $p_1, p_2$ \CR}{to provide the task with the source
       polarization angle(s) in degrees in source number order.  The
       phase correction will be twice this value minus the observed
       RL phase.  Do not provide values for 3C286, 3C147, 3C48, and
       3C138.  These are known to {\tt RLDIF} including rotation
       measures and other spectral dependence.}
\dispt{SPECTRAL\qs 1 \CR}{to do the correction in spectral mode.}
\dispt{DOAPPLY\qs 1 \CR}{to apply the solutions to a {\tt BP} table
       (making a new modified one) and to the {\tt PD} and {CP}
       tables.}
\dispt{DOPRINT\qs -1 ; OUTPRI\qs '{\it file\_name}' \CR}{to write the
       phase corrections applied to a text file suitable for plotting
       by {\tt PLOTR}.}
\dispt{INP\qs \CR}{to review the inputs.}
\dispt{GO \CR}{to determine and apply the corrections.}

Use {\tt UVPLT}, {\tt LISTR} or {\tt POSSM} to check that the expected
RL and LR phases now appear with all calibrations turned on.
Following these steps, you apply the \indx{polarization} calibration
in any task offering {\tt DOPOL}.  A value of 1 will apply the
spectral solution if present or the continuum one is there is no {\tt
PD} table.  A value of 6 for {\tt DOPOL} requests the continuum
solution despite the presence of a spectral solution.  Use {\tt POSSM}
to plot the calibration sources in RL, LR, Q, and U polarization to
make sure that all has functioned correctly (these are newly revised
tasks).\Iodx{EVLA}

If you do not have good observations of a polarization angle
calibrator, it may be possible to correct the data in some
circumstances.  See the help files for {\tt \tndx{QUOUT}} and {\tt
\tndx{QUFIX}} for possible methods.

If you think that the right minus left phase of your reference antenna
was not stable over time, but you have produced good model images of Q
and U ignoring that, then it may be possible to improve the
polarization calibration with the task {\tt \tndx{RLCAL}}\@.  It does
a self-calibration of Q and U to find a time-variable right minus left
phase to apply to the data.

\Sects{Target source data --- edit and {\tt SPLIT}}{evlaSplit}

At this point, your calibration should be finished.  You should now do
an initial editing on the target sources, much like that done above
for the calibration sources.  Run {\tt RFLAG} on the target source(s)
and perhaps use:
\dispt{DEFAULT\qs \tndx{TVFLG} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{BCHAN\qs $c1$ ; ECHAN\qs $c2$ \CR}{to average across a range of
       channels --- not as flexible as {\tt ICHANSEL} but probably
       okay here.}
\dispt{BIF\qs $j$ ; EIF\qs BIF \CR}{to edit one IF only, which will
       suffice for problems that are not IF dependent, such as drop
       outs, antenna not on source, etc.  Choose an IF that is
       reasonably free of RFI\@.}
\dispt{NCHAV\qs ECHAN-BCHAN+1 \CR}{to average all the channels into
       one number.}
\dispt{CALCODE\qs '-CAL' \CR}{to do just target sources now.}
\dispt{DPARM(6)\qs $\Delta\ t$ \CR}{to do no time averaging in the
       work file set $\Delta\ t$ to the data interval in seconds.}
\dispt{GO \CR}{to start the task.}
\dispe{Again, remember to set it to flag all channels and IFs.  You
may have to select sub-windows and force the averaging to one times
$\Delta\ t$ to edit in detail, or perhaps the default time averaging
will be beneficial.  In general, the {\tt DISPLAY AMP V DIFF} is a
powerful way to catch bad amplitudes and phases.  It will catch
drop outs either as bright lines for strong sources or dark grey ones
for weak sources.}

Since \Indx{EVLA} data sets tend to be large and unwieldy, it is
recommended that you separate the data into the separate target
sources, applying the current calibration and flagging once and for
all.  The imaging task {\tt IMAGR} can do this on the fly, but,
especially for observations of spectral-line sources, this is
excessively expensive.
\dispt{DEFAULT\qs \tndx{SPLIT} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{CALCODE\qs '-CAL' \CR}{to do just target sources now.}
\dispt{GO \CR}{to write out separate calibrated data sets for each
       target source.}

A task new to {\tt 31DEC13} will help calibrate data sets which
contain a strong, \eg\ maser, line in one or a few channels with
interesting but weaker signals in other channels and/or the continuum.
After applying the best standard calibration described above, you can
split out the maser channel(s) with {\tt UVCOP}\@.  Make images and
self-calibrate following the processes described in \Rchap{image}
making an {\tt SN} table containing the full calibration needed to
apply to the maser.  Then use task {\tt \tndx{SNP2D}} to convert this
into delays and phases to apply to the full, multi-IF data set.  This
will work so long as the residual phases found in the self-cal are
small and is actually required to do the best calibration possible
over very wide bandwidths.

Unless {\tt \tndx{TYAPL}} has been used, \Indx{EVLA} data sets have
weights which only reflect the integration time in seconds.
Calibration routines do not change these weights when changing the
data amplitudes.  There is a task called {\tt \Tndx{REWAY}} which
computes a robust rms over spectral channels within each IF and
polarization.  It can simply base the weights on these on a
record-by-record, baseline-by-baseline basis.  Alternatively, it can
use a scrolling buffer in time so that the robust rms includes data
for a user-specified number of records surrounding the current one.  A
third choice is to average the single-time rmses over a time range and
then convert them to antenna-based rmses.  In all three modes, the
task can then smooth the rmses over time applying clipping based on
user adverbs and the mean and variance found in the rmses.  A flag
table (extension file) may be written to the input data file removing
those data found to have rmses that are either too high or too low.
For these weights to be meaningful, the bandpass and spectral
polarization calibration must be applied and it helps to omit any RFI
or other real spectral-line signal channels from the rms computation.
For the weights to be correctly calibrated, all amplitude calibration
must also be applied.  For these reasons, {\tt REWAY} might well be
used instead of {\tt SPLIT} --- when {\tt TYAPL} was not used ---
running it one source at a time.  Thus,
\dispt{DEFAULT\qs \tndx{REWAY} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it n\/}; GETN\qs {\it m\/} \CR}{to select the data
       set on disk $n$ and catalog number $m$.}
\dispt{DOCAL\qs 1 ; DOBAND\qs 3 \CR}{to apply the delay, complex gain,
       and bandpass calibration.}
\dispt{SOURCE\qs '$target_1$' , ' ' \CR}{to do one target source.}
\dispt{APARM\qs 11, 30, 12, 0, 10, 4 \CR}{to use a rolling buffer of 11
       times separated by no more than 30 seconds and then smoothed
       further with a Gaussian 12 seconds in FWHM\@.  Data are flagged
       if the rms is more than 4 times the variance away from the mean
       averaged over all baselines, IFs, and polarizations.  Flagging
       on the variance of the rms from the mean on a baseline basis is
       essentially turned off by the 10.}
\dispt{GO \CR}{to write out a calibrated, weighted data set for the
       first target source.}
\dispe{Then, when that finishes}
\dispt{SOURCE\qs '$target_2$' , ' ' ; GO \CR}{to do another target
       source.}
\dispe{It is not clear that this algorithm is optimal, but it
certainly should be better than using all weights 1.0 throughout.  It
will be interesting to compare data weights found with {\tt TYAPL} to
those found with {\tt REWAY}\@.  The task now displays statistical
information to assist the user in determining which weights are
excessively high or low.}

\sects{Spectral-line imaging hints}

Some spectral-line data sets contain only a few spectral windows, each
with a great many spectral channels.  The continuum subtraction
task {\tt UVLSF} requires that the continuum signal be a linear
function of channel across each spectral window.  Converting the data
to more spectral windows with task {\tt \tndx{MORIF}} or  {\tt
\tndx{REIFS}} may make the data come closer to this requirement.
Having more spectral windows with fewer channels may also speed up
imaging in the {\tt LINIMAGE} procedure mentioned below.

In many spectral-line observations you will want to separate the
continuum signal from the channel-dependent signals.  This is
discussed in some detail in \Sec{linecsub}.  The larger number of
channels from the \Indx{EVLA} does mean that continuum may be
estimated with greater accuracy than when there were rather few
channels which were both free of edge effects and spectral-line
signal.  The wider total bandwidth may, however, invalidate the
assumption that the continuum signal at each visibility point can be
represented by a polynomial of zero or first order.  If there is a
single dominant continuum source offset from the phase center, the
assumption may be rendered valid by shifting the data with {\tt UVLSF}
to center the continuum source temporarily in order to subtract it.
To examine this assumption and to determine which channels appear safe
to use as ``continuum'' channels, use {\tt \tndx{POSSM}}\@.
\dispt{DEFAULT\qs POSSM ; INP}{to set the task name and clear the
      adverbs.}
\dispt{INDI\qs {\it Tn\/}; GETN\qs {\it Tm\/} \CR}{to select the
       calibrated line data set on disk $Tn$ and catalog number $Tm$.}
\dispt{DOTV\qs 1 ; NPLOTS\qs 1 \CR}{to plot only on the TV, one
       baseline at a time.}
\dispt{ANTEN\qs {\it n1 , n2 , n3 , n4} \CR}{to select the antennas
       nearest the center of the array}
\dispt{BASELINE\qs ANTEN \CR}{and only them.}
\dispt{BIF\qs {\it j} ; EIF\qs BIF \CR}{to plot one IF at a time.}
\dispt{APARM\qs 0 \CR}{to  display vector averaged spectra.
       Scalar averaged spectra will turn up at the edges reflecting
       the decreased signal to noise in the outer channels which will
       assist in determining channels that should be omitted.}
\dispt{GO \CR}{to run the task.  Make notes of the desirable channels
       IF by IF\@.}
\dispe{Note also whether the continuum appears to be a linear function
of channel.  If so, then use {\tt \tndx{UVLSF}} to fit the continuum
signal, writing a continuum only and a spectral-line only data set:}
\dispt{DEFAULT\qs UVLSF ; INP}{to set the task name and clear the
      adverbs.}
\dispt{INDI\qs {\it Tn\/}; GETN\qs {\it Tm\/} \CR}{to select the
       calibrated line data set on disk $Tn$ and catalog number $Tm$.}
\dispf{ICHANSEL\qs $c11, c12, 1, if1, c21, c22, 1, if2, c31, c32, 1,
       if3, \ldots\/$ \CR}{to select the range(s) of channels which
       are reliable for fitting the continuum.  For a multi-IF data
       set, you will need to select the channel ranges carefully by
       IF\@.}
\dispt{ORDER\qs 1 \CR}{to select fitting the continuum in real and
       imaginary parts with a first order polynomial in channel
       number.  {\tt UVLSF} offers orders up to four, but they are not
       for the faint at heart and will give bad results if there are
       large ranges of channels left out of the fit due to line
       signals.}
\dispt{DOOUTPUT\qs 1 \CR}{to have the continuum which was fit written
       as a separate data set.  This may be used to image the
       continuum.}
\dispt{SHIFT\qs $\Delta x, \Delta y$ \CR}{to shift the phase center to
       the dominant continuum source temporarily for the fitting.}
\dispt{GO \CR}{to run the task.}
\dispe{Imaging the continuum output may, in addition to any
scientific value of the continuum image, provide additional flagging
and even self-calibration information which may be applied to the line
data.}

If {\tt UVLSF} cannot be used, flag the channels at the edges and
those with spectral signals using {\tt UVFLG}\@.  Construct a
continuum image with {\tt IMAGR} on this flagged, spectral-line data
set.  Note that you might want to reduce the size of the data set
with time averaging ({\tt UVAVG}) and/or channel averaging ({\tt
SPLIT} or {\tt AVSPC}) before beginning the imaging.  Imaging is
discussed in detail in \Sec{imagr} through \Sec{cleancc} and will not
be discussed here.  You may find that additional editing is needed and
that iterative self-calibration is of use.  Be sure to copy those
flags (but not the edge and spectral-signal flags) and final {\tt SN}
table back to the line data set.  Apply them with {\tt SPLIT} and then
subtract the final continuum model with {\tt UVSUB}\@.  It you have
had to use the \indx{spectral index} options of {\tt IMAGR}, you may
do the proper subtraction including these options with {\tt
\tndx{OOSUB}} rather than {\tt UVSUB}\@.

At present, the EVLA observing setup allows you to select the initial
frequency of observation based on a desired LSRK velocity in the
central channel.  From there, however, the observations are conducted
at a fixed frequency.  Furthermore, the information about rest
frequencies, source velocities, and even more fundaemtal parameters
such as reference frame (LSRK or barycentric) and type of velocity
(radio or optical) are lost.  {\tt SETJY} allows you to correct this.
First use {\tt SETJY} to set the desired rest frequencies (note that
they are allowed to be a function of IF) and the {\tt VELTYP} and {\tt
VELDEF}\@.  Then use {\tt OPTYEP='VCAL'} over all sources and IFs.
This will compute the velocities at which you observed for the first
time you observed each source and enter the values in the source
table.

Having done this, the task {\tt \tndx{CVEL}} may be used to shift
the visibility data to correct for the rotation of the Earth about its
axis as well as the motion of the Earth about the Solar System
barycenter and the motion of the barycenter with respect to the Local
kinetic Standard of Rest.  {\tt CVEL} works on multi-source as well as
single-source data sets.  It applies any flagging and bandpass
calibration to the data before shifting the velocity (which it does by
a carefully correct Fourier transform method).  Note, the use of
Fourier-transforms means that one {\it must not} use {\tt CVEL} on
data with channel separations comparable to the widths of some of the
spectral features.  Furthermore, narrow EVLA bands apparently have
sharp cutoffs at the edges which cause any continuum signal to
generate sine waves in amplitude after the FFT\@.  Therefore, {\tt
UVLSF} {\it must be run before} {\tt CVEL}\@.  The velocity
information used by {\tt CVEL} must be correct.  Use {\tt LISTR} and
{\tt SETJY} to insure this before using {\tt SPLIT} and {\tt CVEL}\@.
A special version of {\tt CVEL} has been written to correct not only
for the Earth's motion but also for planetary motion to observe a line
at rest with respect to a planet; see {\tt \tndx{PCVEL}}\@.

Spectral-line imaging of \Indx{EVLA} data will resemble that for the
old VLA except for the increased number of spectral channels and the
consequent increase in the data set size.  Since {\tt IMAGR} must read
the full data set to select the data for the next channel to be
imaged, it is important that the data set be small enough to fit in
computer memory if at all possible.  OSRO data sets may not need this
operation and skipping it may simplify any continuum imaging that you
wish to do.  However, separating the IFs into separate files will not
interfere with spectral imaging and will help with the data set size
problem:
\dispt{DEFAULT\qs \tndx{UVCOP} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it Tn\/}; GETN\qs {\it Tm\/} \CR}{to select the
       calibrated target data set on disk $Tn$ and catalog number
       $Tm$.}
\dispt{DOWAIT\qs 1 \CR}{to have the task resume {\tt AIPS} only after
       it has finished.}
\dispt{OUTSEQ\qs 0 ; OUTDISK\qs INDISK \CR}{to avoid file name issues
       and select the output disk.}
\dispt{FOR BIF = 1 TO $N$; EIF = BIF ; GO; END \CR}{\hspace{1em} to
       make separate files of each of the $N$ IFs.}
\dispt{DOWAIT\qs -1 \CR}{to turn off waiting.}
\dispe{Doing this {\tt UVCOP} step on large data sets will be worth
any extra trouble it may cause.  A {\tt RUN} file and procedure called
{\tt \tndx{LINIMAGE}} has been written to assist in this process.  It
even runs {\tt FLATN} and reassembles the images from the separate IFs
into cubes with {\tt MCUBE} or {\tt FQUBE} if necessary.  Note that
you could perform the separation into separate IFs before {\tt UVLSF}
which will speed up {\tt POSSM} and {\tt UVLSF}.  However, the
continuum output would then have to be assembled using {\tt VBGLU},
which is why the steps above were shown in the present order.}

Spectral-line imaging is discussed in \Sec{lineimag} as well as
throughout \Rchap{image}.  With large numbers of spectral channels,
you may wish to have {\tt IMAGR} find appropriate Clean boxes for you.
Set {\tt IM2PARM(1)} through {\tt IM2PARM(6)} cautiously.  {\tt
IM2PARM(7)} controls whether the boxes of channel $n$ are passed on to
channel $n+1$.  The default does not pass the boxes along when
auto-boxing which is probably the correct decision.  The end result of
the imaging will be one image ``cube'' for each IF since each IF has
to be imaged separately even with a multi-IF input data set.  (If you
set {\tt BIF = 1; EIF = 0} and try to image channel 103, you will
actually image the average of channel 103 from each of the IFs.)  To
put the individual cubes together into one large cube, use {\tt MCUBE}
(\Sec{mcube}).

The wide bandwidths of the EVLA have revealed an error in the old
code.  {\tt IMAGR} and {\tt MCUBE} now control the units of data cubes
carefully, making sure that each plane is in units of Jy per {\it
header} beam.  The actual restoring beamwidths used are now maintained
in a {\tt CG} table.  This allows the best resolution to be used in
each plane and the approximate match between the units of the residual
image and the restored components to be maintained, while still
returning correct fluxes when integrating brightness over area.  {\tt
CONVL} with {\tt OPCODE = 'GAUS'} will now use the {\tt CG} table to
find the exact Gaussian needed to produce a constant resolution in
each plane.  Use of {\tt BMAJ = 0} in {\tt IMAGR} followed by {\tt
CONVL} is now the best way to insure a constant resolution with
correct image units throughout.

\sects{Continuum imaging hints}

The first problem that continuum observers will notice with their
\Indx{EVLA} data is that the spectral and time resolution of the data,
by default anyway, will be rather more than their science requires.
It will be possible to instruct the software which extracts data from
the archive to do some averaging in both frequency and time.  However,
detailed editing for RFI and other issues may require excellent
resolution in both these domains.  After the data have been edited,
you can average data in both domains so long as you are careful not to
average so much that you produce radial (bandwidth) and/or transverse
(time) smearing within the image area.  Note that the increased
sensitivity of the EVLA will increase the area over which
non-negligible astronomical objects may be found while the wide
bandwidth will mean that lowest frequency part of your band will be
sensitive, because of its larger primary beam, to a much larger area
on the sky than the highest frequency part.  The spectral averaging
can be done with {\tt SPLIT}; use {\tt APARM(1)=1} and set {\tt
NCHAV}, {\tt CHINC}, and perhaps {\tt SMOOTH} appropriately.
Similarly, {\tt AVSPC} can be used with {\tt AVOPTION='SUBS'}, setting
{\tt CHANNEL} and {\tt SMOOTH} suitably.  You will almost certainly
wish to retain some spectral separation, so do not use the ``channel
0'' option.

Time averaging should be done with {\tt UVAVG}:
\dispt{DEFAULT\qs \tndx{UVAVG} ; INP}{to reset all adverbs and choose
       the task.}
\dispt{INDI\qs {\it Sn\/}; GETN\qs {\it Sm\/} \CR}{to select the
       calibrated target data set on disk $Sn$ and catalog number
       $Sm$.}
\dispt{YINC\qs $\Delta t$ \CR}{to average to $\Delta t$ seconds.}
\dispt{OPCODE\qs 'TIME' \CR}{to have all samples in a given interval
       written with the same time; this helps with self-cal.  Other
       options are available.}
\dispt{GO \CR}{to produce the averaged data set.}
\dispe{{\tt UBAVG} will do a more aggressive averaging, using
baseline-dependent time intervals appropriate for the desired field
of view.  Do not use {\tt UBAVG} if you are planning to use
self-calibration since it destroys the time regularity in the data on
which {\tt CALIB} depends.  {\tt IMAGR} may now do this extra
averaging for you on the fly to reduce the size of the work file it
uses.  Set {\tt IM2PARM(11)} and {\tt (12)}.}

Imaging of the continuum is discussed at great length in \Rchap{image}
and those details will not be repeated here.  Bandwidth-synthesis
imaging, which will be the only form of continuum imaging with the
\Indx{EVLA}, will make certain adverbs more important.  Set {\tt
BCHAN} and {\tt ECHAN} to avoid the noisier edge channels.  Set {\tt
NCHAV = ECHAN - BCHAN + 1} and {\tt CHINC = NCHAV}.  This will then
image all of your IFs and spectral channels into a single image,
positioning each channel correctly in the $uv$ plane.  With the EVLA,
you will be imaging a wider field of view than you did with the VLA\@.
Use {\tt SETFC} with {\tt IMSIZE 0 ; CELLSIZE 0} to see if you should
image with a single facet or with multiple facets.  If using multiple
facets and trying for significant dynamic range, start imaging with
{\tt OVERLAP 2 ; ONEBEAM -1}, but consider {\tt OVRSWTCH = -0.05} or
so to switch into faster methods of Cleaning when the dynamic range in
the residual is small enough.

It has been widely noted that the noise in the outer channels of each
IF (spectral window) is higher than in the more central channels.  You
may wish to experiment with down-weighting channels by a function of
the bandpass correction amplitude.  In {\tt 31DEC13}, task {\tt
\tndx{BPWGT}} offers several options for doing just this, using {\tt
WEIGHTIT} to control what exponent of the bandpass amplitude is used
in the correction.  A solution, which should be better, is availble in
{\tt 31DEC14} with task {\tt \tndx{BPWAY}}\@.  This task operates on
ether a scan-by-scan or a source-by-source basis to evaluate the rms
as a function of time on each channel individually.  It determines the
rms on short intervals, like {\tt RFLAG}, normalizes them over each
spectral window, and then smooths the normalized rmses over time
functions which can be quite long.  The results are then applied to
the data to modify the weights on a channel-by-channel,
baseline-by-baseline basis.  This process should allow data from the
edges of the spectral windows to be used appropriately, especially in
bandwidth synthesis.  Note however, that channel 1 in each window
includes signal from both that channel and from channel $N_{\rm chan}
+ 1$ (due to aliasing) and so is probably best ignored.

{\tt IMAGR} allows you to request automatic finding of the Clean boxes
({\tt IM2PARM} of 1 through 6).  In cases with low sidelobes, this
works rather well, but you should probably keep an eye on what it does
with {\tt DOTV 1} in any case.  {\tt IM2PARM(12)} controls the
baseline-dependent time averaging while specifying the maximum field
of view you expect.  This allows you to reduce the size of the work
file considerably which will at least reduce the time required for
many of the steps in the imaging proportionally.  It may be rather
better than that if the work file is very large otherwise, requiring
actual reading of the disk every time the data are accessed.  Note,
however, that the uniform weighting of your data will be affected.
This averaging reduces the number of samples at short spacings
disproportionally and so appears to reduce their weight in the
imaging.  Some {\tt UVTAPER} could be used to compensate for this.

By default, bandwidth synthesis imaging assumes that the primary beam
and all continuum sources are the same at every frequency.  In fact,
the primary beam size varies linearly with frequency (to first order
anyway) and sources have spectral index.  {\tt IMAGR} will allow you
to compensate for the average spectral index at almost no cost with
{\tt IMAGRPRM(2)}\@.  A far more accurate and expensive correction for
\indx{spectral index} may be made if you do the following.  First
image each spectral channel (or group of closely-spaced channels)
separately.  Combine them into a cube with {\tt \tndx{FQUBE}},
transpose the cube with {\tt TRANS}, and solve for spectral index
images with {\tt \tndx{SPIXR}}\@.  To use these images, set {\tt
IMAGRPRM(17)} to a radius ($> 0$) in pixels of a smoothing area and
put the image name parameters in the 3rd and 4th input image names.
Note that this algorithm is expensive, but that it can be sped up with
judicious use of the {\tt FQTOL} parameter.  The change of primary
beam with frequency may be corrected by setting {\tt IMAGRPRM(1) = 25}
for the diameter of the \Indx{EVLA} dishes.  Note that this algorithm
is expensive, but that it can be sped up with judicious use of the
{\tt FQTOL} parameter.  These two corrections work together, so that
doing both costs very little more than doing just one of them.

A {\tt RUN} file and procedure named {\tt \tndx{OOCAL}} has been
written to do self-calibration using the spectral-index image(s) and
primary-beam correction in the manner used in {\tt IMAGR}\@.  The
procedure runs {\tt OOSUB} to produce a divided data set, then {\tt
CALIB} to solve for complex gains, and finally {\tt TACOP} to move the
{\tt SN} table to the real input data set.  If your model is a large
image rather than Clean components, the procedure {\tt \tndx{IMSCAL}}
in this {\tt RUN} file will convert the model image into faceted Clean
components and then run {\tt OOCAL}\@.  Similar procedures for {\tt
FRING}, called {\tt \tndx{OOFRING}} and {\tt \tndx{IMFRING}} are also
available.

If you are observing a strong source and trying for very high dynamic
range, you may have to correct for errors that are baseline- rather
than antenna-dependent.  One source of these errors is the antenna
polarization leakage which affects the parallel-hand visibilities in a
non-closing fashion.  Task {\tt \tndx{BLCAL}} can be used after you
have as good an image as you can get without it.  This task will
divide the data by the model and average over a user-specified time to
find baseline-dependent corrections which may then be applied to the
data by setting adverb {\tt BLVER}\@.  We recommend that you average
the divided data over all of the times in your data to get a single
correction for each baseline (and IF and polarization).  If you use
shorter intervals, you run the risk of forcing your data to look too
much like your model.  Since the polarization leakage is probably a
function of frequency, an experimental version of {\tt BLCAL} called
{\tt \Tndx{BLCHN}} has been released.  It determines the same
correction but does not average over channels.  {\tt BLCHN} can even
adjust the resulting correction table to correct for spectral index
prior to applying and storing the values.  The correction is saved in
a table which {\tt \tndx{POSSM}} and {\tt \tndx{BPLOT}} are able to
display.  However, the calibration routines do not know how to apply
this table, so {\tt BLCHN} writes out the corrected data as well as
the table.  A new task called {\tt \tndx{BDAPL}} has been written to
apply this {\tt BD} table to another data set.

{\tt 31dEC16} contains a new TV-menu driven editing task called {\tt
\Tndx{UFLAG}}\@.\footnote{Greisen, E. W. 2016, ``Editing on a $uv$
grid in \AIPS'' AIPS Memo 121, {\tt
http://www.aips.nrao.edu/aipsdoc.html}}  If your image shows stripes,
indicative of residual bad data, this task allows you to view the data
as it is gridded for imaging and to flag bad cells in the $uv$ plane
or even some, but not all, of the individual visibilities contributing
to apparently bad cells.\Iodx{EVLA}

\sects{Additional recipes}

% chapter   *************************************************
\recipe{Columbian fresh banana cake with sea foam frosting}

\bre
\Item {Open an 18.5 oz {\bf yellow cake mix} into a large mixxing
   bowl; do not use a mix that contains pudding or requires oil.
   Combine with 1/8 teaspoon {\bf baking soda}.}
\Item {Stir 3/4 cup {\bf Coca-Cola} briskly until foaming stops.
   Add to cake mix and blend until just moistened.  Then beat at high
   speed for 3 minutes, scraping the bowl often.}
\Item {Combine 2 teaspoons {\bf lemon juice} with 1 cup mashed {\bf
   bananas} and then add to batter.  Add 1/3 cup finely chopped {\bf
   nuts} and beat for 1 minute at medium speed.}
\Item {Turn the batter into a well greased, lightly floured 9x13
   baking dish. Bake in a preheated \dgg{350} oven for about 40
   minutes or until the cake tests done.   Cool on a rack for 15
   minutes, remove cake from pan and turn right side up on a rack to
   finish cooling.}
\Item {In the top of a double boiler, combine 2 large {\bf egg
   whites}, 1 1/2 cups packed {\bf light brown sugar}, 1/8 teaspoon
   {\bf cream of tartar} (or 1 tablespoon corn syrup), and 1/3 cup
   {\bf Coca-Cola}.  Beat at high speed for 1 minute with an electric
   mixer.}
\Item {Place over boiling water --- the water should not touch the
   bottom of the top half of the double boiler.  Beat on high speed
   for about 7 minutes until the frosting forms peaks when the mixer
   is raised. Remove from boiling water.  Empty into a large bowl.}
\Item {Add 1 teaspoon {\bf vanilla extract} and continue beating on
   high speed until thick  enough to spread, about 2 minutes. Spread
   on the sides and top of the cold banana cake.}
\ere

% chapter *************************************************
\recipe{Chewy banana split dessert}

\bre
\Item {Prepare and bake one package (19.8 0z) chewy fudge (or
      other favorite) {\bf brownie mix}.  Allow to cool thoroughly,
      four hours or more.}
\Item {Peel 2 large ripe {\bf bananas} and place very thin
      slices on top of brownie.}
\Item {Cover bananas evenly with one 12-oz.~container of {\bf
       whipped topping} (thawed) and drizzle 1/2 cup {\bf chocolate
       syrup} over that.}
\Item {Refrigerate to chill completely.  Cut into squares to
       serve.}
\ere

\vfill\eject

% chapter *************************************************
\recipe{Banana July cocktail}

\bre
\Item {Sprinkle 3 sliced {\bf bananas} with 1 tablespoon {\bf lemon
     juice}.}
\Item {Mix with 1 1/4 cans drained and flaked {\bf tuna}, 1/2 {\bf
     onion} chopped, and 2 tablespoons chopped {\bf gherkins} or {\bf
     olives}.}
\Item {Spoon into 7 cocktail shells.}
\Item {Melt 2 tablespoons {\bf butter} in a saucepan.  Add 2
     tablespoon {\bf cake flour} and salt and pepper to taste.}
\Item {Add 1/4 cup {\bf chicken stock} and 1/4 cup dry {\bf white
     wine}.  Simmer for one minute stirring constantly.}
\Item {Add 1/3 cup grated {\bf cheddar cheese} and allow to cool.}
\Item {Add 1/4 cup fresh cream to sauce and pour over banana-tuna
     mixture.}
\Item {Sprinkle with 1 tablespoon grated {\bf cheese} and {\bf
     paprika}.  Decorate with a slice of {\bf gherkin} or {\bf
     olive}.}
\Item {Bake 15--20 minutes at \dgg{350};  serve warm.}
\item[ ]{\hfill Thanks to Turbana Corporation ({\tt www.turbana.com}).}
\ere

% chapter *************************************************
\recipe{Banana Dream Pizza}

\bre
\Item {Preheat oven to \dgg{400}.  In a large bowl, combine 2 1/2 cups
       {\bf all-purpose flour}, 2 tsp {\bf baking powder}, and a pinch
       of {\bf salt}.  Add 4 Tsp softened {\bf sweet cream butter} and
       blend.  Add 3/4 cup warm {\bf milk} and mix well.  If the dough
       is still sticky, add a small amount of flour.}
\Item {Form the dough into a ball.  Knead it on a floured surface
       until it is smooth.  Roll out the dough and place it in an
       oiled, 16-inch pizza pan.  Bake for 15-20 minutes, or until the
       crust is light brown.}
\Item {In a nonmetallic bowl, mash 4 {\bf bananans}.  Add 1 teaspoon
       {\bf lime or lemon juice} and 6 tablespoons {\bf honey}; mix
       well.}
\Item {Slice 2 {\bf bananas} horizontally and place the slices in
       water to cover.  Add 1 teaspoon {\bf lime or lemon juice} to
       prevent discoloration.}
\Item {Spread the banana mixture on the crust.}
\Item {Drain the sliced bananas and blot them with paper towels.
       Place them in a circular pattern on the banana mixture.  Baste
       the banana slices with  3 tablespoons {\bf melted butter}.}
\Item {Bake for 20--30 minutes at \dgg{400} until the crust is golden
       brown.}
\Item {Remove from the oven and top with 1 quart {\bf vanilla ice
       cream} and 1/2 cup chopped {\bf macadamia nuts} while still
       hot.  Serve immediately.}
\ere

\sects{Concluding remarks, early science}

\AIPS\ itself, and particularly this appendix, do not begin to cover
all of the issues that will arise with \Indx{EVLA} data.  The
increased sensitivity of the EVLA will mean that imaging will no
longer be able to ignore effects that are difficult to correct such as
pointing errors, beam squint, variable antenna polarization across the
field, leakage of polarized signal into the parallel-hand
visibilities, etc.,~etc.  These are research topics which may have
solutions in \AIPS\ or other software packages such as {\tt OBIT} and
{\tt CASA} eventually.

%\sects{Additional recipe}

\vfill\eject

\begin{figure}[!ht]
\centering
%\resizebox{\hsize}{!}{\gname{OrionA}\hspace{0.5cm}\gname{OrionB}}
%\resizebox{\hsize}{!}{\gbb{272,699}{OrionA}\hspace{0.5cm}\gbb{272,699}{OrionB}}
\resizebox{5.8in}{!}{\gbb{272,699}{OrionA}\hspace{0.5cm}\gbb{272,699}{OrionB}}
\caption[Orion hot core at K band]{{\bf Early EVLA science:} The
spectrum of the hot core of Orion A at K band.  Three separate
observations of 8192 channels each 0.125 MHz wide were made using 12
antennas in the D array.  Two hours total telescope time went into
each of the two lower thirds of the spectrum and 1 hour was used for
the highest third.  The plot was made using {\tt ISPEC} over a 54 by
60 arc second area.  Line identifications provided by Karl
Menten.\Iodx{EVLA}}
\label{fig:OrionKband}
\end{figure}

%\vfill\eject
