\label{sec:mosaic}

We are often asked why the wide-field imaging and deconvolution steps are
more difficult than their equivalent for single-field. The main answer is
that doing wide-field observations with an interferometer is kind of
paradoxical. Indeed, (sub)millimeter interferometers are before all tuned
to get the best possible spatial resolution. A natural consequence is the
lack of measurement of the low spatial frequencies which are extremely
important in wide-field observations. Hence the paradox.  

Progress in the design (\ALMA{} was designed with wide-field imaging as a 
main goal) or in performances (\NOEMA{} and the 30-m) has led to 
wide-field images being now customary.  The tools have become much 
simpler and user-friendly (see below !) but because of its paradoxical 
nature, wide-field imaging with an interferometer implies a 
knowledgeable use of those tools.

\subsection{In a nutshell}

\begin{verbatim}
  1  read uv gag_demo:demo-mosaic-imager.uvt
 (2)  read single gag_demo:demo-single-imager.tab
 (3)  uv_short
 (4)  mosaic
  5  uv_map
  6  clean
 (7) fit /jvm;  uv_restore
  8  show sky
  9  write * MyDemo
\end{verbatim}
\begin{enumerate}\itemsep 0pt
\item Read your \uv{} data
\item Optionally, read your single-dish data
\item Optionally, merge it with with the \uv{} data set,
by using the single-dish data to provide short spacings
for the interferometer data.
\item Optionally, switch to a different Mosaic method (see \ref{sec:sub:sault})
\item Image as usual
\item deconvolve as usual
\item Optionally, improve result by refining the residuals
\item look at it
\item Save the result.
\end{enumerate}
You are done. If the \uv{} data set is a \textbf{Mosaic} data set,
it works as if it is a single-field, except that the result appears
as the \sicvar{SKY} brightness distribution, because it is
always corrected for primary beams.

Now, if the result is crazy, do not blame the software. Rather read 
carefully the information below: \textbf{Mosaics} and \com{UV\_SHORT} 
are simple to use, but can be tricky to use well !...

\subsection{General considerations about wide-field imaging}

The measurement equation for a millimeter interferometer is to a good
approximation (after calibration)
\begin{latexonly}
  $$ {V(u,v) = FT(B_\mathrm{primary}.I_\mathrm{source})(u,v) + N} $$
\end{latexonly}
\begin{rawhtml}
  $$ {V(u,v) = FT(B_\mathrm{primary}.I_\mathrm{source})(u,v) + N} $$
\end{rawhtml}
where $FT(F)(f)$ is the bi-dimensional Fourier transform of
the function $F$ taken at the spatial frequency $f$, $I_\mathrm{source}$ the
sky intensity, $B_\mathrm{primary}$ the primary beam of the interferometer
(\ie\ a Gaussian of FWHM the natural resolution of the single-dish antenna
composing the interferometer), $N$ some thermal noise and $V(u,v)$ the
calibrated visibility at the spatial frequency $(u,v)$. The product of the
sky intensity by the primary beam, which ``quickly'' decreases to zero,
implies that an interferometer looking at a particular direction of the sky
will have its field-of-view limited by the size of the primary beam.
 
To image a field-of-view larger than the primary beam size, the antennae of
an interferometer will be successively pointed in different directions of
the sky typically separated by half the size of the primary beam. This
process is called mosaicing and the result requires specific imaging and
deconvolution steps. Another possibility is to acquire data as the
interferometer antenna continuously slew through a portion of the sky. This
second observing mode is called interferometric On-The-Fly (OTF). While
mosaicing is standard at \NOEMA{} (see section~\ref{sec:mosaicing}), some
efforts are currently done to commission the OTF observing mode.

Mosaicing and OTF clearly belongs to wide-field imaging. However
considerations about wide-field imaging start as soon as the size of the
source is larger than about 1/3 to 1/2 of the interferometer primary beam.
Indeed, a multiplicative interferometer (\eg\ all interferometer in the
(sub)mm range) is a bandpass instrument, \ie\ it filters not only the large
spatial frequencies (this is the effect of the finite resolution of the
instrument) but also the small spatial frequencies (all the frequencies
smaller than typically the diameter of the interferometer antennas). An
important consequence is that a multiplicative interferometer do \emph{not}
measure the total flux of the observed source. This derives immediately
from the following property of the Fourier Transform: The Fourier transform
of a function evaluated at zero spatial frequency is equal to the integral
of your function. Adapting this to our notation, this gives
\begin{latexonly}
$$  V(u=0,v=0) \stackrel{\mbox{FT}}{\rightleftharpoons} \sum_{ij~\in~\mathrm{image}} \cbrace{B_\mathrm{primary}.I_\mathrm{source}}_{ij}. $$
\end{latexonly}
\begin{rawhtml}
$$  V(u=0,v=0) \stackrel{\mbox{FT}}{\rightleftharpoons} \sum_{ij~\in~\mathrm{image}} \left({B_\mathrm{primary}.I_\mathrm{source}}_{ij}\right). $$
\end{rawhtml}
\ie\ the visibility at the center of the \uv{} plane is the total intensity
of the source. As a multiplicative interferometer filters out in particular
\mymath{V(u=0,v=0)}, the information about the total flux of the observed source
is lost. In summary, a multiplicative interferometer only gives information
about the way the flux of the source is distributed in the spatial
frequencies larger than the primary beam but no information about the total
flux.

