; IMEAN
;---------------------------------------------------------------
;! displays the mean & extrema and plots histogram of an image
;# Task Plot ANALYSIS
;-----------------------------------------------------------------------
;;  Copyright (C) 1995, 1999, 2002-2004, 2006-2009
;;  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
;-----------------------------------------------------------------------
IMEAN     LLLLLLLLLLLLUUUUUUUUUUUU CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
IMEAN:  Task to print the mean, rms and extrema in an image
DOHIST          -3.0         2.01  True (1.0) do histogram plot.
                                   = 2 => flux on x axis
USERID      -32000.0      32000.0  User ID.  ignored
INNAME                             Image name (name)
INCLASS                            Image name (class)
INSEQ            0.0       9999.0  Image name (seq. #)
INDISK           0.0          9.0  Disk drive #
BLC             -1.0       4096.0  Bottom left corner of image
                                     0=>entire image
TRC              0.0       4096.0  Top right corner of image
                                     0=>entire image
DOINVERS        -1.0          1.0  > 0 => histogram outside
                                   <=0 => inside BLC/TRC
NBOXES           0.0       1024.0  No. of ranges for histogram.
PIXRANGE                           Min and max range for hist.
FUNCTYPE                           'LG' => do log10 plot of #
                                   samples, else linear
PIXAVG   $                         Estimate of mean noise value
PIXSTD   $                         Estimate of true noise rms
                                      < 0 => don't do one
                                      = 0 => 2-passes to get
DOCAT          -1.0         1.0    Put true RMS in header
LTYPE         -10.0        10.0    Type of labeling: 1 border,
                                   2 no ticks, 3 - 6 standard,
                                   7 - 10 only tick labels
                                   <0 -> no date/time
OUTTEXT                            Name of output log file,
                                   No output to file if blank
DOTV           -1.0         1.0    > 0 Do plot on the TV, else
                                   make a plot file
GRCHAN          0.0         8.0    Graphics channel 0 => 1.
----------------------------------------------------------------
IMEAN
Type: Task
Use:  IMEAN will read a portion of an image and print the mean and rms
      brightnesses found.  It also prints the location and value of the
      max and min brightnesses in that portion.  For clean maps, the
      mean is converted into a total flux.  An option to generate a
      histogram plot and/or print file is available.  It also computes
      the peak and rms of the histogram of the image in an attempt to
      determine the mean and rms of the noise part of the signal.  To do
      this option requires either some help from you or a second pass
      through the data.  This fit may fail if the initial guess of the
      rms is too high.  It can also think that it has worked but get a
      wrong answer when the initial guess is closer but still
      significantly too high.  It is always a good idea to take the
      output of the a successfull run of IMEAN for this fit rms
      and repeat IMEAN until that rms settles to a constant value.
      Note that pixel values which are exactly zero are not used in
      the fit for the rms.  This allows blanked pixels to be REMAGed
      to zero without affecting these computations.

      Two adverbs are now also returned by the task.  This allows the
      fit noise to be fed back to IMEAN for refinement and to be used
      in other computations or tasks.

      The aperture for the computation may be either rectangular or
      circular.
Adverbs:
  DOHIST......True (>0) means plot the histogram determined with
              NBOXES and PIXRANGE.  A second histogram is always
              computed, ignoring these adverbs, in an attempt to fit a
              Gaussian to the peak.  If that is succesful, the fit is
              plotted on any plotted histogram.  If 0 < DOHIST <= 1,
              then the flux is plotted on the Y axis and the counts on
              the X axis.  If DOHIST > 1, the axes are reversed -
              which is a more common form.
  USERID......User ID of owner of image.  Ignored.
  INNAME......Image name(name).         Standard defaults.
  INCLASS.....Image name(class).        Standard defaults.
  INSEQ.......Image name(seq. #).       0 => highest.
  INDISK......Disk drive # of image.    0 => any.
  BLC.........The Bottom Left-hand pixel of the subarray of the image to
              be analysed. The value (0,0) means (1,1).
              If BLC(1) = -1, then BLC(2) is taken as the radius of a
              circular aperture centered in TRC(1),TRC(2) which must
              be specified, not defaulted.
  TRC.........The Top Right-hand pixel of the subarray of the image to
              be analysed.  The value (0,0) means the top right hand
              corner of the entire image.
              See note about circular aperture under BLC above.
  DOINVERS....>  0 Do the histogram OUTSIDE the rectangular or
                   circular area defined by BLC/TRC
              <= 0 Do the histogram INSIDE (including borders) the
                   rectangular or circular area defined by BLC/TRC
  NBOXES......Number of boxes used in computing histogram for
              plotting.  The number of boxes used to compute the
              apparent noise rms is controlled by the task.
              <= 1 => 101 boxes,  > 1024 => 512
  PIXRANGE....Intensity range min/max over which plotted histogram is
              computed.  Max <= min (i.e. 0) => full range.  This is
              used to set the range between the center of box 1 and
              the center of box NBOXES.
  FUNCTYPE....Type of axis plot for number of samples in each box.  'LG'
              => log base 10, else linear.
  PIXAVG......Mean value of the noise part of the image - an initial
              guess to help IMEAN fit a Gaussian to the noise.
              The final fit is returned.
  PIXSTD......RMS of the noise portion of the image - an initial guess
              to help IMEAN fit a Gaussian to the noise.
              > 0 => use PIXSTD as an estimate and read the image only
                     once.  It is taken as a source-free estimate of the
                     rms.
              = 0 => get the estimate from ACTNOISE in the image header
                     (if present and positive) or from a first pass
                     through the image.  A second pass is required in
                     that case to get the correct result.
              < 0 => do not fit the noise with a Gaussian.
              You can use the verbs IMSTAT or TVSTAT to set these
              adverbs.  Use a source-free region or it will not work in
              all probability.   Alternatively, divide the PIXSTD
              output by IMSTAT by some factor (e.g. 4 or 10) before
              calling IMEAN.  Note too, that these verbs include
              pixels which are exactly zero in the computation, while
              IMEAN does not.  hus, the verbs may not work well on a
              REMAGed image.  The final fit is returned.
  DOCAT.......> 0 => write the new actual noise estimate as keyword
              ACTNOISE and the estimate zero level as ACTMEAN in the
              image header.
  LTYPE.......Labelling type: 1 = border, 2 = no ticks, 3 - 10 =
              standard, with  7-10 all labels other than tick numbers
              and axis type are omitted.  Less than 0 is the same except
              that the plot file version number and create time are
              omitted.
  OUTTEXT.....Output file to log measurements for later user processing.
              File created if it does not exist and appended to if it
              already exists.  Nothing is is written to a file if the
              name is blank.  File name should contain directory and
              file parts, i.e, "LOCAL:IMEAN.OUT" or
              "RUNFIL:IMPORTANT.POINTS".  The histogram is printed into
              the file.
  DOTV........> 0 => plot directly on the TV device, otherwise make a
              plot file for later display on one or more devices
              (including the TV if desired).
  GRCHAN......Graphics channel (1 - 7) to use for line drawing.  0 => 1.
----------------------------------------------------------------
