; SETJY
;---------------------------------------------------------------
;! Task to enter source info into source (SU) table.
;# TASK CALIBRATION
;-----------------------------------------------------------------------
;;  Copyright (C) 1995-1996, 2000, 2004-2005, 2007-2008, 2010-2012
;;  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
;-----------------------------------------------------------------------
SETJY     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SETJY     Task to enter source info into source (SU) table.
INNAME                             Input image name (name)
INCLASS                            Input image name (class)
INSEQ             0.0     9999.0   Input image name (seq. #)
INDISK            0.0        9.0   Input image disk unit #
SOURCES                            Sources to modify.
QUAL            -10.0              Source qualifier -1=>all
BIF               0.0              Low IF # for flux density
EIF               0.0              High IF # for flux density
ZEROSP                             I,Q,U,V flux density (Jy)
                                   (at 1 GHz if OPTYP='SPEC)
SPECINDX       -5.0     5.0        Spectral index
SPECURVE                           Spectral index curvature
OPTYPE                             '    ' => use other adverbs
                                   for required operation
                                   'SPEC' => as ' ' but ZEROSP
                                   is at 1 GHz not freq of BIF
                                   'CALC' => determine
                                   3C286/3C48/1934 fluxes from
                                   standard formulae
                                   'VCAL' set velocity of
                                   ref channel
                                   'REJY' => reset source
                                   fluxes to zero.
                                   'REVL' => reset velocity
                                   to zero
                                   'RESE' => reset fluxes &
                                   velocities to zero.
CALCODE                            New calibrator code:
                                     '----' => change to blank
SYSVEL                             Velocity of source (km/s)
RESTFREQ                           Line rest frequency (Hz)
VELTYP                             Velocity type 'LSR,'HELIO'
VELDEF                             Velocity definition 'RADIO',
                                   'OPTICAL'
FREQID                             FQ table entry to use for
                                   velocity information and
                                   'CALC' option
APARM                              (1): Pixel to which SYSVEL
                                        refers ( 0=>1)
                                   (2): Only for 'CALC' option:
                                     <= 0 => use best VLA
                                         values (2013/2010)
                                        1 => use best VLA
                                         values (2010) = default
                                         before 13-Oct-2012
                                        2 => use VLA 1999.2
                                         values = default before
                                         2/15/10 in SETJY
                                        3 => use VLA 1995.2
                                         values
                                        4 => use oldest VLA
                                         values (1990)
                                        5 => use Baars values
                                     (any) for 1934-638, the
                                         ATCA value of 30Jul94.
                                   (3): Only for 'CALC' option:
                                        multiply the calculated
                                        fluxes by APARM(3) with
                                        0 -> 1
                                   (4): Only for 'CALC' option:
                                        Use channel APARM(4)'s
                                        frequency for flux
                                        0 -> center
----------------------------------------------------------------
SETJY
Task:  SETJY enters source information into the source (SU) table.  If
       a model for the source is available, it should tell you.  These
       models may be read with CALRD.  CALIB scales the models to the
       total flux in the SU table, so this must be set for the actual
       observing frequency with SETJY even when models are used.

       CALIB now uses the "V polarization" flux when calibrating RR
       (= I + V) and LL (= I - V) correlators.  This may be used for
       instruments with circular polarization if the calibrator is
       circularly polarized (not usually significant).  It may also be
       used with equatorially mounted instruments having linearly
       polarized feeds.  Such feeds do not rotate with parallactic
       angle and so have XX = I-Q and YY = I+Q.  To calibrate these
       instruments, relabel the Stokes from (-5 to -8) to (-1 to -4)
       and put minus the Q flux into the V position (ZEROSP(4)).

       Some users have models for sources other than those provided
       with AIPS.  To use such a model, it is recommended that you
       first run SETJY to set some total flux including spectral index
       and curvature in the SU table.  Then the model will be scaled
       to that flux and GETJY may be used to adjust that scale after
       CALIB.  If you do not set a non-zero flux for such calibrators,
       CALIB will use the flux contained in the model but GETJY will
       assume 1.0 and the result after GETJY will be erroneous.
Adverbs:
  INNAME.....Input image name (name).       Standard defaults.
  INCLASS....Input image name (class).      Standard defaults.
  INSEQ......Input image name (seq. #).     0 => highest.
  INDISK.....Disk drive # of input image.   0 => any.
  SOURCES....The list of sources.  '*' = all; a "-" before a
             source name means all except ANY source named.
             All '  ' =>all.
  QUAL.......Only sources with a source qualifier number in the
             SU table matching QUAL will be modified if QUAL is
             not -1.
  BIF........The lowest IF number for which the given flux
             densities are valid. 0 => 1.
  EIF........The highest IF number for which the given flux
             densities are valid. 0 => all.
  ZEROSP.....The I, Q, U, and V flux densities in Jy.  This option is
             ignored if all 4 values are zero or if OPTYPE is 'CALC',
             'VCAL', 'REJY', or 'RESE'.  It is used otherwise to set
             the fluxes of all 4 polarizations.  If ZEROSP(1) < 0,
             then the I polarization flux is not altered.  This allows
             you to CALC the I flux and set the Q, U, and V fluxes.
             Note, if SPECINDX is not zero, then ZEROSP values are
             taken to be the values at 1 GHz (OPTYPE='SPEC') or at the
             frequency of BIF (OPTYPE not 'SPEC').
  SPECINDX...Spectral index; 0 -> no spectral index of curvature.
  SPECURVE...Spectral curvature.  The net flux of the source is then
               log (flux) = log (ZEROSP(i)) + SPECINDX * log (f) +
                  SPECURVE(1) * [log(f)]^2 + SPECURVE(2) * [log(f)]^3
                  + SPECURVE(3) * [log(f)]^4
             where all logarithms are base 10, f is the frequency in
             GHz, and flux is the source flux at frequency f.
  OPTYPE.....'    ' => use ZEROSP values for the source flux
                  densities at the frequency of BIF and SYSVEL for
                  source velocity.
             'SPEC' => as ' ' except that ZEROSP is interpreted as the
                  fluxes at 1 GHz, the standard fiducial frequency.
             'CALC' => use the standard Baars et al formulae and
                  frequency information in the header to determine the
                  flux densities of the primary calibrators 3C286,
                  3C48 and 3C147 (IAU style names in B1950 or J2000
                  are also recognized by SETJY).  Any selected sources
                  with a recognized name will have fluxes calculated.
                  Australia Telescope source 1934-638 is also
                  recognized (J2000 only but can start with P).
                  (see APARM(2) for polynomial selection).  ZEROSP is
                  ignored.
             'VCAL' => compute the velocity of the first observation
                  in the data set for each of the requested sources
                  and store it in the SU table.  ZEROSP, SYSVEL and
                  APARM(1) are ignored.  RESTFREQ must be set in
                  advance for each IF or specified by RESTFREQ.
             'REJY' => reset source flux densities to zero for
                  source(s) specified.  ZEROSP is ignored.
             'REVL' => reset velocity to zero for source(s)
                  specified.
             'RESE' => do both 'REJY' and 'REVL' operations.

  *********** WARNING: the following adverbs are used on all OPTYPEs
  *********** except as noted, but ' ' and 0.0 are not used to change
  *********** things.
  CALCODE....The 4 character calibrator code to be inserted.
             '    ' => no change, '----' => change to blank,
             '*' is not allowed.
             NOTE that CALCODE is not part of the source selection in
             SETJY as it is in other tasks.
  SYSVEL.....The velocity of the source (in km/s) per IF.
             0 => no change.  If 0 is desired use 1.0E-10.
  RESTFREQ...Rest frequency of line (Hz) per IF; the value used
             is the sum of RESTFREQ(1)+RESTFREQ(2).
             0=>no change
  VELTYP.....Velocity system ('LSR','HELIO'); ' '=> no change.
  VELDEF.....Definition of velocity, 'RADIO' or 'OPTICAL';
             ' ' = > no change.
  FREQID.....Frequency identifier to select (you may determine
             which is applicable from the OPTYPE='SCAN' listing
             produced by LISTR).  This is needed to set the
             frequency for flux computations in CALC OPTYPE.
             It is also needed to estimate the width of a line
             channel in km/s for calculation of velocity info.
             SET IT on CALC.
  APARM......(1) The frequency pixel (or channel) to which the
                 velocity refers. (0=>1)
                 The velocity stored in the 'SU' table will be
                 recalculated to refer to the reference pixel.
             (2): Only for 'CALC' option:
                  <= 0 => use latest VLA values (Perley-Butler 2013)
                          or, for 1934-638, the ATCA value of 30Jul94.
                          new values only for 3C286 and 3C295
                          (Begins 13-Oct-2012 as the default.)
                     1 => use latest VLA values (Perley-Butler 2010)
                          or, for 1934-638, the ATCA value of 30Jul94.
                     2 => use VLA values from 1999.2 (available as the
                          default in SETJY until from 22 Dec 2000 to
                          15 Feb 2010)
                     3 => use mid-1990s VLA determined values
                          (1995.2) or, for 1934-638, the ATCA
                          value of 30Jul94.
                     4 => use oldest VLA determined values
                          (1990) or, for 1934-638, the ATCA
                          value of 30Jul94.
                     5 => use Baars values or old ATCA/PKS values for
                          1934-638
             (3): Only for 'CALC' option:
                  You may wish to reduce the "official" flux computed
                  from the VLA measurements to account for resolution
                  effects.  If 0 < APARM(3) <= 2.0, the computed flux
                  is multipled by APARM(3).  Use the model images
                  instead!
             (4): Only for 'CALC' option:
                  The spectral index computation requires a particular
                  frequency to be used for the flux of each IF.  The
                  frequency used is the one for channel APARM(4)
                  adjusted for each IF.  0 -> center of IF.  Note that
                  when say 1/2 of the IF is flagged for RFI, you can
                  run SETJY for that IF only selecting a more central
                  channel amongst those remaining.
----------------------------------------------------------------
SETJY: Enter Source Flux Density and Calcode into the SU Table.
       Other source parameters may also be entered.
RELATED PROGRAMS: CALIB

                           PURPOSE

 The flux density scale of radio interferometers is often determined by
observations of radio sources of known brightness.  For interferometer
observations, it is important that the standard sources used for this
purpose be relatively compact. This is often at odds however with the
requirement that the sources have very low variability over long
timescales.

 For calibration of observations with the VLA, the radio sources 3C48,
3C286 and 3C147 are often used.  In the southern hemisphere 1934-638
may also be used for this purpose.

 The standard reference for the flux density of bright radio sources
is the paper by Baars, Genzel, Pauliny-Toth, Witzel 1977, Astron.,
Astrop. volume 61, page 99.  The flux density of the standard sources
can be modelled as a polynomial expansion over frequency.  Polynomial
coefficients have also been derived independently by R. Perley and
G. Taylor as part of a long-term program to monitor the standard flux
density calibrators at the VLA. These flux densities have been tied to
3C295 as it is believed that the bulk of the emission from 3C295
should remain constant over a timsecale of thousands of years.

 SETJY will calculate the expected flux density of the standard
calibrators using either the Baars etal. coefficients or those derived
from the VLA observations in 1990, 1995.2, or 1999.2. This option is
selected by setting OPCODE to 'CALC'. The coefficient set to be used is
selected using APARM(2), with the default giving the 2010 values.

The 2010 values are believed to be the best so far determined and
3C48, 3C147, 3C286, and 3C196 are believed to be essentially constant
over time.  The 2010 values in log units are
  Source   log(f 1GHz) SPECINDX  SPECURVE(1)  SPECURVE(2)  SPECURVE(3)
  3C48      1.3197      -0.7253   -0.2023       0.0540        0.0
  3C147     1.4428      -0.6300   -0.3142       0.1032        0.0
  3C138     1.0053      -0.4384   -0.1855       0.0511        0.0
  3C286     1.2361      -0.4127   -0.1864       0.0294        0.0
  3C295     1.4605      -0.7043   -0.3951       0.0815        0.0
The numbers for 1934-638 (Reynolds, 02/Jul/94) are old and on a
different scale entirely (1 MHz) and so are not given here.

***** WARNING - 3C48, 3C147, and especially 3C138 have not been stable
in flux in recent years.  3C138 has doubled in flux at Q band in the
past few years!  Use these sources with great caution.  *************

** NOTE 1: As of the end of 2000, there still is uncertainty in
the absolute VLA flux scale at 43 GHz, with the planets and NGC 7027
giving results that are discrepant by roughly 10%.  For further
information, consult the VLA Observational Status Summary, available
via the VLA web site at http://www.vla.nrao.edu/

** NOTE 2: It was discovered several years ago that the existing 1990 VLA
coefficients were rounded incorrectly in SETJY, introducing a positive
bias of approximately 0.5%, 0.9%, 1.2%, 1.4% and 2.0% at P, L, C, X
and U bands respectively for 3C286. The effect for other sources is
less significant. This error affected AIPS versions up to and
including 15JAN96. The 1990 coefficients implemented in subsequent
versions have been corrected to remove the rounding error.

 For more detailed information regarding the variability of the
standard flux density calibrators at the VLA the user is referred to
the VLA calibrator manual which is available on the WWW at
http://www.nrao.edu/doc/vla/html/calib.shtml.

 The source 1934-638 is the primary calibrator for the ATCA (Australia
Telescope Compact Array).  The flux density scale for 1934-638 was
re-determined by John Reynolds (jreynold@atnf.csiro.au, 30/jul/94) and
implemented in SETJY as the default on 30 August 1994.  Changes in the
flux density scale are significant at all frequencies.  The old scale
can be obtained with OPTYPE='CALC' by setting APARM(2)=1.  If there
are changes between the model being used and the previous of more than
3% the previous model will also be printed (although the current one
is stored with the data).

Frequency          New - Old
  (MHz)               (%)
---------------------------------
408                 -1.9
843                 -3.5
1380                -7.9
1413                -8.1
1612                -9.3
1660                -9.5
1665                -9.5
2295               -11.4
2378               -11.5
4800                -7.9
4835                -7.8
4850                -7.8
8415                +8.5
8420                +8.5
8640                +9.8


 The SETJY output in the SU table can be viewed with the tasks
LISTR or PRTAB.

 There are now models of some calibrator sources shipped with AIPS.
These models are read in with the task CALRD.  The verb CALDIR will
tell you what models are available.  They cover the full range of VLA
bands from L to Q.  New models will be developed for the EVLA.

Note, to use these as calibrators, you must enter a total flux in the
source table with SETJY or GETJY which is correct for your observing
frequency.  Then CALIB will scale the flux in these models to that
total flux.

These models are in J2000 coordinates.  If your data are in B1950,
either change the uv data to J2000 with UVFIX or change the images to
B1950 with EPOSWTCH.
----------------------------------------------------------------