Deconvolution algorithms use, in one way or another, the information of the
flux at the smallest \textbf{measured} spatial frequencies to extrapolate the
total flux of the source. This works correctly when the size of the source
is small compared to the primary beam of the interferometer. The extreme
case is a point source at the phase center for which the amplitude of all
the visibilities is constant and equal to the total flux of the source:
Extrapolation is then exact. However, the larger the size of the source,
the worst the extrapolation, which then underestimates the total source
flux. This is the well-known problem of the missing flux that observers
sometimes note when comparing the flux of the source delivered by a mm
interferometer with the flux observed with a single-dish antenna. The
transition between right and wrong extrapolation is not well documented. It
depends on the repartition of the flux with spatial frequencies but also of
the signal-to-noise ratio of the measured spatial frequencies. It is often
agreed that the transition happens for sizes between 1/3 and 1/2 of the
interferometer primary beam. For larger source size, information from a
single-dish telescope is needed to fill in the missing information and to
thus obtain a correct result. This is the object of
section~\ref{sec:short-spacings}.

\subsection{Mosaicing}
\label{sec:mosaicing}

\subsubsection{Observations and processing}

In a single-field observation, an interferometer tracks a particular
direction of the sky, named the phase center. The portion of the sky which
can be image around this direction is directly linked to the size of the
primary beam. The easiest way to image field-of-view larger than the
primary beam size is to track one direction of the sky after another until
the desired field-of-view is filled with small images made around many
different tracking directions. This observing mode is called mosaicing and
the tracked observations which constitute the mosaic are called fields.

There are many constraints to optimize mosaicing.
\begin{description}
\item[Nyquist sampling of the mosaic field-of-view and mosaic pattern] The
  mosaic field-of-view must at least be Nyquist-sampled to obtain a
  reliable image. Each observed field can produce a reliable image of the
  same shape than the primary beam, \ie\ a circular Gaussian (This assumes
  that the short-spacing problem has been solved). Nyquist sampling thus
  implies that the mosaic fields follow an hexagonal compact pattern as
  this ensures a distance between all neighboring fields of half the
  primary beam size. When the total observing time is fixed, Nyquist
  sampling is the best compromise between sensitivity and total
  field-of-view. Indeed, the distance between neighboring fields could be
  less (in which case the mosaic would be oversampled) than half the
  primary beam size. In this case, the sensitivity on each pixel of the
  final image would increase with the share of the time spent to observe
  this direction.
\item[Uniform imaging properties and quick loop around the fields] Getting
  uniform imaging properties is a desirable feature in the final result.
  This implies that a \uv{} coverage and a noise level as uniform as
  possible among the different fields. Quickly looping around the different
  fields is the easiest way to reach this goal. However, dead time to
  travel from one field to another must also be minimized. At NOEMA,
  the compromise is to pause at least 1 minute on each field and to try to
  loop over all the fields between two calibrations every 20 minutes.
  Hence, mosaic done in a single observing run is made of at most 20
  fields.  Larger mosaic must be observed by group of fields in different
  observing runs.
\end{description}

\subsubsection{Imaging}

When combining together (dirty or clean) images, it is important to correct
the primary beam attenuation to avoid modulation of the signal in the
combined image. If we forget for the moment the dirty beam convolution, the
images associated to each field are noisy measurements of the same quantity
(the sky brightness distribution) weighted by the primary beam. The best
estimation of the measured quantity is thus given by the least mean square
formula
\begin{latexonly}
\begin{equation}
  \label{eq:mosaic:signal}
    M(\alpha,\delta) = \frac{\displaystyle\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}\,F_i(\alpha,\delta)}
      {\displaystyle\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}},
\end{equation}
\end{latexonly}
\begin{rawhtml}
 $$   M(\alpha,\delta) = \frac{\displaystyle\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}\,F_i(\alpha,\delta)}
      {\displaystyle\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}},
 $$
