In more common ALMA cases, first check the CASA logger, see Fig. 9.

Figure 9: CASA logger messages from gaincal. The total, ’expected’, is the sum
of (scan length)/(solution interval), rounded up per scan, per spw and per
polarisation unless these are averaged (but irrespective of the number of
antennas). ’attempted’ is the number after subtracting intervals flagged
(previously, or by existing calibration tables applied as gaincal gaintables).
succeeded is the number of solutions which converged using the input
parameters; this does not guarantee that they are suitable to apply to the
data.

As explained in Appendix C.2 it is safest not to use failed solutions for
flagging, i.e. set applycal applymode=’calonly’, calwt=False  at least until
you are sure that all the parameters and the model used to derive solutions
are optimum. If the minimum solution interval from Eq. 24 is more than a scan,
or some or all antennas/times are hard to calibrate, refer to see Sec. 5.10.
Additional tips are given in Brogan et al. (2018) sec. 2.3.5. Distinguish
between:

Improvable

data especially at the start of self-calibration. Even if many solutions fail
or show a large scatter, check the visibilities. If the data are not obviously
bad, try improving the model or parameters in gaincal. You can discard the
guilty image and/or gain table (see towards the end of Sec. 4.1) and try again
with different imaging or calibration parameters. Or, if phase referencing may
not have been very good, pass the failed solutions (applycal
applymode=’calonly’) for the initial rounds and hope that fewer fail as the
model improves.

Unselfcalibratable

data which has had good phase calibrator corrections applied. The target may
be much too faint, so there is no point trying. However, if it is borderline,
or some antennas have lower S/N (e.g. extended source/long baselines) you may
find many solutions (say, 20–50%) fail in self-calibration, but the rest are
fairly good. The data giving failed solutions have had the phase calibrator
corrections applied, so if they are not obviously bad, usually it is best to
let them pass. You can test by making an image without flagging, then back up
the flagging state and repeat applycal with calmode=’calflag’ and re-image; if
this image is worse, restore the flags. Also compare with no self-calibration.

Useless

data, e.g. pure noise, zero amplitudes. If the data cannot be salvaged, see
Sec. 4.6.3.

####  4.6.1 Assessing phase solutions

This section gives examples of what to look out for in phase solution tables.
Fig. 4 bottom left shows per-scan (large circles) phase solutions for a phase
calibrator, which follow a mostly consistent trend with time, demonstrating
that they can be interpolated reasonably accurately across the target data,
such that the residual self-calibration solutions, Fig. 8 left, are within
$(\pm 60^{\circ})$, approximately the phase changes between phase calibrator
scans. More examples of gain tables are given in Fig. 10. These are mostly
plotted using fixed ranges on the axes. When looking at other tables, make
sure to check the scales before jumping to conclusions.

(a) DV15 is the reference antenna with zero phase solutions. DV07 and DV19 solutions change smoothly, within the scan to scan differences between the phase calibrator solutions previously applied. Small jumps in the centre of some scans are due to having used applycal interp=’nearest’ (not linear). All antennas have a similar number of solutions. |
---|---
(b) If phase calibrator solutions have not been applied, a larger solution range, even wrapping through 180∘, may be seen. If the data were phase referenced, check that the solutions were applied and the model is correct. Even in this case, a high phase solution rate may be reasonable if the phase changes rapidly (which would also be seen for the phase calibrator). |
(c) Here, the 30-s solutions for DV07 look quite noisy on short time scales but the average change per scan is just a few tens degrees. DV19 is worse with some periods appearing random and many failed solutions. The polarisations should be aligned (as in (a)) after applying initial phase solutions; the random offsets between X and Y (blue and green) solutions seen here are due to noise. It would be advisable to use a longer solution interval of 150s or 300s. |
(d) Many failed solutions but little scatter, as on DV19, suggests a lower minsnr and/or more averaging might be better, or possibly data have been lost due to deliberate flagging or previous failed solutions. |
(e) If solutions have 180∘ noise scatter on all antennas, try a longer solution interval or other averaging. Check that the correct previous calibration has been applied and the right model is present. If S/N is high, check the reference antenna/try a different one or see example (f), (g). Alternatively, maybe S/N is too low to self-calibrate. |
Figure 10: Target self-calibration phase solution examples. (a) and (b) are probably good solutions; (c) and (d) need better inputs (or flagging) and (e) may be all bad. In all plots with both blue and green spots they represent solutions for the X and Y polarisations. Continued next page.  (f) Most of these solutions look like noise but the first few DV07 scans show a high phase rate. Possibly prior calibration has been forgotten, or there is no phase-referencing. In such a case see Sec. 5.5; if the target is complex or peaks many beams from the phase centre it could be that the genuine corrections are undersampled. |
---|---
(g) Using solint = ’int’ for the (f) situation shows coherent solutions (it may be necessary to zoom; the lines are to guide the eye). If S/N is too low for short enough solution intervals, see Sec. 5.10.3 for fitting to the phase slope. |
(h) In each scan, the final solution has failed or is inconsistent relative to the general trend. A 96-s solution interval was used for 300-s scans so the last interval is only 12 s, with worse S/N. If you need just a few solutions per scan, use an exact divisor (e.g. 75 s in 300-s scans). Alternatively, bad solutions at the start or end of scans may be due to slewing, see Sec. 4.6.3. |
(i) When solutions are close to zero the data match the model within the noise; time to stop self-calibration. |
Figure 10: (continued) Target self-calibration phase solution examples. (f)
needs improved parameters, leading to good solutions in (g). (h) needs better
inputs or flagging and (i) shows no more phase calibration is needed.

####  4.6.2 Assessing amplitude solutions

For already well-calibrated data, amplitude solutions are likely to be within
$\lessapprox$20% of 1. Fig. 11 gives example solution tables. It is important
to check for low points555for AIPS check high points as the data are
multiplied by solutions as in CASA, the solutions are divided into the data,
so a low solution signifies weak visibility amplitudes and when that is
applied the associated noise will also be amplified. Check the phase solutions
but if these or the averaging interval can’t be improved, such data should be
flagged (Sec. 4.6.3).

The diagnostics are analogous to those for phase solutions with these
considerations:

Scan-length

solution intervals are often best if previous, good calibration has been
applied. For complex, high S/N sources try shorter intervals but you cannot
calibrate away noise. However, short solution interval amplitude gain tables
can be a quick way to identify bad data, which can then be flagged separately.
Discard the diagnostic table and repeat with a more suitable solution
interval.

Decorrelation

giving low amplitude solutions can occur due to previous bad phase solutions
(e.g. an unsuitable averaging interval) or intrinsic high phase noise – the
unaveraged amplitudes may look OK but the more averaging, the worse the
solutions. If the phase cannot be corrected, flag the data.

Contamination

from spectral lines which have not been excluded, but should be, can give bad
continuum self-calibration solutions (high and/or noisy).

Target flux

should stay about the same, i.e. solutions close to 1 (if flux scale
corrections have been applied, Sec. 2.2.1). The image flux density often
improves due to phase calibration (see Table 3) but the main effect of
amplitude self-calibration should be to reduce the noise rather than change
the image flux, see discussion of normalisation in Sec. 4.5. Using gaincal
solnorm=True is safest but solnorm=False is a good way to check for model
problems (gains very different from 1) See Fig. 11(n) for an example without
prior flux scaling.

(j) Amplitude self-calibration solutions should be close to 1, as for DV07, if previous calibration was good. Investigate scatter $\gtrapprox 10\%$. The large scatter on DV19 may be due to poor preceding phase solutions, a bad model or too low S/N. If S/N is enough, many cycles of self-calibration may be needed to improve the model, with shorter amplitude solution intervals. |
---|---
(k) Using a shorter solution interval for DV07 shows good results with a small variation close to 1, suggesting that the calibration is complete. There is a higher, noise-like scatter for DV19; if there are still amplitude errors a longer solution interval is needed. |
(l) DV07 single solutions $>$20% discrepant are probably due to bad data (but check previous phase solutions). Identical, low solutions on one antenna, DV19, show entirely bad data. Identical 1’s (0’s) on all antennas may mean that the table contains only phase (amplitude) solutions but amplitude (phase) is being plotted. |
(m) Amplitude solutions $\ll$1 are expected if the flux scale has not been corrected, e.g. no phase referencing. Otherwise it indicates a poor model or decorrelation (see Fig. 10(f)). Structure in good solutions, changing faster for antennas with more long baselines, DV19, shows a data-model discrepancy, e.g. due to a point model used for a complex source (see Sec. 5.5). |
(n) Although DV07 has lower solution amplitudes than DV19, the former also has smaller scatter, maybe due to a $T_{\mathrm{sys}}$ mis-scaling, not bad visibilities. Try making a model excluding DV07 and using this to derive amplitude solutions for all antennas (see Sec. 5.3). The variation within a scan is just noise so a longer solution interval is needed. |
Figure 11: Target amplitude self-calibration solution examples. (j), (k) and
(l) need some improved inputs. (m) may be good solutions if self-calibrating
without prior flux scale/amplitude calibration. (n) shows probably-good
solutions but DV07 needs re-scaling and a longer solution interval is needed.

####  4.6.3 Flagging

To check the cause of bad solutions, and remove bad data, the best practice is
to

  * •

Back up the current flagging state using flagmanager to make it easy to
restore or repeat flags if necessary.

  * •

Check the visibilities in plotms. Apply all good calibration and try different
averaging intervals if necessary and make a note of any bad data (see the help
for the locate function).

  * •

Write a script for flagdata.

Alternatively, you can use failed solutions to flag data in applycal
calmode=’calflag’, especially if only a few percent of solutions are affected
and it would not mean losing all the long baselines (or other vital data
scales), but make sure to back up the previous flagging state. For more
details see the CASA documentation for these tasks and, especially for cm-wave
data, which often needs far more flagging than ALMA data, the CASA Guide to
Flagging (VLA) (Appendix B.2)

Bad solutions at the start (or, occasionally, the end) of all or most scans
can be due to data recorded whilst the telescopes are slewing. Plot the data
with the shortest time-averaging needed to show any issues and this will show
up as low visibility amplitudes and phase noise. These can be flagged using
flagdata mode=’quack’.

###  4.7 Applying the calibration (applycal)

The task applycal is used to apply the tables derived using calibration tasks
such as gaincal. Some parameters can usually be left as default: see Appendix
B.3 for a link to the CASA documentation for applycal, for all options and
Appendix C.2 for some parameters and suggested values most relevant to ALMA
self-calibration.

####  4.7.1 Weights

Each visibility sample has amplitude and phase (as in Eq. 1) and also a
weight. The weights for ALMA (and most other telescopes) are initialised in
proportion to integration time, channel width etc., at the very start of
processing (importasdm) if CASA 4.2.2 or later was used by the standard
pipeline/QA2 scripts. The initial weights should be automatically modified
correctly in any visibility data averaging (proportional to the antenna
sensitivity and the time and frequency span of the data). However, by default,
all channels in each spw have the same weight. If channel-averaging is used
and channels have been selectively flagged, per-channel weights should be
derived. This can be achieved by using mstransform usewtspectrum=True to do
the averaging, or by running initweights, see the NRAO template script (link
in Appendix B.5) for an example.

The weights can also be modified when calibration is applied (applycal
calwt=True). The pipeline/QA2 applies weights derived during initial
calibration e.g. from $T_{\mathrm{sys}}$. The weights can occasionally be mis-
scaled or inconsistently scaled between observations; this is rare but if you
find otherwise inexplicable problems, the CASA Guide to Weights (see Appendix
B.2) describes what sensitivity-based weights should look like. Weights can be
plotted in plotms.

These weights will be retained when the target data are split out for self-
calibration. Weights can be further modified when applying self-calibration
gain tables, to downweight the data contributing noisier solutions. This will
improve the image S/N but reduce the contribution of target structure on the
scales of the downweighted spacings. This is a price worth paying for arrays
with good $uv$ coverage and/or if the source does not have important structure
on the corresponding scales. However, if, for example, most of the antennas
contributing the longest baselines have the greatest errors initially, the
smallest scales will not be represented properly in the image model and thus
the longest baselines will not be calibrated effectively, see Sec. 5.10. The
synthesized beam will also become larger, i.e. worse angular resolution. In
such cases it is safer to use calwt=False at least for the first rounds of
self-calibration. This is also the case for calibration of arrays of
telescopes of different sensitivities (e.g. VLBI, e-MERLIN).

As an alternative to calwt you can, after all calibration, use the separate
task statwt to modify the weights based directly on the scatter in the
visibilities. This requires selection of data where time-baseline fluctuations
are noise-dominated, so it will not work for targets with bright extended
structure and any spectral lines should be excluded. A more sophisticated
scheme for connecting the calibration and imaging weights is described by
Bonnassieux et al. (2018).

Calibration weights become part of the visibilities and can only be re-
initialised or modified using the CASA toolkit. Additional weights can be
applied to the uv data during the imaging process (see help for tclean). These
imaging weights do not affect the intrinsic data weights. In order to ensure
all available scales are represented in making self-calibration images, it is
best to use close to natural weighting (e.g. for ALMA, typically robust
$\geq$0.5) when preparing self-calibration models (see also Sec. 6.2). In
situations where some baselines are initially hard to calibrate, the first
rounds of calibration and imaging can use a restricted uvrange and uvtaper
(see Sec. 5.5). The ranges are expanded as the model improves in successive
rounds of calibration.

###  4.8 Modified workflows

Sec. 4.1 described incremental self-calibration, where the previous solutions
are applied in subsequent rounds of self-cal. This can be modified in two
separate ways, described in more detail by Brogan et al. 2018.

If, after one or a few rounds of self-calibration, you get an image and model
which are much better than the starting model (e.g. the initial model included
CC which turned out to be artefacts), you can remove the previous self-
calibration and model (tasks clearcal, delmod) and start phase self-
calibration afresh with the better model without applying previous solution
tables. A similar strategy is used in the NRAO template imaging script, see
Appendix B.5. If the model you want to use exists, but did not result from the
immediately previous tclean, see the tclean documentation or Sec. 4.3.2 for
how to insert it in the MS. If the S/N permits, in this case you could start
with a solution interval shorter than a scan. In each applycal, be sure to
apply any solution tables you applied in gaincal plus the new table. It helps
to make your own flow chart.

