%-----------------------------------------------------------------------
%;  Copyright (C) 2002
%;  Associated Universities, Inc. Washington DC, USA.
%;
%;  This program is free software; you can redistribute it and/or
%;  modify it under the terms of the GNU General Public License as
%;  published by the Free Software Foundation; either version 2 of
%;  the License, or (at your option) any later version.
%;
%;  This program is distributed in the hope that it will be useful,
%;  but WITHOUT ANY WARRANTY; without even the implied warranty of
%;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%;  GNU General Public License for more details.
%;
%;  You should have received a copy of the GNU General Public
%;  License along with this program; if not, write to the Free
%;  Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
%;  MA 02139, USA.
%;
%;  Correspondence concerning AIPS should be addressed as follows:
%;         Internet email: aipsmail@nrao.edu.
%;         Postal address: AIPS Project Office
%;                         National Radio Astronomy Observatory
%;                         520 Edgemont Road
%;                         Charlottesville, VA 22903-2475 USA
%-----------------------------------------------------------------------
\documentstyle[aaspp4,epsfig]{aastex}
%\documentstyle{article}
%
% probably don't need all these...
%
\newcommand{\AIPS}{{$\cal AIPS\/$}}
\newcommand{\POPS}{{$\cal POPS\/$}}
\newcommand{\KR}{{$\tt KRING$}}
\newcommand{\FR}{{$\tt FRING$}}
\newcommand{\ttaips}{{\tt AIPS}}
\newcommand{\AMark}{AIPSMark$^{(93)}$}
\newcommand{\AMarks}{AIPSMarks$^{(93)}$}
\newcommand{\LMark}{AIPSLoopMark$^{(93)}$}
\newcommand{\LMarks}{AIPSLoopMarks$^{(93)}$}
\newcommand{\AM}{A_m^{(93)}}
\newcommand{\ALM}{AL_m^{(93)}}
\newcommand{\eg}{{\it e.g.},}
\newcommand{\ie}{{\it i.e.},}
\newcommand{\daemon}{d\ae mon}
% \input psfig