\end{rawhtml}
where $M(\alpha,\delta)$ is the brightness of the dirty/cleaned mosaic
image in the direction $(\alpha,\delta)$, $B_i$ are the response functions
of the primary antenna beams in the tracking direction of field $i$, $F_i$
are the brightness distributions of the individual dirty/cleaned maps, and
$\sigma_i$ are the corresponding noise values. As may be seen on this
equation, the intensity distribution of the mosaic is corrected for primary
beam attenuation. This implies that noise is inhomogeneous. Indeed, if
$N(\alpha,\delta)$ is the noise distribution and $\sigma(\alpha,\beta)$ is
its standard deviation in the direction $(\alpha,\beta)$, we have
\begin{latexonly}
\begin{equation}
  \label{eq:mosaic:noise}
    N(\alpha,\delta) = \frac{\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}\,N_i(\alpha,\delta)}
      {\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}},
\end{equation}
\end{latexonly}
\begin{rawhtml}
$$    N(\alpha,\delta) = \frac{\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}\,N_i(\alpha,\delta)}
      {\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}} $$
\end{rawhtml}
and
\begin{latexonly}
\begin{equation}
  \label{eq:mosaic:sigma}
    \sigma(\alpha,\delta) = %
    \frac{\sqrt{\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}}}
    {\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}} = %
    \frac{1}{\sqrt{\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}}} %
    \simeq \frac{\sigma} {\sqrt{\sum\nolimits_i B_i(\alpha,\delta)^2}}
\end{equation}
\end{latexonly}
\begin{rawhtml}
$$ \sigma(\alpha,\delta) = 
    \frac{\sqrt{\sum\nolimits_i \frac{B_i(\alpha,\delta)}{\sigma_i^2}}}
    {\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}} = 
    \frac{1}{\sqrt{\sum\nolimits_i \frac{B_i(\alpha,\delta)^2}{\sigma_i^2}}} 
    \simeq \frac{\sigma} {\sqrt{\sum\nolimits_i B_i(\alpha,\delta)^2}}
$$
\end{rawhtml}

with the approximate formula assuming nearly equal noises $\sigma_i \approx \sigma$.
Thus, the noise strongly increases near the edges of the mosaic
field-of-view, but is also non-uniform in the central regions, especially
if the pointings are not sufficiently packed. 

To limit this, it is possible to truncate the primary beams (preferably
by tapering  them by a continuous function to avoid sharp edge effects). 
A better approach is to limit the deconvolved region in the deconvolution
step.

\subsubsection{Deconvolution}

Standard \clean{} algorithms must be slightly modified to work on a dirty
mosaics. Indeed, the use of truncated primary beam in the above equations
is only a first order measure to avoid noise artifacts. However, the noise
level still increases at the edges of the mosaic, implying that at some
point the \clean{} algorithms will confuse noise peaks at the mosaic edges
with true signal. To avoid this, the iterative search is made on a
signal-to-noise image $M(\alpha,\beta)/\sigma(\alpha,\beta)$ instead of the
residual image. At the restoration step, the clean component list is used
to produce the residual map and clean map. Nothing particular is done with
the remaining signal-to-noise image.

\subsubsection{Typical use}

The processing of mosaics for \NOEMA{} is essentially similar to that
of single fields. There are only two small changes
\begin{description}\itemsep 0pt
\item[Creation of \uv{} table]  For \NOEMA{} data, a mosaic UV table 
should be created using the \qom{/MOSAIC} option of command 
\qom{TABLE} in \clic{}.  For \ALMA{} data, this is implicitely
handled by the FITS to UVT conversion.  In case UV data files
come by separate pointings, \com{UV\_MOSAIC} can consolidate them
into a single UV table.
\item[Imaging] is done through \com{UV\_MAP} as for a single field.
However, the process is different. The command takes into account
the various fields, the primary beams, and select an optimum projection
center (phase center). The later may need to be specified by the user
using the \sicvar{MAP\_CENTER} string, or as argument to \com{UV\_MAP},
of, for the \texttt{SAULT} method, by command \com{MOSAIC}.
\item[Deconvolution] is also similar, but not all algorithms are
available: \qom{MX, SDI} and \qom{MRC} do not work for mosaics.
The change of behavior of the \clean{} algorithms is visualized
through the change of prompt from \texttt{IMAGER>} to \texttt{MOSAIC>}.
\end{description}