Alternatively, instead of updating the model and calibration in the same MS at
each stage (as in Fig. 5), you can split out the calibrated (corrected column)
target data after each applycal step. The data column of the new MS contains
the previous corrections. Use that for the next round of imaging and gaincal.
This means that you are only ever applying the table just generated in
applycal. Some users find this simpler, although it generates a greater data
volume and can be more complicated if you are transferring solutions between
parts of a data set.

###  4.9 When to stop self-calibrating

The three rounds of self-calibration (Fig. 5) are typical but for low S/N you
may only be able to do the first phase-only round. Conversely, additional
rounds may be needed to improve a model of a complex target, or if high
dynamic range is needed you may be able to go to successively shorter solution
intervals as the model improves. In some cases you may find that the image
structure becomes clearer after amplitude self-calibration, and so you can use
the better model to improve phase calibration., see note at the end of the
list in Sec. 4.1 and Sec. 4.8.

In all self-calibration, there should be some change in each cycle, either in
the solution parameters or the model, or flagging of the data, and the image
S/N should improve whilst the rms does not increase (except in the case of a
deliberate re-scale). When this is no longer the case stop self-calibrating.
The noise level should be estimated taking into account the spectral ranges
actually used and the duration and number of antennas after any flagging, and
the PWV during observations; see Appendix B.2, CASA Guides, Analysis Utilities
for scripts to estimate the amount of useful data, and the web log, QA2 report
or SNOOPi for the WVR measurements.

The obvious time to stop is if you reach the predicted noise level and
inspection of the visibilities suggests that the solution interval already
used is sufficient to remove all but random noise errors, or an additional
round of calibration produces no further improvement (Figs 10(i) and 11(j) or
(k), DV07).

If the noise remains more than a few tens percent higher than expected, Sec. 5
suggests some other approaches which may be applicable. Be careful not to
reduce the solution interval to shorter than the timescale of systematic
errors (or a single integration); if the solutions are dominated by random
scatter you are probably just moving noise around which is not useful. The
shorter the solution interval the more tightly the data are constrained so the
model must be very accurate. If the image peak increases significantly, check
that the rms has not also increased and that real, extended flux has not been
reduced by being forced to conform to an incorrect model. Use of a bad model
or too short a solution interval can also make negative or positive artefacts
worse near the target even if the noise off-source falls. If you are using the
continuum for self-calibration, image a line channel to check that it has also
improved (or v.v.).

Several situations limit the efficacy of self-calibration. See Sec. 6 for how
to recognise confusion, missing spacings and issues which require special
treatment and/or cannot be cured by self-calibration. Previous calibration may
not have been optimum e.g. a weak bandpass calibrator or too-distant phase
calibrator, when the target S/N does not allow short enough solution intervals
to compensate completely. Self-calibration cannot correct fully for antenna
position errors and tracking errors, Sec. 6.6.1, especially for sources far
from the pointing centre. You may reach a dynamic range limit, see Sec. 3.3;
for ALMA it can be difficult to get dynamic ranges better than a thousand, but
S/N $>5000$ has been achieved (e.g. Fenech et al. 2018). At high dynamic
range, especially for lower-frequency arrays, baseline-dependent errors which
cannot be factorised per-antenna may emerge, see Sec. 5.13.

##  5 Special Circumstances

In this section we cover a number of situations more complex than well-behaved
continuum self-calibration where additional procedures are needed.

###  5.1 Transferring solutions between spectral windows/across frequency
differences

Observations may be made in a spectral configuration where all or some spw are
very narrow or fall in very noisy parts of the atmosphere (transmission can be
plotted in plotms) which nonetheless contain bright lines (e.g. a 100 Jy maser
in a region of 50% transmission) exclude all the affected channels during
continuum self-calibration as if they were a spectral line or transfer
solutions from another spw. In such cases, check in case prior calibration has
flagged the narrow (or noisy) spw. The phase calibrator may not provide enough
S/N; the ALMA pipeline usually recognises this situation and averages in time
or across spw as required, or the phase calibrator may have been observed in
wider spw. However, if this has not been done (e.g. early cycle data) many
solutions may fail for narrow spw, and thus flag the target. In such a case
the phase calibrator corrections (or those for any other calibration source
with many failed solutions) should be re-derived with more averaging (and a
lower minsnr if necessary). This can also be the case during self-calibration.
The principle is the same in both cases.

One method is similar to that used by the pipeline and standard QA2 scripts
for the phase calibration source in narrow spw, which seeks to increase the
phase calibrator’s S/N per solution interval by using a longer solution
interval (e.g. ’inf’ instead of ’int’) and/or averaging all spw. Such
averaging (e.g. all continuum channels) can also be used for self-calibration,
as summarised in Sec. 5.10.2.

In this section we outline an alternative method in the case that you have
some spw wide enough to self-calibrate individually, the solutions are usually
less noisy if very narrow spw are left out and the wide spw solutions are
applied to all. Similarly, if a line provides the best S/N for self-
calibration, its solutions can be applied to all channels.

Normally, after applying all corrections including the phase calibrator
solutions to the target, there should be no remaining offsets between the
continuum phases for different spws in an EB. The correction for spw offsets
also removes instrumental offsets between polarisations (but not the effects
of source polarisation or parallactic angle rotation). Check that this is the
case by plotting phase v. time for each spw – you may have to average per
scan, even all baselines, for narrow spw. If the phase calibrator was observed
in the same configuration it may be easier to examine its calibrated
visibilities. For each correlation there should be no systematic offset
between spw (as in the top row of Fig 12); if there is, see Sec. 5.1.2 for use
of a ‘diff gain cal’.

Assuming you are using continuum and have identified line-free channels, and
have a measurement of the continuum peak, you can calculate the continuum
bandwidth for each spw and thus what the S/N would be. You may already have
per-spw continuum images from the pipeline, or make images. Otherwise, if you
have an image made from all spw, aggregate bandwidth $\Delta\nu$, the noise
per spectral window with line free channels summing to
$\delta\nu_{\mathrm{spw}}$ is proportional to
$\sqrt{\Delta\nu/\delta\nu_{\mathrm{rms}}}$ so you can estimate whether you
can use any individual spw for self-calibration or, perhaps, combine two in
the same baseband. You may need trial and error to decide whether combining
more spw gives more good solutions (Sec. 4.6) and a better image due to better
S/N per solution, or whether it makes things worse because the errors are
different in different spw.