\newcommand{\boxit}[3]{\vbox{\hrule height#1\hbox{\vrule width#1\kern#2%
\vbox{\kern#2{#3}\kern#2}\kern#2\vrule width#1}\hrule height#1}}
%
\newcommand{\memnum}{107}
\newcommand{\whatmem}{\AIPS\ Memo \memnum}
%\newcommand{\whatmem}{{\bf 99}}
\newcommand{\memtit}{{\tt KRING} versus {\tt FRING} Tests}
\title{
%   \hphantom{Hello World} \\
   \vskip -35pt
%   \fbox{AIPS Memo \memnum} \\
   \fbox{{\large\whatmem}} \\
   \vskip 28pt
   \memtit \\}
\author{ Amy J. Mioduszewski\\
National Radio Astronomy Observatory\\Socorro, NM, USA}

%
\parskip 4mm
\linewidth 6.5in                     % was 6.5
\textwidth 6.5in                     % text width excluding margin 6.5
\textheight 8.91 in                  % was 8.81
\marginparsep 0in
\oddsidemargin .25in                 % EWG from -.25
\evensidemargin -.25in
\topmargin -.5in
\headsep 0.25in
\headheight 0.25in
\parindent 0in
\newcommand{\normalstyle}{\baselineskip 4mm \parskip 2mm \normalsize}
\newcommand{\tablestyle}{\baselineskip 2mm \parskip 1mm \small }
%
%
\begin{document}

\begin{abstract}
This comparison was designed to discover whether \KR\ or \FR\ should
be used for most, if not all, fringe fitting problems.  Within reasonable
uncertainty, \FR\ and \KR\ performed very similarly.  There
is some indication that the default signal to noise cutoff in \KR\ is
too low for low signal to noise cases.  As one would expect, for high
flux density sources the solution
interval should be set as low as possible.  For low flux density sources
the solution interval should be set considering both the ability to find
a good solution and to interpolate accurately.  The only consistent
difference between \KR\ and \FR\ is that \KR\ runs faster than \FR\ a vast
majority of the time, typically by factors of 1.5 to 4.
\end{abstract}

\section{Method}

In order to compare {\tt KRING} and {\tt FRING} one needs to
create a dataset where the ``answer'' is known.  To do this I
used the following procedure:

\begin{enumerate}

\item Select a dataset and use {\tt SPLIT} to create a single
source data file.  In this case a 5~GHz data set was used.

\item Run task {\tt UVMOD} on this dataset to remove original data
and add point source or Gaussian with given flux density and size (for
Gaussian).  No noise is added at this time.

\item Run {\tt MULTI} to create multisource data set.  Copy a {\tt CL} table
from original data set which has all the fringe fit solutions from the
original data set applied, but does not contain any amplitude calibration.
The {\tt CL} table used here is shown in figure~\ref{snplt}\@.  Run {\tt SPLIT}
applying that {\tt CL} table.

\begin{figure}[t!]
\plotone{FIG/AIPSMEM107A.PS}
\caption{{\tt SNPLT} of phases for 1 IF  for the {\tt CL} table
applied to the simulated data to introduce known phase, rate and delay
errors.}
\label{snplt}
\end{figure}

\item Run {\tt UVMOD} again to add noise.

\item Run {\tt MULTI} again to provide \KR\ and \FR\ with a multisource
dataset.

\item Run \KR\ and \FR\ with similar input values.

\item Copy {\tt CL} table that was used in step~3 to data
set on which \KR\ and \FR\ were run. Run {\tt CLCAL} using this
{\tt CL} table as the {\tt GAINVER} and the {\tt SN} tables out of
\KR\ and \FR\ as the {\tt SNVER}.  If \KR\, \FR\ and
{\tt CLCAL} were perfect then the resulting {\tt CL} table will have
rates, delays and phases which are all zero.  Figure~\ref{snplt2} shows
the result of applying the {\tt SN} table from running \KR\ on a 250~mJy
point source to the {\tt CL} table shown in figure~\ref{snplt}\@.

\begin{figure}[t!]
\plotone{FIG/AIPSMEM107B.PS}
\caption{{\tt SNPLT} of phases for 1 IF of a {\tt CL} table
produced by applying the solutions from running \KR\ on a 250~mJy point
source to the original {\tt CL} table (shown in figure~\ref{snplt})\@.
As expected the solutions are near but not always exactly zero (except
for the reference antenna, whose phase is, by definition, zero).}
\label{snplt2}
\end{figure}

\item Repeat all these steps with various flux densities, and {\tt SOLINT}
values.

\item Histograms of the resulting phases, rates and delays are made.

\end{enumerate}

Of course, one weakness with this method of comparing
\KR\ and \FR\ is that {\tt CLCAL} does not always interpolate perfectly,
but this
should affect both \KR\ and \FR\ and therefore not hurt the comparison.

\section{Point sources}

Point sources with flux densities of 1~Jy, 500~mJy, 250~mJy, 175~mJy and
100~mJy were simulated.
All histograms, for all flux densities, and solution intervals show
a Gaussian distribution of residual phases centered at zero,
see figure~\ref{phase2}.  However, a slow but
steady degradation of the solutions is evident as the flux density of
the point source decreases.  This is seen in figure~\ref{phase2}
as the growth of the width of the distribution of residual phases and
the lowering of the peak.
Table~\ref{table} shows the percent of reported good solutions from \FR\ and
\KR; this shows a significant
change in the ability of both \FR\ and \KR\ to find
good solutions between 175~mJy and 100~mJy, particularly at low
solution intervals.  This break between 175~mJy and 100~mJy is influenced
by the {\tt CL} table (\eg\ how rapidly the phases change with time due
to atmospheric coherence)
used to introduce the errors that \KR\ and \FR\ must fix and the amount
of noise in the data.  Therefore this break could be at a different flux
for different data sets.   Since the signal to noise ratio (SNR)
in \KR\ and
\FR\ are calculated differently it is not meaningful to compare the percent
reported solutions directly.

\begin{figure}[t!]
\plotone{FIG/AIPSMEM107C.PS}
\caption{Histogram of residual phase for point sources with various
flux densities.  The black lines the results for \FR\ and the gray (blue)
from \KR\@.}
\label{phase2}
\end{figure}

Table~\ref{table} also lists the percent of actual
good corrections, \ie\ the percent of residual phases near 0 after {\tt
CLCAL} is run.
For the high flux density cases nearly all the passed solutions have
a very high SNR, so we must
conclude that the difference between the reported good solution and the
actual good solutions from \FR\ and \KR\ result from
``bad'' solutions with high SNR\@.  There is also the factor that
between the reported good solutions and the actual good corrections {\tt CLCAL}
is run, which probably corrupts some fraction of the solutions.
Particularly suggestive is the fact that many more of the corrections
are considered bad as the solution interval increases, so {\tt CLCAL}
is understandably less accurate when interpolating over larger gaps in time.
However this could also be caused if the solution interval becomes larger
than the atmospheric coherence time.
For the 100~mJy case the SNR cutoff may be too low.  \KR\ usually
runs faster than \FR\ but the difference for the
100~mJy case is much larger than the other flux densities which suggests
that \FR\ spent more time searching different baselines for possible
solutions.  In this case, \FR\ finds {\it significantly} more good solutions
than \KR\, which may be the result of additional searching.
Both \FR\ and \KR\ will search multiple baselines if solutions they find are
below their respective SNR cutoffs.  So, setting the \KR\ SNR cutoff higher may
have resulted in more actual good solutions.  This low flux density case also
does not follow the pattern of longer time interval, fewer good corrections.
This is probably because for the low flux density \FR\ and \KR\ needed a
long solution interval to find any good solution at all.

If the actual good corrections for \FR\ and \KR\ are compared, it is evident
that for 500~mJy and more \KR\ does a slightly better job, for 250~mJy
and 175~mJy \FR\ does a slightly better job and for 100~mJy \FR\
does a much better job.  Again the higher percent good corrections for
\FR\ in the 100~mJy case may have to do with the SNR cutoff for \FR\
being more reasonable than the one in \KR\@.  There is some indication
that \KR's rate solutions are better than \FR, which may explain \KR's
slightly better performance for the high flux density point sources.

% As seen in figure 1, in the lower
% signal to noise
% cases \FR\ seems to do a better job.  At higher signal to noise
% the case is not so clear.  \FR\ may do a slightly better job with
% the phases (see figure 1)  but \KR\ seems to do a slightly
% better job with the rates (see figure 2).  However \KR\ seems produce
% alias peaks every $\sim 0.5$~mHz away from zero.
% This difference between
% \FR\ and \KR\ in the rates disappears for the low signal to noise
% cases and as you increase the solution interval.
%
% I also ran \FR\ and \KR\ with various solution intervals, 2, 4, 6, 8, and
% 10 minutes.  As expected, for the low signal to noise cases the incidence
% of finding correct solutions when up as a function of solution interval
% and then plateuaed somewhere between 4 and 6 minutes.  The most likely
% explanation for this is that even though the solutions themselves may
% become more accurate as the solution interval increases, you lose your ability
% to interpolate accurately with
% the higher intervals.  This simply reinforces the wisdom that one should
% use the smallest solution interval possible.

For all but 2 cases \KR\ ran faster than \FR; see last 2 columns in
table~\ref{table}.  The difference increased as the solution interval
increased.  As
mentioned above, the huge differences seen for the 100~mJy case are
probably caused by \FR\ searching more baselines for good solutions
than \KR\@.

\begin{deluxetable}{cccccccc}
\tablecolumns{8}
% \tabletypesize{\footnotesize}
\tablecaption{Point Source}
\tablehead{
  \colhead{flux} &
  \colhead{sol. int.} &
  \multicolumn{2}{c}{\% reported good solutions\tablenotemark{a}} &
  \multicolumn{2}{c}{\% actual good corrections\tablenotemark{b}} &
  \multicolumn{2}{c}{run time (sec)\tablenotemark{c}} \\
%
   (mJy)  & (min) & \FR & \KR & \FR & \KR & \FR & \KR }
\startdata
 1000 &   2 &  85.9 &  94.2 &  90.4 &  88.3 &    32 &    30 \\
 1000 &   4 &  80.9 &  92.9 &  81.0 &  82.0 &    68 &    45 \\
 1000 &   6 &  83.8 &  92.6 &  68.4 &  70.4 &   112 &    50 \\
 1000 &   8 &  83.8 &  92.6 &  67.9 &  70.0 &   167 &    76 \\
 1000 &  10 &  93.5 &  93.5 &  50.8 &  51.8 &   166 &    77 \\
  500 &   2 &  83.7 &  93.6 &  88.2 &  92.1 &    33 &    34 \\
  500 &   4 &  79.7 &  92.9 &  80.8 &  81.6 &    71 &    43 \\
  500 &   6 &  81.7 &  92.6 &  68.6 &  70.7 &   120 &    52 \\
  500 &   8 &  81.7 &  92.6 &  68.1 &  70.3 &   172 &    80 \\
  500 &  10 &  88.4 &  93.5 &  50.5 &  51.4 &   173 &    78 \\
  250 &   2 &  83.2 &  92.5 &  81.0 &  81.5 &    36 &    35 \\
  250 &   4 &  79.5 &  92.9 &  76.5 &  76.1 &    68 &    48 \\
  250 &   6 &  82.9 &  92.6 &  68.0 &  66.2 &   109 &    56 \\
  250 &   8 &  82.9 &  92.6 &  67.6 &  65.9 &   171 &    75 \\
  250 &  10 &  82.9 &  93.5 &  50.2 &  49.5 &   169 &    73 \\
  175 &   2 &  83.2 &  91.5 &  69.4 &  58.4 &    41 &    38 \\
  175 &   4 &  82.5 &  92.9 &  71.2 &  64.7 &    73 &    52 \\
  175 &   6 &  78.5 &  92.6 &  65.5 &  61.9 &   136 &    85 \\
  175 &   8 &  78.5 &  92.6 &  65.2 &  61.8 &   200 &   102 \\
  175 &  10 &  91.7 &  93.5 &  49.4 &  47.7 &   207 &   106 \\
  100 &   2 &  32.1 &  37.2 &  26.9 &  20.8 &   104 &   101 \\
  100 &   4 &  66.3 &  50.5 &  40.7 &  14.2 &   483 &   156 \\
  100 &   6 &  76.2 &  76.4 &  51.5 &  21.8 &   726 &   148 \\
  100 &   8 &  76.2 &  76.4 &  51.9 &  22.1 &   620 &   159 \\
  100 &  10 &  74.1 &  91.7 &  41.0 &  30.6 &   817 &   161 \\
\enddata
\tablenotetext{a}{As reported by \FR\ or \KR\@.}
\tablenotetext{b}{Calculated as number of solutions with residual phase
within $\pm 10^{\circ}$ of $0^{\circ}$ over the total number of non-flagged
solutions.}
\tablenotetext{c}{CPU time.}
\label{table}
\end{deluxetable}


\section{Gaussian sources}

A slightly resolved Gaussian was used to test if there is a significant
difference between a point source and a slightly resolved source.  For
the most part there is not; see figure~\ref{gauphase}.  Table~\ref{tabgau}
shows one difference: when the flux is spread over a slightly
resolved Gaussian, it is more difficult for \KR\ and \FR\ to find
good solutions.  Also instead of the slight bias towards \KR\
for the strong point sources, \FR\ always seems to do a slightly
better job, but not as startlingly better for the 100~mJy source.
Again, the run times indicate that \KR\ is faster.

\begin{figure}
\plotone{FIG/AIPSMEM107D.PS}
\caption{Histogram of residual phase for a slightly resolved Gaussian
with various
flux densities.  The black lines the results for \FR\ and the gray (blue)
from \KR\@.}
\label{gauphase}
\end{figure}

\begin{deluxetable}{cccccccc}
\tablecolumns{8}
% \tabletypesize{\footnotesize}
\tablecaption{Single Gaussian}
\tablehead{
  \colhead{flux} &
  \colhead{sol. int.} &
  \multicolumn{2}{c}{\% reported good solutions\tablenotemark{a}} &
  \multicolumn{2}{c}{\% actual good corrections\tablenotemark{b}} &
  \multicolumn{2}{c}{run time (sec)\tablenotemark{c}} \\
%
   (mJy)  & (min) & \FR & \KR & \FR & \KR & \FR & \KR }
\startdata
 1000 &   2 &  82.7 &  94.5 &  77.1 &  73.5 &    85 &    96 \\
 1000 &   4 &  93.1 &  94.5 &  72.5 &  71.7 &   168 &   116 \\
 1000 &   6 &  91.3 &  93.6 &  55.3 &  56.2 &   280 &   127 \\
 1000 &   8 &  93.5 &  94.8 &  42.7 &  41.4 &   371 &   141 \\
 1000 &  10 &  93.5 &  94.8 &  42.6 &  41.3 &   371 &   142 \\
  500 &   2 &  82.4 &  94.5 &  74.7 &  70.5 &    86 &    93 \\
  500 &   4 &  91.6 &  94.5 &  69.5 &  69.0 &   181 &   111 \\
  500 &   6 &  89.8 &  94.2 &  54.2 &  55.3 &   320 &   121 \\
  500 &   8 &  93.5 &  94.8 &  42.2 &  40.3 &   386 &   134 \\
  500 &  10 &  93.5 &  94.8 &  42.1 &  40.1 &   395 &   133 \\
  250 &   2 &  82.3 &  89.6 &  62.9 &  57.2 &   100 &    98 \\
  250 &   4 &  91.3 &  94.0 &  62.2 &  57.1 &   174 &   116 \\
  250 &   6 &  89.9 &  93.8 &  51.7 &  50.9 &   291 &   128 \\
  250 &   8 &  93.5 &  94.8 &  41.2 &  39.0 &   384 &   132 \\
  250 &  10 &  93.5 &  94.8 &  41.0 &  38.8 &   372 &   133 \\
  175 &   2 &  80.3 &  83.7 &  51.7 &  40.5 &   166 &   112 \\
  175 &   4 &  89.3 &  93.6 &  47.7 &  40.4 &   235 &   133 \\
  175 &   6 &  90.6 &  94.0 &  46.3 &  41.1 &   336 &   131 \\
  175 &   8 &  93.3 &  94.4 &  37.1 &  34.9 &   401 &   137 \\
  175 &  10 &  93.3 &  94.4 &  37.0 &  34.8 &   429 &   140 \\
  100 &   2 &  14.2 &  10.1 &  13.4 &   8.7 &   559 &   254 \\
  100 &   4 &  34.6 &  15.0 &  12.4 &   7.5 &  1007 &   251 \\
  100 &   6 &  68.8 &  42.6 &  21.4 &  10.6 &  1440 &   227 \\
  100 &   8 &  82.0 &  68.1 &  23.6 &  12.6 &  1388 &   233 \\
  100 &  10 &  82.0 &  68.1 &  23.7 &  12.6 &  1512 &   234 \\
\enddata
\tablenotetext{a}{As reported by \FR\ or \KR\@.}
\tablenotetext{b}{Calculated as number of solutions with residual phase
within $\pm 10^{\circ}$ of $0^{\circ}$ over the total number of non-flagged
solutions.}
\tablenotetext{c}{CPU time.}
\label{tabgau}
\end{deluxetable}

\section{Conclusions}

\begin{enumerate}

\item In ability to find good solutions, there does not seem to be
a clear advantage to using \FR\ or \KR\@.  A possible exception is for very
low SNR, where \FR\ seems to do a better job; however see the next point.

\item For low signal to noise cases, where one probably wants \FR\ or
\KR\ to search many possible baselines for good solutions, one should be
careful about setting the SNR cutoff.

\item For weak sources, increasing the {\tt SOLINT} must be balanced
with the ability to interpolate accurately between solutions with a
very large {\tt SOLINT}.  How to make this choice is unclear; for the
100~mJy point source the maximum solution interval seemed to be
between 6 and 8 minutes.  Of course, this depends on flux density of
the source, and how complicated the phases are.  If one wanted to
be very careful, one could do simulations similar to mine to determine
the best {\tt SOLINT} for an expected flux density and phase behavior.

\item \KR\ seems to run faster then \FR\, so where time is an issue
\KR\ seems to be the better choice, particularly since there is no
clear ``winner'' in other ways.

\end{enumerate}
\end{document}