Compared to single-dish, a few additional variables are used to control
mosaic creation and deconvolution. These are handled through a number
of \sicvar{MOSAIC\_...} variables
\begin{description}\itemsep 0pt
\item[\sicvar{MOSAIC\_BEAM}] The truncation level of primary beams
when doing the individual field combination, in fraction of peak, so
in range[0,1].
\item[\sicvar{MOSAIC\_FIELD}] The map size around individual pointings
in the \texttt{SAULT} method, in numbers of FWHP. A typical value
of 4 is often appropriate. Very high dynamic range mosaics may 
require somewhat larger values. Limited S/N mosaics can accomodate
smaller values, though probably not less than 2.
\item[\sicvar{MOSAIC\_GUARD}] The guard band size beyond the
mosaic region, in numbers of FWHP. The default value
of 2.5 is in general appropriate. However, mosaics with confusing
sources near the edge may require a larger fraction of a primary beam
\item[\sicvar{MOSAIC\_SEARCH}] The minimum fraction of a primary beam
below which no Clean component is searched for. A default value of 0.2
is often appropriate.
\item[\sicvar{MOSAIC\_TRUNCATE}] The minimum fraction of a primary beam
cumulated response below which no image restoration is performed. 
Below this threshold, the Clean image is blanked. A default value of
0.2 means the noise is 5 times larger at the edge than at center...
\end{description}
The first 3 variables above apply to the map making process (\qom{UV\_MAP}
and \qom{UV\_RESTORE}) while the last 2 apply to the deconvolution (\qom{CLEAN}).
In addition, there are 2 information variables: the logical \sicvar{MOSAIC\_ACTIVE}  
indicates if Mosaicing is active, and the character string \sicvar{MOSAIC\_MODE}  
indicates the Mosaic method (\texttt{NONE, GUETH} or \texttt{SAULT}).

Finally, note that the mosaic deconvolution produces sky brightness
images (\sicvar{SKY} variable) while single-field deconvolution 
produces images attenuated by the primary beam.
\imager{} makes no specific assumption about the \uv{} coverage
of individual fields. However, it uses a single Clean beam
in the deconvolution, so Mosaics where fields have widely different
\uv{} coverage may not conserve flux properly.  
Mosaicing deconvolution will work better
if all fields are equivalent in \uv{} coverage and noise level.

%\footnote{IS THAT TRUE ? : An additional subtlety of the current \imager{} implementation of
%mosaicing is that \mapping{} assumes that the individual fields of the
%mosaic have similar noise level.}

A mosaicing session would thus just be like a single-field
imaging:
\begin{verbatim}
       1 read uv gag_demo:demo-mosaic 
      (2) mosaic [args ...]
       3 uv_map
       4 hogbom /flux 0 10
       5 fit /jvm
       6 uv_restore
       7 show sky
       8 write * demo
\end{verbatim}
Comments:
\begin{description}\itemsep 0pt
\item[Step 1] Read the UV table
\item[optional Step 2] Turn to the \texttt{SAULT} method
\item[Step 3] Image the mosaic
\item[Step 4] Deconvolve
\item[Step 5-6] Optimize residuals (see Sec.\ref{sec:sub:jvm})
\item[Step 7] Look at the result. The result is in  \sicvar{SKY}.
\item[Step 8] Save the result \sicvar{SKY}, and the intermediate files (\sicvar{BEAM, DIRTY, PRIMARY}).
\end{description}

However, mosaics can be huge and require more memory than available (see Section \ref{sec:huge}).
To overcome this issue, \imager{}  provides
the script \script{@ image-mosaic}\footnote{Jan-2023: No provision for \texttt{SAULT} method 
yet in this script. Take it as a template and modify to your needs.} that splits the 
\qom{UV\_MAP} step into slices that fit into memory.
The user can then read the resulting images and deconvolve them, eventually by blocks of channels
if needed (in particular when a \qom{uv\_restore} step is desired) using a similar logic.

\subsection{Large Mosaics: the \texttt{SAULT} method}
\label{sec:sub:sault}
The default Mosaic processing uses the \texttt{GUETH} method described in \cite{gueth95}. The processing
involves imaging each field on the same grid as the full mosaic. This has two drawbacks for large
mosaics: 1) it requires lot of memory 2) beam smearing effect at edges may become significant.

To circumvent this, one can use the \texttt{SAULT} method (\cite{sault96}), where only a limited area is imaged
around each field, with a phase center near the pointing direction, and a correction to handle
the proper common projection center. They are then added at the appropriate place to the larger Mosaic. 
This method limits beam-smearing effects to those of a single field. The method is faster and uses less memory
than the \texttt{GUETH} method for mosaics larger than about 16 fields.