Using the chosen spw or combination, make a model image. In ft (if used) and
in gaincal set spw to spw/channel selection used for the model. By default,
gaincal and applycal apply the gaintable solutions for a given spw only to
that spw and flag spw with no solutions. In order to apply solutions across
boundaries, you have to use the spwmap parameter (see Appendices C.1 and C.2).
In this example, the wide-band spw is number [18] and the narrow spw are [20,
22, 24, 26, 28, 30, 32]. spw 1–17 are present in the data (e.g. as listed by
listobs and although they are not being used for the target they must be given
in the spwmap list. A ‘diff gain cal’ table ’DGC.p’ is being used and you have
derived a wide-band correction table ’spw18.p0’. You need one spwmap list per
table (an empty list applies each set of corrections to the spw it was derived
from), giving:
gaintable=[’DGC.p’, ’spw18.p0’]
spwmap=[[],[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,18,18,
18,18,18,18,18,18,18,18,18,,18,18,18,18]]
to apply spw18.p to spw 18 and all higher-number spw.
If you want to average all spw, the resulting gaintable will be labelled for
the lowest-number spw in the average, so, here, if you averaged all science
spw between 18 and 32 in gaincal, you would use the same spwmap as above in
applycal (and in the next round of gaincal, if you were applying these tables
when deriving a new one).

Tropospheric refraction is proportional to frequency (Eq. 4), so a phase
correction of $45^{\circ}$ at 220 GHz is $45\times 270/220\sim 55^{\circ}$ at
270 GHz. If you are transferring solutions across a large frequency interval,
gain tables are scaled appropriately in applycal by using the interpolation
suffixes ’PD’, e.g., for two gaintables, applycal
interp=[’linearPD’,’linearPD’] – note also that in such cases you are usually
extrapolating not interpolating. Within a single EB this is less serious; the
maximum scaling required, in Band 3, is 16%, but is worth using across a
larger interval e.g. using a line for self-calibration in a spectral scan. For
band-to-band phase referencing, see Asaki et al. (2020b, a).

Figure 12: Exaggerated example of correcting for offsets between spectral
windows and correlations. Top left: DGC (bandpass calibrator) raw phases
CM10&CM11 baseline, XX (purple) and YY (orange) correlations, for wide spw 18
(87.65–89.45 GHz) and narrow spw 32 (around 89.2 GHz). Top right: the same spw
raw phases for the target as a function of time; the narrow spw is noisier.
Bottom left: time-averaged phase solutions for the DGC for CM10 and CM11,
polarisations X and Y. Bottom right, the target self-calibration phase
solutions for spw 18 (showing both polarisations now aligned) after applying
the DGC solutions during gaincal.

####  5.1.1 Transferring solutions between MS

It can be necessary to transfer solutions between separate visibility data
sets. For example, if self-calibrating using a spectral line, it may be
quicker to split out the line channel(s) into a separate, small MS for self-
calibration. When you have achieved the best set of gain tables, these can be
applied together to the full data set. However, you might want to apply the
tables after each round of calibration to the full as well as to the line MS,
and make a test image of another line or the continuum to ensure that the
solutions are suitable for all data.

If you split out a line for self-calibration from spw 2 (for instance), using
mstransform reindex=False then the MS spw used to derive the self-calibration
gain table will be numbered 2\. If there are 4 spw to be corrected in the MS
you are applying it to, in applycal specify spwmap=[2,2,2,2] (see also example
in Sec. 5.1).

####  5.1.2 Use of Diff Gain Cal

If one or more spw are very narrow, all spw may have been averaged for the
phase calibrator, or it may have been observed in a different, full-bandwidth
configuration. Before solution transfer between spw, or spw averaging, the
instrumental phase offsets between spw must be removed by applying corrections
from a source used as a ‘diff gain cal’, DGC. This is usually the bandpass
calibrator but can be any continuum source where good phase solutions can be
derived per spw by averaging over a long time period (usually all data).

In this example, the phase calibrator wide-band spw are [18, 20, 22, 24] and
the narrow target spw are [26, 28, 30, 32], the bandpass calibrator being
observed in both sets of spw. Figure 12 top right shows the phase offsets
between the wide- and narrow-band (noisier) raw phases for a single baseline.
The bottom right (DGC.p) shows a single, averaged solution per spw per
correlation per antenna, representing the spw and polarisation offsets. The
solutions in DGC.p are _not_ designed to correct phases in the manner of
imaging corrections, but, when applied to any other data in the same EB, they
allow the next set of phase corrections to be derived such that they can be
applied regardless of spw or polarisation offset as long as the DGC solutions
are again applied. Thus, the bottom right panel shows that the target
solutions for spw 18 (spw18.p0), derived whilst applying the DGC solutions,
have the polarisations aligned and are symmetric about zero and in fact can be
applied to spw 32.

You may be able to use the target as its own DGC, see Sec. 5.10.2.

###  5.2 Spectral line self-calibration

####  5.2.1 Aligning data in rest frame of target

Before aligning in frequency check that each separate data set has used the
correct position for the target, allowing for proper motions. The imaged
target peak should be at the same angular separation (or exactly at) from the
pointing centre in each case. In case of alignment problems see Sec. 5.11 for
this and other issues when combining executions.

For each execution of an ALMA EB, the requested spw centre frequency is
adjusted for the $V_{\mathrm{LSR}}$ of the target but then held fixed for the
duration of the observations (except for ephemeris objects, for which see Sec.
5.12). The rotation and bulk motions of the Earth amount to about 1–2 km s-1
per day so the shift during an execution is $<0.1$ km s-1 but is more for
multiple executions and can be tens km s-1 for observations months apart, or
if required by observational tuning (which is limited in precision to $\sim$20
MHz). For simple imaging, tclean will adjust to a chosen reference frame
correctly but for self-calibration the data must usually be combined into a
single MS adjusted to a constant $V_{\mathrm{LSR}}$, i.e. a constant frequency
in the target frame. For a single execution or for very broad channels this
may not be necessary but as you usually would split out the target anyway this
can be done in the process.

Use the listobs output to compare the frequency ranges and channel widths for
each spw in multiple executions. Work out, for each spectral window, the
overlapping frequency range and note the largest channel width in frequency,
and split each spw out separately using the appropriate values in mstransform,
regridms=True, to ensure aligned frequencies and a uniform frequency width. If
you only have one execution but channels $<0.1$ km s-1 then it is also best to
regrid the data. Then, concatenate the regridded MS with a small frequency
tolerance (about 1 channel). You can also use a position tolerance for targets
with proper motion, to align the combined data by pointing position (assuming
this is correct, see above) rather than absolute position. If each of e.g. 3
input MS had e.g. 4 spw and the same, single target, then the single output MS
should also have 4 spw with frequency coverage similar but probably not
identical to the original and one target field. If the concatenated data set
has $>$4 spw (or more than the expected number of spw) then the regridding did
not use the correct frequency ranges/widths and/or the frequency tolerance is
too small. If the target is listed more than once, you probably need a larger
position tolerance in concat.

####  5.2.2 Line self-calibration and the presence of continuum emission

If you have made a concatenated data set, use this from now on, after applying
continuum self-calibration if relevant (see below).

ALMA targets usually exhibit both line and continuum and if the S/N per spw is
high enough (see Sec. 4.4.2 including Eq. 25), it is best to self-calibrate
the continuum first. Measure the S/N for the line-free continuum – you can use
the pipeline/QA2 image if you are sure it is line-free, or make an image from
the data combined as above – note that the numbering of line-free channels may
have changed. Making a channel-averaged copy of the data with averaging will
speed up continuum self-calibration, but see precautions in Sec. 4.3.

If at all possible do amplitude self-calibration to make sure that the
spectral slope is consistent across all spw, see Secs.4.3 to 4.5.1. Apply the
calibration to the whole target data set.

For self-calibration using a line, choose the line with the brightest compact
peak, which may not be the brightest spectral peak on all baselines. Fig. 13
shows that the line around channel 520 is most suitable (left-hand image), and
in fact lines with a ‘triangular’ profile usually provide the most compact
emission. You can also plot a $uv$ range confined to the longer baselines to
identify compact lines. If possible, self-calibrate using a single channel or
a few channels, taking care not to include weaker emission from the line wings
which will reduce the averaged S/N. If the line emission is resolved and the
structure changes from channel to channel, or becomes more extended away from
the peak, then channel averaging should be minimised.

Figure 13: Example spectral lines with images of peak channels (on same
intensity and angular scales); the left-hand image peak of channels around 515
is three times brighter than the peak _c_ ompact emission in the more extended
line, despite the higher spectral peak, around channel 290, of the latter.

Whether to subtract the continuum before or after line self-calibration
depends on which route will enable the most accurate model to be developed.
Estimate the S/N for the channel(s) to be used for self-calibration for the
chosen line. If the line is much brighter than the continuum you can estimate
the rms in the combined channel width to get a rough estimate, or make an
image of the chosen channels. If the rms in the combined channels is such that
the continuum would be $\lessapprox$3$\sigma_{\mathrm{rms}}$ in those
channels, or the line and continuum have very similar structure but the line
has much higher S/N, self-calibrate on the line before subtracting the
continuum (as this will be more accurate for better-calibrated data). In other
cases, subtract the continuum before line self-calibration. However, if the
continuum is bright enough to be seen in the channel(s) used for line self-
calibration, but has weak, hard-to-image extended emission, then you can self-
calibrate using the data set after continuum subtraction but apply the
corrections to the original unsubtracted data (see Sec. 5.1.1) and then re-
subtract before making the final images.

Line self-calibration then follows the same principles as for continuum (Secs.
4.3 to 4.5). Make sure that you use the same channel selection in imaging and
in calibration as you used in making the model, but use the spwmap parameter
in applycal to apply the solutions to all spw (Sec. 5.1). If you have
previously used continuum self-calibration then the flux scale and positions
of all spw should be consistent, but otherwise, in order to transfer
corrections from a line in one spw to all spw, see also Sec. 5.1.2 to check
that there are not phase offsets and, if the frequency difference is more than
10–20% (depending on the probable accuracy of phase corrections), see the last
paragraph of Sec. 5.1 for scaling phase corrections by frequency.

###  5.3 Extending self-calibration from a time selection to all target data

Sometimes, phase-referencing is less successful for part of an EB, for example
if the phase calibrator is at a lower Declination than the target and suffers
low elevation effects for the last scan(s), or if an execution is terminated
early and the last scan is on the target. In such cases, an image made from
all the target data including scans without good phase referencing is likely
to have serious artefacts. Fig. 14 left (data from Decin et al. 2015) shows
that the last phase calibrator scan is missing and the previous scans are
progressively noisier as the observation progresses. The amplitude for the
last two target scans is also poorly calibrated. Fig. 14 in the top left of
the right-hand panel, shows that making an image, after applying the phase
calibrator corrections only, showed more than one apparent source of similar
brightness. Imaging just the first two scans gave a noisier image but the star
could be identified clearly. In a case like this:

  * •

Make an image model from the good target data, making sure that it is saved in
the MS.

  * •

Perform and apply phase self-calibration for the good scans (iteratively if
necessary).

  * •

Re-image the good scans naking sure that the model is saved in the MS and
perform amplitude self-calibration as usual for the good scans.

  * •

Applying this calibration and re-imaging the good scans now provides a model
M0 for starting to self-calibrate _all_ the data.

  * •

_Don’t use the previous gain tables_ ; phase self-calibrate all scans with the
shortest solution interval which was suitable for the first two scans
(although if that fails many solutions, try longer), table p0all.

  * •

Don’t use applycal yet, but apply p0all in gaincal for amplitude self-
calibration of all scans, still using model M0, table a0all.

  * •

Image all scans and if necessary use this as a model to continue self-
calibrating all data; however, at every gaincal and applycal, apply tables
p0all and a0all as this will ensure that all the scans have reasonable
starting calibration.

This uses the first two scans to provide a model to self-calibrate all the
data; the thing to remember is not to image all scans until you have applied
both phase and amplitude solutions to all scans. The first set of solutions
for all data will look quite different for the different scans.

Figure 14: Left: phase calibrator and target scans for CW Leo (ALMA Band 9,
continuum), one baseline, after applying phase calibrator solutions. The phase
calibrator was at a higher declination than the target and is seen at low
elevation in the last scans. Right: Images of CW Leo during self-calibration.

A similar strategy was used in self-calibrating a maser peak in the VY CMa
data, Fig. 15, but in this case although phase-referencing worked properly,
there was an additional error (of unknown origin) affecting target phases for
one antenna. The amplitudes after applying the phase calibrator solutions were
as expected, showing slight resolution (top row). However, one antenna, DA50,
showed an anomalously high phase rate (bottom row). In this case, DA50 was
excluded from imaging and calibration (antenna=’!DA50’) in the initial phase-
only self-calibration (table p0) using solint=’inf’, which would have averaged
over the $360^{\circ}$ wrap. DA50 was then included for phase calibration
using a solution interval of 36 sec, and, applying all phase solutions, for
amplitude self-calibration. If the model has the right amplitude scale and you
want to correct mis-scaled data, in gaincal use solnorm=False so the solutions
for the good antennas (or spw etc.) should come out close to 1, but the
problem antenna (or etc.) will have the required solutions, as in Fig. 11 (n).

Figure 15: Top, left and right: VY CMa amplitudes for a spectral peak after
applying phase calibrator solutions, all reasonably consistent and indicating
slight resolution. Bottom left: VY CMa phases for this peak after applying
phase calibrator solutions. This are mostly fairly flat (offset as the peak is
not at the phase centre) but the last 3 full scans show a steep phase slope
for one baseline. Bottom right: This is due to DA50, contrasted with a better-
behaved antenna.

Transferring solutions between spw assumes that the corrections obey Eq. 4,
i.e. the atmosphere is non-dispersive and the phase errors scale linearly with
frequency (negligible within a single ALMA tuning). However, some water masers
e.g. 325 GHz, are bright enough to self-calibrate but the data are affected by
a deep telluric water line which may produce non-linear effects. Transferring
solutions to other parts of the observed spectrum e.g. the line-free continuum
may leave higher than expected residuals and astrometric errors. If the
continuum or any other line is bright enough to self-calibrate, you could
derive and apply its solutions first, and then self-calibrate the maser. This
will almost certainly improve the maser channels but compare before and after
applying its solutions to other channels to see which gives the best S/N and
test for position shifts (which will also give an idea of any additional
astrometric uncertainty for the maser).

###  5.4 Resolved phase calibrator

Self-calibration with the default point or an external model can also be used
to build up a model for the phase reference source if it is unexpectedly
resolved, similar to the procedure for a target, Sec. 5.5.1. If using QA2
scripts, make sure that the best model is inserted into the MS, either from
your final tclean or with ft if you are using an external model (see Sec.
4.3.2), before running the stages calibrating the phase reference. If there is
a delmod in that part of the script, remove it. If you have no external model,
normalise the amplitude solutions while developing a model. The simplest ways
to set the target and phase calibrator flux densities is to use the bandpass
calibrator or $T_{\mathrm{sys}}$ as outlined in Sec. 5.5. Or, measure the
apparent total flux density of the phase calibrator from an image made after
applying corrections derived for all baselines using normalised amplitude
solutions, which will be in correlator units. Make an alternative amplitude
solution table in the usual QA2 fashion but in the gaincal leading to
fluxscale restrict the baseline lengths to those where the phase calibrator is
unresolved in order to derive the total phase calibrator flux density. Then,
derive a scaling table to apply alongside the normalised all-baseline
amplitude calibration table (and the phase corrections) to the target and
phase-reference, see Appendix D.2.

This is not usually necessary for ephemeris objects used for phase
referencing, as the ephemerides used in CASA provide models, see Sec. 5.12.

###  5.5 Observations without phase referencing or problem phase calibrators

Some very early ALMA data, and observations from other arrays, are observed
without phase referencing, or the phase reference source may be so weak it
does more harm than good, so self-calibration is worth trying. VLBI data are
often not phase-referenced and the application of prior calibration will
differ from the description below but the actual self-calibration principles
are the same. See the CASA VLBI School (linked in Appendix B.1) for more
details such as the calibration of delay and rate. The use of ALMA in VLBI
requires pre-calibration of the phased array data and special attention to
polarisation, see ALMA-TH and Goddi et al. (2019).

Occasionally, a phase (or other) calibrator is bright enough but the model is
not correct – typically, a calibrator is assumed to be a point source but is
actually resolved (see Sec. 5.4), or there are other sources in its field.
This leads to an overestimate of amplitude corrections for longer baselines so
a target plot of corrected amplitude against $uv$ distance has an unphysical
positive gradient, and also to phase errors, an increase in noise and
degredation of astrometry. Very weak extensions (below the required dynamic
range) may not matter, but in other cases the resolved calibrator should be
self-calibrated itself, starting as described below for a target, until a good
image model is obtained. This model can then be provided in the QA2 script or
pipeline and the stages from the first use of the calibrator in question
should be repeated (taking care that no subsequent steps remove the good
model). If this is successful you can then process the target as normal.

If the you tried applying phase calibrator solutions to the target
unsuccessfully use clearcal before recalibration/self-calibration; you may
also have to restore any data flagged by bad solutions.

If the phase calibrator is unusable, you need alternative techniques for both
the functions of phase-referencing, i.e. setting the flux scale (for
correlator output units to Jy) as well as time-dependent calibration. Make
sure that the bandpass and earlier calibration are as good as possible. If you
have separate flux scale and bandpass calibrators, fluxscale produces a gain
table with the bandpass calibrator amplitude corrections scaled. If the
solutions for the bandpass calibrator are pretty smooth and consistent,
including the solution closest in time to the target, apply that table using
interp=’nearest’.

If the solutions show more than a few percent scatter, or if you have an
a-priori value for the flux density of the bandpass calibrator (or whatever
you are using as flux scale calibrator for the target) you can, first, use
setjy to set its flux density. Derive time-dependent phase and then normalised
amplitude corrections for this calibrator. Apply these to the calibrator and
derive another amplitude solution table without normalisation with a long
time-averaging interval; this table can be applied to the target also. The
amplitude scaling factor should be the same for all sources unless they
contribute a significant fraction of $T_{\mathrm{sys}}$, in which case see
Appendix D.3. Don’t apply phase solutions from other sources to the target if
you don’t have phase referencing as these are direction- and time-dependent.

Alternatively, in the absence of any astrophysical flux scale calibrator, you
can use $T_{\mathrm{sys}}$ to scale the data from correlator counts to Jy, see
Appendix D.2.

Estimate S/N from the observing parameters and whatever prior information you
have about the target. If the S/N is so low that you need to average all spw
and polarisations, see Sec. 5.1.2 for using a bright calibrator to remove the
offsets. It is best to apply the fluxscale (and DGC, if needed) tables along
with the bandpass and other prior calibration, and split out the target; we
assume that, however you do it, these tables are all applied.

####  5.5.1 First round of self-calibration without phase referencing

You will have to do one round of phase self-calibration _before_ imaging the
target. See Appendices C.1 and C.2 as well as the online help for more
explanation of parameters mentioned here.

If a model is not specified in gaincal, the default is a 1 Jy point source at
the phase centre. If you expect the target to be dominated by a point source
this is adequate for the first round of phase-only self-calibration. If you
have access to a separate observation of the same target at a similar
resolution (even e.g. a more compact array but a higher frequency), and can
image this to produce a model, this can be used as long as the structure is
similar to what you expect. You may need to modify the model header to
persuade ft to insert it correctly. An image in units of Jy per pixel can be
used. The CC table attached to an AIPS image (exported from AIPS as FITS) can
be converted to a CASA image, see Appendix D.5.

Be very cautious in the first gaincal, phase only (so the model amplitude does
not matter), possibly reduce minsnr to avoid failing solutions. For arrays
with few antennas, you might also need to reduce minblperant. Use applycal
applymode=’calonly’ as failed solutions may be due to an inadequate model (not
bad data). Each self-calibration product (tables, images, MS corrected column)
should be inspected carefully (Sec. 4.6), especially in the early stages. As
well as checking the S/N, make sure that you are not freezing artefacts into
the data or forcing extended emission into a central point.

If many solutions fail or look like noise, or the subsequent image is very
noisy or distorted, it may help to restrict the $uv$ range in the first round
of calibration. For example, if you think that the target is a few synthesised
beams in area with an unknown distribution of peaks, you could restrict the
range to less than about half the longest baseline length (so, effectively,
the point model will be larger, and complex substructure is below the
resolution limit, so the model represents the data better). If all antennas
have at least some baselines in this range the resulting gain table will
correct all antennas and you can then make an image with all data as usual. If
some antennas do not have good solutions after the first round, increase the
$uv$ range slightly (enough to include at least one more antenna) in imaging
and use a similar value in the subsequent gaincal, continuing phase self-
calibration with small increases, until all the data are included.

If you are using a spectral line, check the effect of the calibration on the
continuum or a different line (at the end, or after each applycal if not too
time-consuming). Conversely, if you are using compact continuum but you expect
an extended line, image a line channel after applying the calibration to check
it is as expected.

####  5.5.2 Developing the image and model structure

Starting with a point model and building up the actual target structure, as in
Sec. 5.5.1, usually works very well if done cautiously. There is a particular
hazard if your target is a point double and a point source is used as the
model for amplitude self calibration. This can produce an apparently triple
source – ‘spurious symmetrization’. If you see such a structure, and you are
expecting a double not a triple, you may want to try re-imaging just masking
two components to provide an image model of a double. For this, or any,
structure, if your best model is very different from the starting model, you
might want to go back to the beginning and insert the best model (so far)
before the first phase-only self-calibration (as in Sec. 4.8). If necessary
re-apply just the pre-self-calibration gaintables and use delmod and restore
any flagging due to failed solutions. No or fewer $uv$ restrictions and fewer
rounds of calibration would be needed the second time round.

####  5.5.3 Implications of no phase-referencing

The target position is fixed at the position of the first model so you cannot
use self-calibration without phase referencing to improve astrometry. If you
need to adjust the position to match that of other observations, it is easiest
to use puthhead on the final image, but you can also change the visibility
data position (Appendix D.1). See Sec. 3.5.3 for estimating the target
position using ‘reverse phase referencing’ if you do have a detectable phase
calibrator (or check source) but it is too faint to use for normal phase
referencing.

###  5.6 Primary beam correction, heterogeneous arrays and smearing

The model used in self-calibration should represent the sky brightness
distribution detected by the array, including field of view limitations. Thus,
as noted in Sec. 4.3.1, you should not apply a PB correction until after self-
calibration even if there are sources affected by this. Similarly, if sources
in the field are affected by bandwidth- or time-smearing, they can still be
included in the self-calibration model (although self-calibration cannot
remove the smearing); links on this issue are given at the start of Sec. 6.

Occasionally (mostly test data) ALMA 12-m and 7-m data are correlated. Other
arrays, such as e-MERLIN, the EVN and other VLBI, customarily use different-
diameter antennas. The different PB corrections mean that sources outside the
inner parts (1/3 or less) of the PB will be affected differently. This should
not affect position, so phase self-calibration is unaffected, but amplitudes
are. If there is a bright source affected differently by PB corrections, and
you need to try amplitude self-calibration, one strategy is to image it using
the smaller antennas of similar size, to get the least inaccurate model, and
use this to self-calibrate all data. The gains for the larger antennas can
then be scaled by the ratio of their PB correction to that of the smaller
antennas, at the source position.

###  5.7 Mosaics

It is usually best to chose a single field, containing the most suitable
source for self-calibration. Since each pointing is observed separately, any
pointing with weak or no signal will have very low S/N and solutions probably
will fail. Within a single set of pointings, if there are two or more bright
sources such that each is also detectable within the field of view of the
other, use both (or more) such pointings for imaging and calibration, in order
to ensure that confusion is mapped out. The solutions for the best source(s)
can then be applied to all pointings, on a principle similar to phase-
referencing.

Usually, ALMA observes all pointings over a short enough time interval that
the inaccuracies due to a small time offset are small. However, for very large
mosaics, if only a subset of pointings is observed between each pair of phase-
reference scans, you may need to handle each subset separately.

Use the listobs output to identify the scan numbers or source names and
specify these in imaging to make the model, and in gaincal. In applycal, apply
the solutions to all target scans. If there are more than one subset of target
scans with separate calibrator fields use field and gainfield.

###  5.8 Wide-field (anisoplanatic) calibration

In the case of arrays with a wide field of view, such as at low frequencies
(below a few GHz), or arrays using antennas with apertures which are small
with respect to the maximum baseline, $B_{\mathrm{max}}$ at a given
wavelength, the corrections derived in one direction may not be appropriate
for the whole field of view (hence the distinction in the first row of Eq. 2).
This occurs when $B_{\mathrm{max}}\lambda\gtrapprox A_{\mathrm{eff}}^{2}$,
where $A_{\mathrm{eff}}$ is the antenna diameter (Cornwell et al. 2005).

This is not a problem for ALMA but affects metre-wave, wide-field
(anisoplanatic) arrays, where there are usually multiple, detectable sources
throughout the field of view, for example see Appendix B.1 for the LOFAR
cookbook. This can also be an issue for e.g. the VLA and e-MERLIN at
$\lessapprox 2$ GHz. It is often compounded by a large fractional bandwidth,
requiring simultaneous inclusion of multi-frequency terms (Sec. 4.5.1). Wide-
field, wide-band imaging is available in CASA tclean but is also often
achieved using WSClean (Offringa et al. 2014, Offringa & Smirnov 2017). The
technique of deriving solutions for one source in the field, subtracting it
and moving on to the next, is known as peeling, as implemented e.g. in DDFacet
(Tasse et al. 2018). These packages are available on github. Recent overviews
of facet-based techniques are given in van Weeren et al. (2016) and Tasse et
al. (2021).

A similar approach is needed to mitigate the effects of antenna pointing
errors (Sec. 6.7) across wide fields, if there are multiple bright sources
extending outside the inner $\sim$third of the PB, described for the VLA by
Bhatnagar & Cornwell (2017).

###  5.9 Polarisation

ALMA observes in linear polarisation (X and Y) and, usually, only the total
intensity (Stokes I) will be bright enough to self-calibrate, and the location
of the different hands of polarisation, i.e. the phase, should be the same.
Thus, phase-reference and polarisation calibration is used to correct any
instrumental or other $X$-$Y$ offset errors prior to self-calibration. For
amplitude self-calibration, make a total intensity image and use gaincal
gaintype=’T’ to derive average solutions for X and Y, thus ensuring that
differences between the two hands are preserved. When the corrections are
applied, all the correlations will be scaled proportionally per solution
interval. For polarisation calibration of ALMA-VLBI data, see Goddi et al.
(2019).

In the case of arrays with circularly polarised feeds and targets with strong
Zeeman splitting, such as OH masers, the peak in one hand, e.g. LL, may be
offset by many channels from the RR peak, with negligible RR emission in the
LL channels and visa versa. In such a situation it is necessary to derive
solutions from the brightest single hand peak channel and apply these to all
data. This relies on prior calibration (phase-referencing, parallactic angle,
and polarisation leakage where possible) to have removed any instrumental L-R
offset. If this has not been possible, a procedure similar to that used to
correct for wide-narrow band offsets can be used as in Sec. 5.1.2.

###  5.10 Low S/N and calibration problems

If the first image is much noisier than expected, check first that there are
not phase referencing problems and that all prior calibration has been applied
correctly to the target. You could also inspect images of a check source, if
present, or the phase calibrator; if the latter is resolved see Sec. 5.4. If
the problems only affect a particular spectral window, antenna or time
segment, see Secs. 5.1 – 5.3. If the phase calibrator is entirely too weak or
absent see Sec. 5.5 and Sec. 6.6 also for general prior calibration problems.
See Sec. 4.6 for diagnostics if you have tried self-calibration but many
solutions fail and also check the target visibilities in case there are bad
data.

This Section covers intrinsically faint targets such as where the S/N of the
first target image is so low that the minimum solution interval $\delta t$
from Eq. 24 is longer than a scan, or you try the usual recipe of solving for
phase per scan, per polarisation, per spw but lots of solutions fail. There
are several potential strategies to allow calibration solutions to be derived
with a high enough S/N to be worthwhile, for targets which are borderline
bright enough – see Sec. 4.2 and inspect the target visibilities with
different averaging intervals to see whether self-calibration is likely to
succeed.

####  5.10.1 Calibration parameters to make the best of low S/N data

Appendices C.1 and C.2 outline the use of the parameters which can be changed
from default ALMA values for low S/N calibration. In summary, gaincal minsnr
can be less than 3 (especially if previous application of phase calibrator
solutions means that all data have had some corrections already). If at first
the model is likely to be only an approximate representation of the target,
use applycal calwt=False, applymode=’calonly’ to avoid downweighting or
flagging data in early cycles of self-calibration. More averaging and
alternatives are discussed in the next two Sections.

####  5.10.2 More averaging

If Sec. 4.2 and Eqs. 24 and 25 suggest that the S/N is too low for self-
calibration solutions per spw, per scan, per polarisation, try averaging in
frequency or time in plotms to find the intervals which allow you to see some
structure in the visibilities. For example, averaging both polarisations and 4
spw with similar continuum bandwidths could reduce $\sigma_{\mathrm{rms}}$ by
$\sqrt{8}$, so S/N 20 without averaging becomes S/N 56. Initial averaging over
scans etc. may also be needed even if the optimum solution interval should be
a scan or less but many solutions fail or the image after self-calibration is
noisier than you expect. Examine any solutions you have derived (Sec. 4.6) to
help diagnose issues.

See Appendix C.1 for averaging using parameters gaintype and combine).
Averaging for calibration will only work if the errors (on scales larger than
thermal noise) are similar across the combination interval. For example in
Fig. 12 top right, the phase slope is similar for both spw and both
polarisations plotted and so the polarisations could be combined per spw, if
the constant offset between X and Y was removed. In most ‘real’ cases the
offset (for a phase-referenced target) will be much less. Similarly, the spw
could be combined; see Sec. 5.1.1 for use of spwmap to allow a single set of
solutions to be applied to multiple spw.