In \imager{}, this mode can be activated by using command \com{MOSAIC}. It applies to
the \qom{UV\_MAP} and \qom{UV\_RESTORE} commands. Deconvolution is identical in both 
methods.\footnote{Currently, the dirty and primary beams are expanded to the Sky mosaic size
at the end of the \texttt{SAULT} method, thus limiting the gain that could also occur during
the deconvolution. In principle, this is not needed at all for the dirty beams, as \com{CLEAN}
can handle different Dirty Beam and Map sizes. For Primary beams, it would require 
carrying on the pixel shifts between the Primary beams and the Sky map size.}

\subsection{Mosaic and JvM factor}
\label{sec:sub:jvm}

By construction, the various fields covered in a mosaic have different $uv$ coverages, and thus different
synthesized beams. Furthermore, mosaic covers wider fields, so the impact of frequency variable angular
resolution is more important than in single fields.  

Yet, the mosaic is restored with a unique Clean beam. This situation leads to a mismatch between the used Clean
beam and the dirty beams in some or even most of the fields. 
Furthermore, because Mosaics often use short spacings
(see Section \ref{sec:short-spacings}), the dirty beams often present a wide ``plateau'' that is not well 
fit by a Gaussian
Clean beam.  These are situations which are prone to lead to inaccurate large scale flux restoration, because
the Clean beam and dirty beams area do not match. 

To minimize these issues, it is recommended in \imager{} to use the \comm{FIT}{/JVM\_FACTOR} and \com{UV\_RESTORE}
commands that correct this mismatch to first order by re-scaling the residual by the Clean to Dirty beam ratio, 
the so-called \sicvar{JvM factor} (\cite{jvm1995}). Only do so once you are satisfied with your deconvolution, as \com{UV\_RESTORE}
is often time consuming on Mosaics.

\subsection{Tiny (or degenerate) Mosaics}
\label{sec:sub:tiny-mos}

It may happen, with \ALMA{} or \NOEMA{}, that some data set result in ``tiny'' mosaics,
where the pointing centers, though different, are very close to each other. This
may occur because the specified coordinates changed during the observing sessions,
by accident (a typo) or intentionally, for example when observing moving objects. 

\imager{} will ignore these pointing differences if the position spread is smaller
than \sicvar{MOSAIC\_TOLERANCE} (in arcseconds). In this case, despite the number
of pointings, \com{UV\_MAP} will proceed as for a single field. \textbf{However, proper handling
of the \textbf{phase centers} in this case depends on the reason why the
coordinates were changed. This may require a conscious user action to
preserve the imaging accuracy.} See Sect.\ref{sub:specific:moving} for details. 

\subsection{Mosaic and Self-Calibration}

\textbf{Self-Calibration works on Mosaic too, in exactly the same way as for
single fields.}

However, because of time sharing between the various
pointings in a Mosaic, the signal to noise is in general lower than
on single fields, so that the improvements are smaller.  It may 
happen that some fields may have little signal, and cannot be self-calibrated.
However, these fields are not dynamic range limited, so will not limit
the final result. Accordingly, the best
practice to improve a Mosaic through self-calibration is to avoid
flagging data that cannot be self-calibrated, by setting 
\sicvar{SELF\_FLAG} to \sicvar{NO}.

Self-calibration of Mosaics may need more careful adjustment of the
integration time, \sicvar{SELF\_TIMES}.

\subsection{Hybrid Mosaics}
As of version 4.6-03, \imager{} supports hybrid mosaics, i.e. mosaics 
made with different telescopes. Mosaic "fields" are then identified not 
only based on the pointing center, but also on the telescope 
identification. It does not support hybrid baselines, however.  

This feature allows for example to deconvolve simultaneously ALMA and 
ACA data, or to merge NOEMA and ALMA data although they have different 
primary beams. 

\textbf{This capability is experimental.} The reason for this is that, 
although the principle is the same as for usual mosaics, the $uv$ 
coverage will differ substantially between fields. The definition of a 
synthesized beam is thus more ambigous, and may lead to a mismatch in 
the apparent unit of the residuals compared to the Clean components. 
The use of the \comm{fit}{/jvm} command is thus recommended in this 
case. Careful experiment with different synthesized beams and weighting 
may be needed to obtain a proper result. 

Hybrid mosaics $uv$ tables can be created from the individual $uv$ 
tables of the fields using the \com{UV\_MOSAIC} command as usual. There 
is no automatic spectral resampling. The user must take care about the 
spectral matching of the data, using commands \qom{UV\_RESAMPLE} for 
spectra line data, or \qom{UV\_CONTINUUM} to match the reference 
frequency if needed