Be careful not to average over a such a long time period that the phase
changes by more than you are trying to correct for; see Fig. 10 (f), (g) and
Fig. 12 lower right, where antenna CM10 has a phase slope of $\sim$50∘ in 12
min. Averaging over this interval would leave a residual error of up to
$\sim$25∘; this sort of solution accuracy will probably provide improvements
in imaging but averaging over the whole time shown with $>$300∘ change would
not work (see Eq. 3).

In reality, in a low S/N data set it is hard to distinguish errors from the
intrinsically complicated phase structure of a resolved source. You may be
able to get a better idea of the error phase rate by looking at the phase
calibrator visibilities (before applying its time-dependent phase and
amplitude corrections) since offsets between polarisations and spw are
instrumental and usually constant within an EB. However, you may have to
experiment and find what combinations (if any) produce genuine improvements
from how many solutions pass, whether they look reasonable (Sec 4.6) and
whether the image improves. Assuming that you do get a better model, you may
be able to average over shorter intervals in successive calibration rounds.

See Sec. 5.1.2 for how to check that the spw/polarisations are aligned and
apply averaged corrections. Usually the bandpass calibrator is used to derive
corrections for offsets between spw or polarizations. However, you can also
use the target itself as a ‘diff gain cal’. Before the first self-calibration
round, set solint to a long time interval (or all times) of the best target
data and average in time (gaincal combine=’scan’) but not the spw nor
polarisations. As long as this gives good solutions for all antennas, spw,
polarisations, applying this table as a DGC table (in all gaincal and applycal
allows you to average spw and polarisations for subsequent rounds. _Don’t_
apply the DGC by itself to make an image model; stick with the first model
until you have per-scan solutions as well.

If, even with averaging spw and polarisations (in Eq. 24,
$\delta\nu=\Delta\nu;N_{\mathrm{pol}}=2$), $\delta t$ is greater than a scan
length, there is usually no point in averaging multiple scans for phase
solutions, since this is unlikely to improve on phase calibrator corrections,
but it may help if there are antenna position errors or to remove phase
offsets. On the other hand, long-time averaging is often useful for if one or
more antennas are systematically miscaled as in Fig. 11(n); if spw or
polarizations are affected differently, keep them separate. In this case
amplitude self-calibration may be worth-while even without phase self-
calibration.

####  5.10.3 Solving for phase or rate by gradient or spline fitting

Figure 15, bottom right, shows a steep phase error slope for DA50. If the S/N
is too low to use a short enough solution interval to sample the rate of
change of phase adequately (unlike in Sec. 5.3), one can alternatively fit to
the phase gradient, where this is stable over a scan (or more), so a longer
solution interval can be used.

The task fringefit is designed for VLBI calibration. It performs a fit to the
first derivative of phase as a function of time, known as as ‘rate’ (sometimes
referred to as ‘delay-rate’). This can be done simultaneously with fitting to
the gradient of phase with frequency (‘delay’) but that is not usually needed
for ALMA alone; phase and rate fitting only is done using fringefit
paramactive=[False,True,False]. The best available model should be used. If
successful, applying rate solutions should reduce the phase rate so that a
long (e.g. per-scan) gaincal solution can be used for phase calibration. A
number of rounds of calibration are likely to be needed to improve the model
and solutions iteratively.

Even if the phase errors do not have a consistent gradient, a similar
technique to fit to noisy phase variations with time uses gaincal
gaintype=’GSPLINE’. This can be used to interpolate solutions from a weak
phase calibrator over the target, as well as for target self-calibration, and
can be used for amplitudes as well as phases, see the CASA docs for gaincal
(link in Appendix B.3).

In both cases, the astrometric accuracy will be compromised.

###  5.11 Combining interferometric observations

This section covers multiple executions of the same EB or closely related ones
(e.g. a spectral scan) where the same array is used, and also combining
different arrays. When combining multiple observations, the first issue is to
make sure that they have a consistent target position and flux scale (allowing
for spectral index but assuming no target variability). See Sec. 5.2.1 for
additional considerations for spectral line observations. If you are deriving
solutions from one EB to apply to another you will need to use applycal
interp=’nearest’ (not linear) as linear interpolates but does not extrapolate
in time. If you are deriving solutions from more than one EB, you have to
concatenate them prior to gaincal, see Sec. 5.2.1 if you are using a spectral
line.

In the case of extra-solar Galactic objects with proper motions (see Sec. 5.12
for ephemeris objects), if accurate proper motions were available for each
observation, concat can be used to align MS by the target pointing centres
with the position at the earliest time present. It is all right if the peak is
offset, as long as the position relative to the pointing centre is the same at
each epoch. If not, due to proper motion uncertainties or errors in phase
transfer from the phase calibrator, discrepancies can be corrected by self-
calibration using a single-epoch model (Sec. 5.11.1). However, centring the
peak at each epoch before combination may provide a better starting-model,
using fixvis or phaseshift and fixplanets, see Appendix D.1.

Multiple executions of the same EB should give the same target flux density,
or, for different configurations, plotting amp against $uv$ distance should
show similar amplitudes for a similar $uv$ distance and frequency. There may
be some variations due to $uv$ angle, and if the longest baselines appear to
have a generally higher scatter of amplitudes than short ones then probably
this may be just noise. However, any discrepancy greater than the noise needs
to be removed.

The ALMA accuracy goal is 5–10% depending on band, worse in the early cycles,
but if different observations are made separated in time and/or with different
calibrators these errors accumulate.

Whether additional self-calibration can be used to reduce position or flux
scale errors, and improve combined data images, depends on what is being
combined.

####  5.11.1 Same configuration, different executions or spectral scans

For a single array configuration, if the target position (allowing for any
proper motion) is expected to be the same, as is the flux density (allowing
for spectral index), combined self-calibration can be useful to align EBs.
More data allows more accurate image models to be made (although the S/N in
each solution interval is not changed). Since the structure must be in common
for all spectral ranges observed at different times, only continuum can be
used for joint self-calibration of a spectral scan. If the tunings are closely
interleaved in time (within phase referencing intervals) you could use a
bright line, see Sec. 5.2 for issues like aligning the velocities.

If the position or flux discrepancies are significant, and one EB gives a
significantly better quality image or is more accurate based on a-priori
knowledge, you might want to use its image model as a starting model to phase
self-calibrate all executions. See Sec. 4.4.1 for choosing the refant.
Alternatively you can concatenate the data and make an image model from all
the data, if any discrepancies don’t cause noticeable artefacts, and perform
phase self-calibration. If amplitude self-calibration is possible it is best
to use all data and to solve for the target continuum spectral index if the
S/N permits, especially for a spectral scan, see Sec. 4.5.1.

####  5.11.2 Combining array configurations

There are many considerations when combining arrays (or interferometry plus
single dish total power data); this subsection only covers self-calibration
aspects. For a fuller overview, see the CASA Guide for M100 (ALMA) (link in
Appendix B.2). In this situation, e.g. combining ACA and 12-m array data
observed separately, at any given time, each antenna will only have baselines
within one array or configuration, so calibration tasks will handle the data
for each array separately and the S/N per antenna cannot normally be improved
by self-calibrating the data after array combination. The separate
configurations should be self-calibrated (where possible) before combination
as an image model made from one configuration is probably not representative
of the signal on the spatial scales of another configuration. One exception is
if there is a bright source which is completely unresolved in any
configuration, but otherwise it is usually better to deal with any offsets in
position or flux scale by other means, see Appendices D.1 and D.2.

However, if there is a good range of overlapping baseline lengths, image
models made from a different or multiple configurations may be useful in self-
calibrating individual configurations, if one or more are hard to self-
calibrate due to missing spacings or low S/N. Self-calibrate individual
configurations first as long as this leads to improvements and then make a
combined image model from all calibrated target data. For instance, if you
have MS for extended and compact 12-m array configurations, (generally
referred to as TM1 and TM2), you can using concat to combine the MS, and then
image TM1+TM2 together to provide starting model to self-calibrate TM1. Use
the listobs output for the concatenated MS to select the scan numbers
corresponding to TM1.

Alternatively, you can make the first combined image without concatenation (as
tclean will take a list of MS), and then use ft to Fourier transform the model
into TM1. It will only be inserted on scales corresponding to baselines
actually present in the data. Using this for self-calibrating TM1 won’t lead
to sensitivity to larger scales, but it will avoid model errors giving rise to
spurious calibration solutions. If the starting model does not represent the
smallest scales properly you might need to exclude the longest baselines in
the first rounds of TM1 self-calibration.

Similar situations include using the model from well-calibrated data to be
combined with another configuration which is not phase-referenced, see Secs.
5.3 and 5.5.

Total Power (single dish) observations cannot be conventionally self-
calibrated, even if you have created pseudo-visibilities, since there is no
observational phase information, although they can be used in combination with
array data to constrain large scales in a model for array self-calibration.
Time, frequency or amplitude/flux scale errors should be corrected using
specialised single dish tasks before combination.

###  5.12 Extended emission, Solar System Ephemeris Objects and the Sun

Figure 16: Left, a source likely to have some missing flux on baselines
$<$20m. Right, Venus, showing extreme missing flux and many nulls, suggesting
that it comes close to filling the imageable field of view.

Many Solar system objects – planets, many moons and asteroids – have
ephemerides and models in CASA (setjy standard=’Butler-JPL-Horizons 2012’
Butler 2012). These are generally very accurate with a few caveats for
insolation-dependent flux densities and atmospheric lines. When setting time-
dependent model such as these in setjy always use usescratch=True. For early-
cycle observations the task fixplanets was needed early in processing to apply
the ephemeris to a Solar System target. Having attached or applied the
ephemeris, a Solar System object, whether observed as a calibrator or target,
can be self-calibrated mostly like any other target, apart from any issues
with very large or bright objects, discussed below. If combining multiple
executions, use concat forcesingleephemfield=’Callisto’ (or whatever the
object is). It may not be possible to combine observations separated in time
such that the apparent angular size or flux density of the object has changed
significantly.

See the help for tclean for imaging ephemeris objects; normally, use
phasecenter=’TRACKFIELD’ and, if relevant, specmode=’cubesource’. It is a
matter of judgement whether to use your image, or a built-in model as the
model for self-calibration; using the latter, especially for continuum where
the objects are very well-studied, at least for the initial phase calibration,
can allow you to go straight to a shorter solution interval if S/N permits.

Fig. 16, left, shows a source with flux continuing to rise on the shortest
baselines. It will be necessary to take great care not to include artefacts
due to the missing spacings in the self-calibration model, and the S/N needs
to be based on the $\sim$0.5 Jy flux on the longest baselines, but self-
calibration for phase and amplitude should be possible with the usual S/N
considerations. If additional observations sampling the missing spacings are
available, see Sec. 5.11.2.

Fig. 16, right, shows a planet which not only has much missing flux, as shown
by the precipitous rise for baselines $<$20 m, but many nulls. This indicates
that not only is there much smooth flux on scales not properly sampled but it
has it an angular size probably approaching or exceeding the PB FWHM. Phase
self-calibration can be possible without necessarily restricting the $uv$
range, usually using the ephemeris model. If there were only one or two nulls,
it could be possible to select a $uv$ range or ranges in gaincal where all
antennas have at least 3 baselines with ‘enough’ S/N for amplitude self-
calibration, to a suitable selection of reference antennas. However, the
reduced number of antennas contributing to some solutions will increase the
effective noise and solutions derived from selected $uv$ ranges should be
inspected carefully. In the case shown in Fig. 16, right there are too many
nulls and amplitude self-calibration is probably not possible.

Check for lines if the object has an atmosphere; these may be included in the
built-in model but if the object is resolved their location may be variable
and it is best to exclude the affected channels during self-calibration. The
motion of the emitting regions relative to the planet centre (due to its
solid-body rotation and/or winds) may be significant, see e.g. Sault et al.
(2004) for an example of dealing with this in VLA data.

If you are imaging a Solar System object which was originally observed as a
calibrator and calibrated per execution using the built in model, you can
continue to calibrate combined data using that model. If you combine data for
a Solar System calibrator and make an image model and insert this into the MS
for self-calibration (rather than using the built-in model), the data are then
aligned with the single image so you may not need to use ’TRACKFIELD’, but
just leave phasecenter blank. However, be very careful to write a model
scratch column (not virtual, see Sec. 4.3.2) and check on a sample image.

Obtaining an image with the correct flux scale is problematic for very bright
and/or beam-filling planets, even with an accurate ephemeris value. If it
makes a significant contribution to $T_{\mathrm{sys}}$, not only will the flux
scale need correcting for this (Appendix D.3) but the internal model is for
the ‘true’ brightness distribution, although the signal imaged by ALMA in a
single pointing will have PB attenuation. Two possible solutions are to use a
scaled model, or to ignore the flux scale during processing and apply a global
correction factor (immath) to the final images or measurements. Emission may
extend beyond the well-characterised part of the PB.

For Solar observations with ALMA, see ALMA-TH and the Solar CASA Guide
(Appendix B.2). Once an image giving a good starting model has been achieved,
self-calibration can be used, with the final rounds of calibration normally
using very short (per-integration, e.g. 2s) averaging times, see e.g. Nindos
et al. (2018).

###  5.13 Baseline-dependent calibration

Baseline-dependent errors are errors which cannot be factored into per-antenna
terms. Such errors provide an additional additive term for just one or some of
the terms in square brackets in the phase closure relationship Eq. 10. Thus
the expression does not sum to zero. For this reason they are sometimes called
‘non-closing’ errors. They are usually instrumental in origin (arising after
correlation), and not direction dependent (${\mathbf{M}}_{ij}$ in Eq. 2),
although using a point model for a resolved phase calibrator can produce
similar effects (SI99 Ch. 5 Fomalont & Perley). For this reason, check if this
may be the problem and if so, see Sec. 5.5 before considering baseline
calibration.

The number of baselines contributing to an image is $N(N-1)/2$ where $N$ is
the number of antennas, and hence if solutions are estimated per baseline the
noise per baseline is much higher than per antenna, giving
$\sigma_{\mathrm{solint,baseline}}=\sigma_{\mathrm{solint,ant}}\times\sqrt{N-3}$
for the same solution interval (see Sec. 4.4.2, Eq. 23). Equivalently, for a
given image S/N, the minimum solution interval for baseline self-calibration
is thus increased by a factor of $(N-3)$ relative to the value obtained from
Eq. 24 for antenna-based self-calibration.

For $N=20$ (the example in Sec. 4.4.2) the image S/N needed for antenna-based
calibration is 35 (Eq. 25) but would need to be nearly 150 for baseline-
dependent calibration. Each solution is less well-constrained, especially in
extended configurations and/or short observations when very few baselines may
sample a particular scale in the target, so the model needs to be close to
perfect since there is a higher risk of obtaining apparently good solutions
which are in fact based on artefacts. Task blcal can be used to solve for
phase and/or amplitude and even has an option of frequency-dependent solutions
– requiring even greater S/N and model accuracy.

Antenna-based calibration should be completed and applied first. Baseline-
based calibration is most often used when the target contains a very bright
point source plus very weak extended emission or spectral lines (typically, an
AGN at cm wavelengths), so that a dynamic range $\gg 1000$ is needed.

##  6 Imaging problems and diagnostics

This section describes some of the problems you might find in an image, how to
track down the causes and possible remedies. It concentrates on ALMA problems,
and assumes that the observations are well-designed. For example, time- and
bandwidth-smearing are not covered, but the conditions are shown in Appendix
E. More details are given in SI99 Ch. 18 (Bridle & Schwab) and Ch. 15 (Ekers)
and the talk on error recognition by Taylor at the 2017 NRAO workshop (see
Appendix B.1) for more general coverage. Not all errors are correctable by
self-calibration, and there may be more than one problem present. Check
whether pipeline or QA2 images show that previous calibration/flagging needs
improving. Sometimes re-imaging with parameters more suitable for a particular
target brings good improvements.

In many cases it is not possible to distinguish unambiguously between causes
of error. In order of decreasing probability (in ALMA data), stripes may be
due to an amplitude calibration error (solvable by self-calibration, Sec. 4.5)
or due to bad data (needing flagging, see Sec. 4.6.3) or due to confusion
(requiring better imaging, Sec. 6.4). However, you may have to test different
solutions by trial and error.

Figure 17: 1a: Single, peak channel of the VY CMa data to be used for self-
calibration, phase calibrator solutions only. 1b: Phase self-calibration. 1c:
Phase then amplitude self-calibration but too few clean iterations. 1d as 1c
but cleaned fully. 2a: Different VY CMa channel, with extended emission, fully
calibrated, full resolution, robust=0.5. 2b: uvtaper=’0.1arcsec’, robust=1.
2c: as 2b but also multiscale clean. 2d: as 2c but omitting a central antenna.

Figure 18: 3a–d: VY CMa peak channel as in Fig. 18 1a with artificial errors
added. 3a (3b): Amplitude error on an antenna with mostly long (short)
baselines. 3c: Phase error on an antenna with mostly long baselines. 3d:
Amplitude error on many baselines for a short time (few integrations). 3e:
Confusing source outside image, not included in cleaning (target at (0,0)).
3f: 3e but with confusing source included in cleaning (note different angular
size of image). 4a: Visibility amplitudes for Fig. 18 2a–c, showing extended
flux on antenna removed for 2d. 4b: Visibility amplitudes showing mis-scaled
data causing errors in 3a (mauve) and 3b (black).

###  6.1 Stripes and other structured artefacts

It may be easier to see the errors illustrated in Figs. 18 and 18 on-screen.
In real life you can change the colour scaling in the CASA viewer. Fig. 1
showed examples taken from very early ALMA data where having only 6 antennas
meant errors had a very obvious effect. Similar examples are given here for
some spectral lines taken from the VY CMa data.

In theory you can use the artefact spacings in the image to identify the
baseline lengths responsible for errors but this is very difficult for many
antennas, although it can give some guidance. Artefacts with a spacing similar
to the synthesised beam suggest that one or more antennas with long baselines
are affected; the larger the image spacing of the artefacts, the shorter the
baselines which are implicated. It is usually easier to spot errors in the
visibilities, e.g. use the plotms selections to scroll through all baselines
to the reference antenna and use the locate facility.

Fig 18 1a shows anti-symmetric errors typical of widespread phase errors (Sec.
1.3) which initially dominate a target image with only phase calibrator (and
earlier) solutions applied. If only one antenna is affected, the errors are
elongated as in Fig. 18 3c, especially for a distant antenna in a short
observation, where most of the baselines have a similar direction. After phase
errors are corrected by self-calibration, more symmetric amplitude errors are
revealed, Fig 18 1b. These are usually not so serious but sometimes one
antenna is dramatically mis-scaled, as in Fig. 18 3a and 3b. The longer the
baselines, the narrower are the stripe spacings in the image plane. Fig. 18 4b
shows the baseline ranges of the bad data, which can help pin down the
antenna(s) responsible. Such errors can occur in real life due to
$T_{\mathrm{sys}}$ errors, for example – see Sec. 6.7 for amplitude errors
without associated phase errors.

Fig. 18 3d shows the similar effect of a short burst of bad amplitudes on all
or many antennas but just for a few integrations. Plotting visibility
amplitudes against time can show the bad data. This is less common in ALMA
data but typical of interference at cm wavelengths, where the affected data
also have bad phase. Usually such data must be flagged. For ALMA, if a lot of
data seem to be affected, check the raw visibilities (i.e. before any
calibration at all) in case the target data are fundamentally OK but there is
a problem with $T_{\mathrm{sys}}$ or the phase calibrator (as in Sec. 5.3,
Fig. 14).

Dynamic range errors (Sec. 3.3) are usually dominated by amplitude errors as
in Fig 18 1a or resemble Fig 18 1c and can similarly be tackled by self-
calibration (starting with phase as usual, being careful to restrict the model
to emission you are sure is real). If the signs of phase or amplitude errors
persist for a very bright target, reduce the solution interval as much as is
possible for the S/N (Sec. 4.4.2). Check whether the weights need optimising
(e.g. statwt, Sec. 4.7.1) or even consider baseline calibration (Sec. 5.13).

Errors due to a specific time or antenna where the amplitude and/or phase are
anomalous, but the phase is coherent and amplitudes are not much noisier, can
usually be corrected by self-calibration. However, for very short-timescale
errors, it might be necessary to flag the data if the S/N is too low for a
short enough solint. You might have to exclude the affected data to get a
starting model (Sec. 5.3). If you have trouble identifying the antenna(s),
scans, channels responsible for bad data, check the weights for anomalies and
try no averaging and different averaging intervals – remember that bad phases
depress amplitudes; the affected data will have lower amplitudes the more you
average bad phase.

A persistent sidelobe pattern as in Fig 18 1c or worse (often looking like
spokes radiating from the peak) even after attempting full calibration and
cleaning can indicate a time-variable source (Sec. 6.8).

Fig 18 2a shows the ‘basket weaving’ effect due to gaps in the visibility
plane coverage on longer baselines whilst Fig 18 2d shows the effects of
missing short spacings. These may be mitigated by changing imaging parameters
(Secs. 6.2, 6.3) but not by calibration.

Fig. 18 3e shows curving artefacts typical of sidelobes of a confusing source
to the left of the target at (0,0). The solution is simply to make a larger
image and mask all the sources in cleaning, as in Fig. 18 3f (confusing source
in the NE), see Sec. 6.4. All sources must also be included in models for self
calibration.

###  6.2 Optimise imaging

Before self-calibration, check for problems which may be mitigated by more
suitable imaging parameters. This will also help to make sure you have good
calibration models (although see Sec. 4.3 about not downweighting baselines
during calibration if possible).

Imaging weights are applied in addition to sensitivity-based weights applied
during calibration (Sec. 4.7.1). The combination affects the final image
resolution (for example, if the most distant antennas are less perfectly
calibrated then sensitivity-base weighting in calibration will coarsen
resolution, but using a smaller tclean robust value can mitigate this albeit
probably increasing the noise). Both need careful tuning if you have to
optimise for a specific resolution or surface brightness sensitivity rather
than best S/N.

For ALMA, tclean weighting=’briggs’, robust=0.5 usually gives the best S/N.
Negative robust values give finer resolution but tend to increase the noise
and so do not necessarily improve measurement precision (see Sec. 3.5.2).
Higher robust values may be useful if the observations are affected by missing
spacings as in Fig. 18 2a and 2d, see Sec. 6.3. For sparse arrays/VLBI,
weighting = ’natural’ may make the best use of a small number of antennas.
Where appropriate, use spectral index and/or multiscale imaging (as noted in
Secs. 4.3 and 4.5.1); Fig. 18 2c shows an example of multiscale imaging, which
also speeds up cleaning. The models produced by both methods can be used in
self-calibration.

Clean masks should be neither too large nor too small – ideally roughly just
enclosing the emission which is brighter than anything not known to be real,
which may increase in area in successive clean cycles. Don’t clean too deeply
such that CC are made from noise (Fig. 7) nor too shallowly. Fig. 18 1c shows
an undercleaned image with sidelobes still visible. Check the residual map,
which should not show any traces of the target above a few times the rms
noise. For a perfectly Gaussian noise distribution in an image (without PB
correction), about 3 out of every 1000 pixels are likely to have values
outside $3\sigma_{\mathrm{rms}}$, which is 200 pixels in a $256\times 256$
image (although the chances of being correlated over a beam is lower); less
than 1 pixel (on average) exceeds $4.5\sigma_{\mathrm{rms}}$. The image noise
may be non-Gaussian before calibration is perfect but there should be
approximately equal distributions of positive and negative artefacts. Fig. 19
left shows the residual for the image in Fig. 18 1b, with the image contours
overlaid. A histogram of the noise distribution is shown on the right. It can
be seen that a few hundred pixels lie outside the cyan lines marking $\pm
3\sigma_{\mathrm{rms}}$ values ($\sigma_{\mathrm{rms}}\sim$6 Jy beam-1) but in
this $256\times 256$ image none exceed $|4\sigma_{\mathrm{rms}}|$.

Figure 19: Left: Residual (in greyscale) with image contours (at
[-1,1,2,4,8,16]$\times$ $3\sigma_{\mathrm{rms}}$ ($\sim$18 Jy beam-1)
overlaid, for the image in Fig. 18. Note that although residual images are
normally not convolved with a restoring beam, i.e. flux units Jy pixel-1, they
have been converted to the equivalent in Jy beam-1 for the image beam, for
easy comparison. 1b. Right: Histogram of the distribution of pixel intensities
in the residual (from the CASA viewer). The black line shows a Gaussian
distribution fitted to the noise, with cyan lines marking the $\pm
3\sigma_{\mathrm{rms}}$ values.

###  6.3 Missing spacings

Fig 18 2d shows a small effect of missing short spacings. If you have negative
regions surrounding brighter parts of the image, (the ‘cereal bowl’ effect) a
probable cause is resolved-out, large scale emission. This occurs when a
source has structure which is smooth on scales similar to and larger than the
resolution of the shortest baselines present, bright enough to be detected but
not imaged properly, so the sparse sampling creates large-scale artefacts. If
so, a plot of amplitude v. $uv$ distance will reveal a steep increase in flux
on short spacings e.g. Fig. 16. In such cases, really good results are only
likely to be possible by adding in shorter spacings or total power data. This
is particularly true if the field contains emission on all scales (possibly
extending outside the total field of view), e.g. a large planet or star
forming region with bright, extended emission.

If you can’t add in more data, you can either emphasise the extended emission
or minimise its impact, depending on what aspect of the data you are
interested in. If only the shortest baselines (partially) detect the extended
emission whilst you are mainly interested in compact emission, you can try
just excluding the shortest baselines. The extended emission may then be
completely resolved out or below the surface brightness threshold. Conversely,
if the extended emission is mainly on scales which are poorly sampled but not
much larger, try weighting down the longest baselines using uvtaper as in Sec.
6.2 to increase the synthesised beam. In either case, removing the
contribution of a large fraction of baselines will increase the noise.

Images are also affected by missing intermediate spacings, which tends to
affect ALMA configurations with baselines $\gtrsim 5$ M$\lambda$. Fig. 18 2a
shows that the default tclean deconvolver and weighting (robust=0.5) can leave
a criss-cross pattern sometimes called ‘basket weaving’, in this case due to
the missing spacings around 1250 and 1850 m. This is seen in Fig. 18 4a,
restoring beam size (204$\times$101) mas, and the fine details cannot be
trusted. Applying a uvtaper=’0.1arcsec’ and robust=1. gives a beam
(274$\times$205) mas and Fig. 18 2b shows that although the artefacts can
still be seen faintly in the noise, the cleaned emission is no longer
distorted.

Avoid using $uv$ tapers or other downweighting of specific baselines during
calibration if possible. The longest baselines are likely to have greater
phase errors, and if you can make a reasonable model and self-calibrate
without a $uv$ taper this will allow better calibration for the most distant
antennas; just apply the taper for the final images if necessary, as explained
in Sec. 4.7.1. If, however, the most distant antennas are so badly calibrated
initially that a good image cannot be made, exclude these to make a starting
model and then gradually increase the $uv$ range as self-calibration
progresses, as in Sec. 5.3.

###  6.4 Confusion

Confusion is the presence of bright sources offset from the pointing centre
but within the PB. This can be due to continuum sources affecting the whole
bandwidth or in some cases due to spectral lines, affecting just some
channels. If these are not included in clean masking, artefacts as in Fig. 18
3a are seen. This is commonest at longer wavelengths, so check ALMA data for
amplitude calibration errors or bad data first, but high dynamic-range ALMA
observations of crowded fields e.g. star clusters may be affected. Confusion
by point sources creates a sidelobe pattern, and can be cured by imaging the
culprits. Confusion due to extended emission appears as a steeply rising
excess on short baselines (similar to Fig. 18 4a) but a compact source more
distant than the largest angular scale sampled will not show up like this.

All emission in the field used for a self-calibration model – even if it is
not your science target – should be included in any self-calibration model.
This may even (occasionally, for ALMA) allow self-calibration fields
containing targets which are themselves too faint. In wide-field imaging at
lower frequencies, they may require direction-dependent calibration, Sec. 5.8.

The primary planet can cause confusion in ALMA moon observations and, often
extending through a range of PB sensitivities, adds diffuse noise and is
harder to deal with. When planning observations, remember to allow for the
diameter of the planet, not just its nominal central coordinate.

Spectral cubes may be affected by CO and other contamination from the Milky
Way or nearby galaxies, or in planetary atmospheres. This may be on scales too
large to image but large enough to increase the noise and create artefacts, so
check catalogues etc. for observations in galactic planes.

###  6.5 Noisy images and non-noisy blurring

If images are noisier than expected but without distinctive artefacts, inspect
the visibilities as a function of time for obvious errors e.g. scans which are
complete noise (but see Sec. 5.3 before flagging). If all target data are
noisier than expected check the conditions during observations, see Secs.
3.5.1 and 6.6.2.

Another possibility is frequency-dependent errors, which can blur continuum
images and thus degrade the accuracy of their models, also affecting
calibration applied to lines. Check the line cube or visibility spectrum in
case the continuum channel selection contains line contamination (even in spw
designated continuum by the PI). Exclude more channels if necessary. If there
are likely to be many lines, check cube spectra using different size apertures
and/or inspect the visibility spectrum with averaging for sensitivity in
different $uv$ ranges. More lines may become significant as calibration
improves the S/N.

Are there atmospheric lines causing very noisy regions of the visibility
spectrum? These can be overplotted in plotms or identified using the ALMA
atmospheric model (see Appendix B.5 for link). The $T_{\mathrm{sys}}$
correction usually flattens the bandpass (since Cycle 1) and can lower the
weight for affected channels, mitigating the effect in imaging. If there are
important spectral lines, predicted to be detectable in a noisy spectral
region, see Sec. 5.1.

If there is no hope of retrieving any emission of interest, it may be better
to exclude affected channels from calibration and imaging or flag them. Since
sensitivity $\sigma_{\mathrm{rms}}\propto\sqrt{\Delta\nu}$, where
${\Delta\nu}$ is the bandwidth, excluding e.g. half of one spw, out of four of
equal width, will only increase the noise by a factor of $\sqrt{4./3.5}$, i.e.
an increase $\lesssim 7$%.

Spectral problems may be due to previous calibration issues, Sec. 6.6.

###  6.6 Errors during observations or previous calibration

####  6.6.1 Delay and phase errors and the effects of antenna position
uncertainty

In a spectral cube, bands of higher and lower noise across the whole image,
which shift in position from channel to channel, suggest errors in the delay
(phase as a function of frequency). These may also cause small position
errors. In making continuum images of different bandwidth (e.g. for the phase
calibrator), you should see $\sigma_{\mathrm{rms}}\propto\sqrt{\delta\nu}$ but
bandpass errors (phase or amplitude) will decrease the noise by a smaller
factor than expected. Such errors may be due to poor bandpass calibration,
which usually affects the amplitude corrections more than phase, see Sec. 6.7
and/or to earlier delay errors.

The cause of delay errors is often antenna position uncertainty which causes
direction-dependent errors in calculating the bulk delay and so phase
corrections, (as a function of time and of frequency), derived for one
calibrator, will be inaccurate when applied to another source (Sec. 2.1.4). If
the phase-reference or target is bright enough to see a pattern when plotting
phase as a function of frequency this will produce a slope in the corrected
continuum visibilities for the affected antenna, i.e. a delay error. The task
gencal uses antenna position updates to derive delay corrections for the
affected antennas. This is part of normal pipeline and manual calibration. If
more accurate positions become available later (see Analysis Utility
checkAntennaPositionFiles, Appendix B.2, requiring internet access), re-
generating and re-running the reduction pipeline will use the best current
corrections; however you are likely to need the help of an ARC to modify the
calibration pipeline. Alternatively, the antenna correction entries can be
edited in manual scripts. In either case it is then necessary also to repeat
all bandpass, phase referencing and related calibration. The worst effects of
residual antenna position errors can be removed by self-calibration but the
frequency-dependence of the phase error will remain.

From Eq. 9 a 2 mm antenna position error will cause a change in the phase
error $\phi_{\epsilon,{\mathrm{antpos}}}$ of e.g. 5% across a sideband span of
12 GHz around 230 GHz. For a large
$\phi_{\epsilon,\mathrm{antpos}}=50^{\circ}$ this is $2.5^{\circ}\sim 0.04$
rad. In principle this leads to an image position error $\sim
0.04\theta_{\mathrm{B}}$ (equivalent to the error in Gaussian fitting for S/N
$\sim 25$, Sec. 3.5.2). In reality, on the one hand many antennas may be
affected, but on the other hand the baseline angles and thus the phase slopes
will usually not all be in the same sense. This will blur (rather than
elongate) continuum sources and cause jitter in the positions of spectral
lines.

The line peak in the VY CMa data used here is 271 Jy, S/N 1330 and
$\theta_{\mathrm{B}}\sim 200$ mas so the noise-based position uncertainty
$\sigma_{\mathrm{pos}}=\theta_{\mathrm{B}}/$(S/N) =
$0.00075\theta_{\mathrm{B}}\sim$0.15 mas. The relative positions of maser
components in successive channels show a drift of $\sim$0.5 mas, or 0.0025
$\theta_{\mathrm{B}}$, which is notionally significant. If the drifts are in
different directions for different sets of spectral components that is
probably genuine but if the position-velocity gradient is always the same it
is probable that delay errors are the cause.

Delay errors in other data e.g. VLBI may be due to clock errors etc. (see VLBI
links in Appendix B.1) or to antenna position errors.

####  6.6.2 Noise/artefacts due to phase-reference and other problems

Although self-calibration can solve some phase-referencing errors, the target
noise may not reach the expected level or there may be persistent artefacts.
If you examine the target corrected visibilities in plotms after applying
phase reference solutions, changes due to astrophysical structure should vary
smoothly with time, but jumps in amplitude or phase on individual antennas or
larger deviations on short baselines than on long suggest prior errors. This
may arise if the initial errors are so great that a good starting image is
hard to make. If the target is bright enough you can optimise making the first
image with no or poor phase-referencing, Sec. 5.5.

If the phase-calibrator is weak, failed solutions can lead to excess flagging
of good target data. Check the pipeline weblog or qa2 report plots of
calibration tables (see Sec. 4.6) and the calibrated data for calibration
sources. It may be possible to improve the phase calibrator calibration, see
Sec. 5.1 for some tactics, in particular to reduce the number of failed
solutions or improve the amplitude solutions (which requires adequate previous
phase solutions). This is especially important if the target is too weak for
amplitude self-calibration. Amplitude errors usually change slowly but one
antenna may be mis-scaled, so once the calibrator bandpass and phase are
corrected more than a scan can be averaged if necessary.

Excess image noise may be due to short-timescale noise, too rapid to correct
by self-calibration. Occasionally, time-dependent phase errors may originate
from WVR measurements. The pipeline or QA2 plots and reports show whether
applying PWV corrections improved phase coherence or not. If the PWV is low
(e.g. $<$1 mm at Band 3) corrections may do more harm than good. Conversely,
for PWV $\gtrsim$2 mm, the conventionally-derived corrections may be
inadequate due to clouds, see link in Appendix B.5 for the correction recipe
Remcloud. This may also be noted in the QA0 report.

Tweaking manual QA2 scripts is relatively straightforward. If the data were
originally pipelined, target flagging and continuum channel selection can be
modified following the CASA Guide to the ALMA Imaging Pipeline (see Appendix
B.2). You will probably need expert help from an ARC to rectify problems with
phase-referencing or earlier calibration, either by re-pipelining or by
generating manual scripts.

###  6.7 Amplitude errors due to $T_{\mathrm{sys}}$, antenna pointing or
tracking errors

If images and calibrated visibilities appear to show amplitude errors even
though the phases and delays look good, this could be due to inconsistent
$T_{\mathrm{sys}}$ or bandpass calibration for the target and phase calibrator
or to antenna(s) pointing incorrectly, either systematically or eratically.

If $T_{\mathrm{sys}}$ tables look mis-scaled but with a reasonable relative
S/N and no spikes or large jumps (more than few tens percent, except at edges)
these can be rescaled (see Appendix B.2 link for Analysis Utilities) and then
the remaining calibration repeated (as in the pipeline or QA2, but see Sec.
6.6.2 above). Otherwise, to tackle this just by self-calibration, you can try
excluding the affected antenna(s) to make a starting model as in Sec. 5.3, and
if possible do amplitude self-calibration including all antennas. You can
average over the whole time affected if necessary for S/N. Check for spikes or
other $T_{\mathrm{sys}}$ anomalies. If maverick $T_{\mathrm{sys}}$ channel(s)
are present for only one of the target or the bandpass calibrator you may be
able to remove the discrepancy by editing the $T_{\mathrm{sys}}$ table (see
Appendix B.2 link for Analysis Utilities).

Check if the bandpass calibrator corrected bandpass looks noisier than typical
amplitude excursions ($<$5% in lower ALMA bands, ALMA-TH). Bandpass
calibration might be improved by flagging bad data or changing the solution
interval in prior phase calibration of the bandpass calibrator or the spectral
averaging interval in bandpass, or perhaps using a different source with
better S/N. As long as $T_{\mathrm{sys}}$ has been applied to take care of
short-term spectral amplitude calibration, the instrumental causes of bandpass
errors are usually stable for hours or even days so it may be possible to copy
a better bandpass table from another EB taken using the same frequency,
spectral and array configuration. Occasionally, very noisy spectral regions
are present (Sec. 6.5) and can be excluded from the spw selection during time-
dependent calibration of the bandpass calibrator, phase calibrator etc. even
if you want to include them in bandpass calibration.

An uncorrected antenna pointing offset will skew the primary beam response.
ALMA-TH describes ALMA’s pointing strategy and other arrays e.g. VLA at high
frequencies use ‘pointing up’ but in some arrays, especially VLBI, antennas
take different times to slew and some arrive late. If just the first or last
few visibilities of every scan are bad see flagdata mode=’quack’.

Normal self-calibration for compact targets may reduce small pointing/tracking
errors but if all sources are affected, you may need to redo earlier
calibration from the derivation of the flux scale onwards: exclude the
affected antenna(s) in deriving the phase calibrator flux and then set this
(setjy) and make a good phase-reference amplitude correction table for all
antennas. Applying this plus the phase and other corrections to the target may
be good enough (although the image will inevitably be a bit noisier due to the
lower sensitivity of badly-pointed antennas to off-centre targets). However,
for Alt-Az mounts such as ALMA uses, the beam will rotate relative to the sky
over the course of long observations. If a target field has components offset
from the nominal pointing centre the pointing errors cause them to fall in
different regions of primary beam senstivity during the observations. To self-
calibrate, make an initial image model excluding the affected antennas, as
above for $T_{\mathrm{sys}}$ errors, and see Sec. 5.3. The amplitude solution
interval needs to be less than the interval over which the apparent amplitudes
change significantly.

###  6.8 Target Variability

A very severe sidelobe pattern radiating outwards from bright sources can be
caused by variability during the observation. In such a case, phase solutions
should be applied normally but do not perform amplitude self-calibration on
the whole data set – if you do, it usually makes the image worse, often how
one discovers unexpected variability. Usually variable sources are point-like,
and if you just want a light curve it might be best to obtain this from the
visibilities. If the variable source is not at the centre of the field, shift
the phase centre to its position using the transform tab in plotms or
mstransform; for large shifts use the task phaseshift, in CASA 6.3 and later.
Alternatively, you can make images of each time segment long enough to produce
a reasonable image but short enough to minimise variability and measure the
variable source in each one.

In order to make a combined image of any non-variable emission in the field,
you need to subtract the variable component. This is possible if you can make
good enough image models for time segments over which the variablity has
little effect, masking just the variable source (unless there are other
sources in the field bright enough for their sidelobes to be a problem in
which case subtract first or at the same time). Divide the data into the
segments and, for each segment, clean to the noise or non-variable background
but not too deeply and check that the model is saved (Sec. 4.3.2). uvsub can
then be used to subtract the model of the variable source. Then recombine the
subtracted data sets and image. You can alternatively subtract a simulated
model from each segment. If there are also antenna-dependent amplitude
problems you could try self-calibration for each time segment before
subtracting the variable source but this runs the risk that the amplitude
scale may diverge between segments.

## References

  * [ALMA-TH], Cortes (2022) [ALMA-TH], Cortes, P. A., ed. 2022, ALMA Technical Handbook (ALMA, https://almascience.org/documents-and-tools)
  * Asaki et al. (2020a) Asaki, Y., Maud, L. T., Fomalont, E. B., et al. 2020a, AJ, 160, 59
  * Asaki et al. (2020b) Asaki, Y., Maud, L. T., Fomalont, E. B., et al. 2020b, ApJS, 247, 23
  * Bhatnagar & Cornwell (2017) Bhatnagar, S. & Cornwell, T. J. 2017, AJ, 154, 197
  * Bonnassieux et al. (2018) Bonnassieux, E., Tasse, C., Smirnov, O., & Zarka, P. 2018, A&A, 615, A66
  * Brogan et al. (2018) Brogan, C. L., Hunter, T. R., & Fomalont, E. B. 2018, arXiv e-prints, arXiv:1805.05266
  * Butler (2012) Butler, B. 2012, in ALMA Memo Series, No. 594, Flux Density Models for Solar System Bodies in CASA, https://library.nrao.edu/public/memos/alma/main/memo594.pdf,
  * Condon (1997) Condon, J. J. 1997, PASP, 109, 166
  * Cornwell et al. (2005) Cornwell, T. J., Golap, K., & Bhatnagar, S. 2005, in Astronomical Society of the Pacific Conference Series, Vol. 347, Astronomical Data Analysis Software and Systems XIV, ed. P. Shopbell, M. Britton, & R. Ebert, 86
  * Cornwell & Wilkinson (1981) Cornwell, T. J. & Wilkinson, P. N. 1981, MNRAS, 196, 1067
  * Cotton (2012) Cotton, W. D. 2012, Journal of Astronomical Instrumentation, 1, 1250001
  * Decin et al. (2015) Decin, L., Richards, A. M. S., Neufeld, D., et al. 2015, A&A, 574, A5
  * Fenech et al. (2018) Fenech, D. M., Clark, J. S., Prinja, R. K., et al. 2018, A&A, 617, A137
  * Goddi et al. (2019) Goddi, C., Martí-Vidal, I., Messias, H., et al. 2019, PASP, 131, 075003
  * Hunter et al. (2016) Hunter, T. R., Lucas, R., Broguière, D., et al. 2016, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 9914, Millimeter, Submillimeter, and Far-Infrared Detectors and Instrumentation for Astronomy VIII, ed. W. S. Holland & J. Zmuidzinas, 99142L
  * Jennison (1958) Jennison, R. C. 1958, MNRAS, 118, 276
  * Jung et al. (2011) Jung, T., Sohn, B. W., Kobayashi, H., et al. 2011, PASJ, 63, 375
  * Martí-Vidal et al. (2014) Martí-Vidal, I., Vlemmings, W. H. T., Muller, S., & Casey, S. 2014, A&A, 563, A136
  * Maud et al. (2016) Maud, L. T., Fomalont, E., Tilanus, R., & Dent, W. 2016, in ALMA Memo Series, No. 606, ALMA & Allegro Phase Metrics Workshop Report, https://library.nrao.edu/public/memos/alma/main/memo606.pdf,
  * Maud et al. (2017) Maud, L. T., Tilanus, R. P. J., van Kempen, T. A., et al. 2017, A&A, 605, A121
  * Nagayama et al. (2020) Nagayama, T., Kobayashi, H., Hirota, T., et al. 2020, PASJ, 72, 52
  * Nakazato et al. (2020) Nakazato, T., Ikeda, S., Kosugi, G., & Honma, M. 2020, in Society of Photo-Optical Instrumentation Engineers (SPIE) Conference Series, Vol. 11453, SPIE Astronomical Telescopes + Instrumentation, 2020, 114532V
  * Nindos et al. (2018) Nindos, A., Alissandrakis, C. E., Bastian, T. S., et al. 2018, A&A, 619, L6
  * Offringa et al. (2014) Offringa, A. R., McKinley, B., Hurley-Walker, et al. 2014, MNRAS, 444, 606
  * Offringa & Smirnov (2017) Offringa, A. R. & Smirnov, O. 2017, MNRAS, 471, 301
  * Pardo (2019) Pardo, J. R. 2019, in ALMA Development Workshop, 36
  * Richards (1997) Richards, A. M. S. 1997, PhD thesis, University of Manchester
  * Richards et al. (2014) Richards, A. M. S., Impellizzeri, C. M. V., Humphreys, E. M., et al. 2014, A&A, 572, L9
  * Richards et al. (1999) Richards, A. M. S., Yates, J. A., & Cohen, R. J. 1999, MNRAS, 306, 954, (R99)
  * Rivi et al. (2019) Rivi, M., Lochner, M., Balan, S. T., Harrison, I., & Abdalla, F. B. 2019, MNRAS, 482, 1096
  * Sault et al. (2004) Sault, R. J., Engel, C., & de Pater, I. 2004, ICARUS, 168, 336
  * Sault et al. (1996) Sault, R. J., Hamaker, J. P., & Bregman, J. D. 1996, A&AS, 117, 149
  * [SI99] et al. (1999) [SI99], Taylor, G. B., Carilli, C. L., & Perley, R. A., eds. 1999, Synthesis Imaging in Radio Astronomy II, Vol. 180 (Astronomical Society of the Pacific Conference Series, https://www.aspbooks.org/a/volumes/table_of_contents/?book_id=292)
  * Sob et al. (2021) Sob, U. M., Bester, H. L., Smirnov, O. M., Kenyon, J. S., & Russeeawon, C. 2021, MNRAS, 504, 1714
  * Tasse et al. (2018) Tasse, C., Hugo, B., Mirmont, M., et al. 2018, A&A, 611, A87
  * Tasse et al. (2021) Tasse, C., Shimwell, T., Hardcastle, M. J., et al. 2021, A&A, 648, A1
  * Thompson et al. (2017) Thompson, A. R., Moran, J. M., & Swenson, George W., J. 2017, Interferometry and Synthesis in Radio Astronomy, 3rd Edition (Springer, https://link.springer.com/book/10.1007/978-3-319-44431-4)
  * van Weeren et al. (2016) van Weeren, R. J., Brunetti, G., Brüggen, M., et al. 2016, ApJ, 818, 204

##  Appendix A Abbreviations and symbols

$A12$ | ‘true’ amplitude on baseline between antennas 1, 2 (etc.)
---|---
$A_{\mathrm{eff}}$ | Effective antenna diameter
$A_{\epsilon,\mathrm{baseline}}$ | amplitude error on a single baseline
$A_{\epsilon 1}$ | amplitude error on antenna 1 (etc.)
ACA | Atacama Compact Array
ALMA | Atacama Large Millimetre and sub-millimetre Array
AVC | Automatic Voltage Correction (measure of source contribution to $T_{\mathrm{sys}}$)
$B$ | baseline length
$B_{1/2}$ | baseline length where visibility amplitude is at half maximum power due to errors
$B_{\mathrm{max}}$ | maximum baseline length
$B_{\mathrm{min}}$ | minimum baseline length
$C$ | multiplier for noise-based position errors for sparse $uv$ coverage
CC | Clean Components
$D_{\mathrm{antenna}A}$ | dynamic range limitation due to single antenna amp error
$D_{\mathrm{antenna}\phi}$ | dynamic range limitation due to single antenna phase error
$D_{\mathrm{baseline}A}$ | dynamic range limitation due to single baseline amp error
$D_{\mathrm{baseline}\phi}$ | dynamic range limitation due to single baseline phase error
$D_{\operatorname{all-antenna}A}$ | dynamic range limitation due to same all-antenna amp error
$D_{\operatorname{all-antenna}\phi}$ | dynamic range limitation due to same all-antenna phase error
$D_{\operatorname{all-baseline}A}$ | dynamic range limitation due to random all-baseline amp errors
$D_{\operatorname{all-baseline}\phi}$ | dynamic range limitation due to random all-baseline phase errors
DGC | Diff Gain Cal
$\mathbf{E}$ | ‘Electric’ Antenna voltage pattern including PB response (as used in Measurement Equation)
FDM | Frequency Domain Multiplexing
FWHM | Full Width Half Maximum
$\boldsymbol{I}$ | Sky brightness distribution (as used in Measurement Equation)
$\mathbf{J}$ | Collective errors affecting recorded visibility (as used in Measurement Equation)
$\mathbf{G}$ | Gain errors (non-direction-dependent, as used in Measurement Equation)
$g$ | factor to convert from Jy to Kelvin (inverse of ALMA SEFD)
$K$ | Kolmogorov coefficient
$k$ | coefficient for Jy/Kelvin, efficiency etc. in conversion from $T_{\mathrm{sys}}$ to image noise
$lm$ | Image plane coordinates in formalism such as Measurement Equation
$M$ | number of intervals of independent tropospheric effects
$\mathbf{M}$ | Baseline-dependent errors (as used in Measurement Equation)
MFS | Multi Frequency Synthesis (often, the special case of fitting a spectral index in imaging)
MS | Measurement Set
$N$ | number of antennas
$N_{\mathrm{indep}}$ | number of independent antennas
$N_{\mathrm{pol}}$ | number of polarisations
$P$ | Peak flux density
$\mathbf{P}$ | Parallactic angle rotation (as used in Measurement Equation)
PB | Primary Beam
PWV | Precipitable Water Vapour
QA0 | ALMA Quality Assurance immediately after observations
QA2 | ALMA Quality Assurance for calibration and imaging
QSO | Quasi Stellar Object
SEFD | System Equivalent Flux Density, system temperature conversion factor666ALMA usage, see Appendix D.2 K Jy-1
$S_{0}$ | flux density at frequency 0 (etc.)
$S_{\mathrm{app}}$ | apparent target flux density
$S_{\mathrm{tar}}$ | target flux density
S/N | Signal to Noise ratio (usually, $P/\sigma_{\mathrm{rms}}$ of image)
S/Nsc | Signal to Noise ratio required for self-calibration
spw | spectral window
TDM | Time Domain Multiplexing
TEC | Total Electron Content of ionosphere
$\mathbf{T}$ | Gain errors (direction-dependent as used in Measurement Equation)
$T_{\mathrm{Rx}}$ | receiver temperature
$T_{\mathrm{sky}}$ | sky temperature
$T_{\mathrm{sys}}$ | system temperature
$uv$ | visibility plane coordinates
$V$ | complex visibility
$V_{0}$ | amplitude
$\boldsymbol{V}$ | Complex visibility (matrix form as used in Measurement Equation)
$V_{\mathrm{LSR}}$ | velocity with respect to the Local Standard of Rest (aka LSRK)
VLBI | Very Long Baseline Interferometry
WVR | Water Vapour Radiometry
$\alpha$ | spectral index
$\alpha_{\mathrm{K}}$ | Kolmogorov exponent
$\Delta\mathrm{TEC}$ | difference in TEC above each antenna in a baseline
$\Delta\nu$ | useful bandwidth (excluding gaps/deselected ranges)
$\Delta t$ | time on source (excluding gaps)
$\Delta_{\mathrm{pcal-tar}}$ | phase calibrator – target angular separation
$\delta\nu$ | useful frequency interval per solution
$\delta\nu_{\mathrm{spw}}$ | line-free continuum bandwidth per spw
$\delta t$ | solution interval
$\delta t_{0}$ | minimum solution interval for required S/N
$\delta\phi$ | magnitude of rapid phase fluctuation
$\theta_{\mathrm{B}}$ | synthesised beam (FWHM)
$\lambda$ | wavelength
$\nu$ | frequency
$\nu_{0}$ | frequency of measurement 0 (etc.)
$\phi$ | phase
$\phi 12$ | ‘true’ phase on baseline between antennas 1, 2 (etc.)
$\phi_{\epsilon 1/2}$ | phase error for $B_{1/2}$
$\phi_{\epsilon,\mathrm{short}}$ | phase error due to rapid fluctuations
$\phi_{\epsilon,\mathrm{angsep}}$ | target phase error due to target-phase calibrator angular separation
$\phi_{\epsilon,\mathrm{transfer}}$ | total error in applying phase calibrator solutions to target
$\phi_{\epsilon,\mathrm{baseline}}$ | phase error on a single baseline
$\phi_{\epsilon,\mathrm{target,ant}}$ | total error in phases for each antenna
$\phi_{\epsilon,\mathrm{target}}$ | phase error for whole target data set
$\phi_{\epsilon,\mathrm{time}}$ | target phase error due to time separation between target and phase calibrator scans
$\phi_{\epsilon,\mathrm{antpos}}$ | target phase error due to antenna position error
$\phi_{\epsilon,\mathrm{ion}}$ | phase error due to ionosphere
$\phi_{\epsilon,\mathrm{trop}}$ | phase error due to tropospheric refraction
$\phi_{\epsilon 1}$ | phase error on antenna 1 (etc.)
$\phi_{\mathrm{rms\mu}}$ | tropospheric effective path length fluctuation
$\phi_{\mathrm{rms}}$ | phase noise
$d\phi_{\mathrm{atm/min}}$ | phase change per minute
$\sigma_{\mathrm{posTarget}}$ | target astrometric uncertainty due to phase calibrator solution transfer errors
$\sigma_{\mathrm{posfit}}$ | relative position uncertainty of fitted 2D Gaussian due to noise
$\sigma_{\phi\mathrm{rate,antpos}}$ | phase error rate due to antenna position error
$\sigma_{\mathrm{antpos}}$ | antenna position uncertainty
$\sigma_{\mathrm{rms}}$ | image noise
$\sigma_{\mathrm{solint,ant}}$ | rms noise per antenna in solution interval
$\sigma_{\mathrm{solint,baseline}}$ | rms noise per baseline in solution interval
$\tau_{\mathrm{scan}}$ | Length of a scan (interval between source changes)

Many of the concepts behind these terms are explained more in the Technical
Handbook ALMA-TH.

##  Appendix B Online resources

###  B.1 Schools and workshops

Schools focusing on Self-Calibration These provide an introduction to the CASA
tasks and links to the VY CMa data and scripts used for examples in this
manual:

  * Self-calibration and advanced imaging, Bologna 2017
http://www.alma.inaf.it/index.php/Self-
calibration_and_advanced_imaging_workshop

  * I-TRAIN 6: Improving image fidelity through self-calibration
https://almascience.eso.org/euarcdata/itrain06/.

NRAO Synthesis Imaging summer schools

  * Synthesis Imaging in Radio Astronomy II, the 1998 proceedings (SI99) are online at
https://www.aspbooks.org/a/volumes/table_of_contents/?book_id=292
http://www.phys.unm.edu/~gbtaylor/astr423/s98book.pdf

  * Material from the 2017 school is available at
https://science.nrao.edu/science/meetings/2018/16th-synthesis-imaging-workshop
including Error Recognition
https://science.nrao.edu/science/meetings/2018/16th-synthesis-imaging-
workshop/talks/Taylor_Error_Recognition.pdf and see also Brogan et al. (2018).

ERIS and DARA ERIS (European Radio Interferometry Schools) and DARA
(Development in Africa with Radio Astronomy) have much online material
including on self-calibration, including data sets and step by step guides
aimed at beginners. DARA covers e-MERLIN and (simple) VLBI data reduction and
self-calibration as well as preparation for the AVN; ERIS also covers some
ALMA examples.

  * ERIS 2019
https://www.chalmers.se/en/researchinfrastructure/oso/events/ERIS2019
including T7 Self-calibration (e-MERLIN continuum, suitable for CASA 5) at:
https://www.chalmers.se/en/researchinfrastructure/oso/events/ERIS2019/Pages/Software-
packages-and-datasets.aspx
From 2022 onwards, ERIS will be run by ORP (https://www.orp-h2020.eu).

  * DARA 2021
Workshops for tutorials, as of 2021 in CASA 6, at:
http://www.jb.man.ac.uk/DARA/unit4/unit4.html
EVN continuum covers all stages including self-calibration for a basic VLBI
data set. Spectral Line covers processing target data after applying phase
calibrator etc. corrections, including self-calibration. 3C277.1 is the CASA 6
equivalent of the ERIS 2019 data.

Other schools and resources for other arrays
VLBI

  * VLBI calibration is described in more detail at the 2020 CASA-VLBI Workshop
https://www.jive.eu/casa-vlbi2020/

  * Other links are provided from
https://casaguides.nrao.edu/index.php?title=VLBI_Tutorials

Wide-field/low frequency guidance can be found in the VLA P-band CASA guides
(although not covering self-calibration); for LOFAR see

  * LOFAR data reduction
https://support.astron.nl/LOFARImagingCookbook/ Ch. 20.

NOEMA data reduction including self-calibration (in GILDAS)

  * 2018 IRAM Summer School
https://www.iram-institute.org/EN/content-page-399-7-67-367-399-0.html (and
see IRAM pages for future events).

###  B.2 CASA Guides

It is worth browsing https://casaguides.nrao.edu/ to check for recent versions
and additions; these are just some current examples:

  * A basic guide to parameter settings for ALMA is provided by the CASA introduction to self-calibration
https://casaguides.nrao.edu/index.php?title=First_Look_at_Self_Calibration.

  * VLA self-calibration guide
https://casaguides.nrao.edu/index.php?title=VLA_Self-calibration_Tutorial-
CASA6.2.0

  * For Solar data reduction, see the CASA Guide for sunspots
https://casaguides.nrao.edu/index.php?title=Sunspot_Band6 and for self-
calibration see Nindos et al. (2018).

  * Data weighting
https://casaguides.nrao.edu/index.php?title=DataWeightsAndCombination

  * Reimaging pipelined ALMA data by modifying pipeline commands
https://casaguides.nrao.edu/index.php?title=ALMA_Imaging_Pipeline_Reprocessing).

  * Flagging (at cm wavelengths)
https://casaguides.nrao.edu/index.php?title=VLA_CASA_Flagging-CASA6.2.0.

  * Analysis Utilities
https://casaguides.nrao.edu/index.php?title=Analysis_Utilities

  * Combining arrays
https://casaguides.nrao.edu/index.php?title=M100_Band3

###  B.3 CASA Documentation

Help (task) provides inline help but more details are available from CASA
documentation https://casadocs.readthedocs.io/en/stable/index.html. The most
relevant here are

  * tclean
https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.tclean.html

  * gaincal
https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.gaincal.html

  * applycal
https://casadocs.readthedocs.io/en/stable/api/tt/casatasks.calibration.applycal.html

(also see below Appendices C.1 and C.2

###  B.4 Sensitivity calculators

  * ALMA https://almascience.eso.org/proposing/sensitivity-calculator (also built in to the Observing Tool)

  * VLBI (including EVN, VLBA and global VLBI) https://www.evlbi.org/capabilities

  * GMVA (3mm VLBI) https://www3.mpifr-bonn.mpg.de/div/vlbi/globalmm/sensi.html

  * e-MERLIN http://www.e-merlin.ac.uk/calc.html

  * VLA https://obs.vla.nrao.edu/ect/

###  B.5 Other resources

  * NRAO Template script for ALMA imaging and self-calibration https://github.com/aakepley/ALMAImagingScript/blob/master/scriptForImaging_template.py

  * NRAO Science ready data products provided on request for selected ALMA and VLA observations, including restored ALMA pipeline calibrated MS https://science.nrao.edu/srdp

  * Atmospheric model http://www.apex-telescope.org/sites/chajnantor/atmosphere/transpwv/index_ns.php This plots transmission as a function of frequency for selected PWV using the ATM libraries, Pardo (2019) for the APEX site (which is very similar to ALMA). At present this is only available specifically for ALMA inside CASA, via Analysis Utilities as https://safe.nrao.edu/wiki/bin/view/ALMA/PlotAtmosphere (see Appendix B.2 and https://help.almascience.org/kb/articles/how-can-i-plot-the-atmospheric-transmission-opacity-or-sky-temperature-for-alma). It may be restored to the ALMA Science Portal in time. The transmission for a specific MS can be overplotted in plotms.

  * Clouds Scaling the WVR-derived correction in the presence of clouds: Remcloud https://help.almascience.org/kb/articles/what-is-remcloud-and-how-could-it-reduce-phase-rms

  * Spectral contribution to $T_{\mathrm{sys}}$ Checking for flux scale errors due to large scale spectral flux contribution to $T_{\mathrm{sys}}$
https://help.almascience.org/kb/articles/what-are-the-amplitude-calibration-
issues-caused-by-alma-s-normalization-strategy. As of 2021, ALMA procedures
were being updated and this correction may already have been included so check
whether it is needed for observations processed more recently.

##  Appendix C Guidance for self-calibration parameters in gaincal and
applycal

###  C.1 gaincal

More details to guide the use of gaincal, see Sec. 4.4 and the full CASA
documentation, Appendix B.3. The comments here are applicable for phase and
for amplitude self-calibration unless otherwise stated.

vis, field

Input MS and target

caltable

Output calibration table. Normally, delete any previous table of the same name
and close any plotting window displaying it.

spw

This selection should contain only channels where all the emission should be
described by the model. For example, you can make a continuum image model from
a channel selection for one spw and select the continuum channels of another
spw near in frequency (e.g. in the same EB) but do not use a continuum model
to derive solutions for line channels with different structure or flux density
(although you can apply the continuum solutions to these).

selectdata

has various sub-parameters occasionally needed if part of the data are used to