The visir_img_reduce recipe
===============================================================

.. data:: visir_img_reduce

Synopsis
--------

Combines a stack of chopped, jittered and/or nodded exposures and can compute the sensitivity for standard star observations

Description
-----------

This recipe recombines the data observed in chopping/nodding or
chopping or nodding modes into one combined image using optionally
cross-correlation methods.

The files listed in the Set Of Frames (sof-file) must be tagged:
VISIR-observation-file.fits IM_OBS_CHO_NOD_JIT or
VISIR-observation-file.fits IM_OBS_CHO_JIT or
VISIR-observation-file.fits IM_OBS_NOD_JIT or
VISIR-observation-file.fits IM_OBS_DIR_JIT or
VISIR-observation-file.fits BURST
VISIR-Standard-star-catalog IMG_STD_CATALOG (optional)
VISIR-linearty-table.fits LINEARITY_TABLE (optional)
Additionally, a bad pixel map with a PRO.CATG of IMG_BPM
may be added to the Set Of Frames with tag: BPM.


Constructor
-----------

.. method:: cpl.Recipe("visir_img_reduce")
   :noindex:

   Create an object for the recipe visir_img_reduce.

::

   import cpl
   visir_img_reduce = cpl.Recipe("visir_img_reduce")

Parameters
----------

.. py:attribute:: visir_img_reduce.param.planestart

    Plane number to start repacking from, earlier planes are skipped.  (long; default: 0) [default=0].
.. py:attribute:: visir_img_reduce.param.ncycles

    Number of full on-off cycles to repack. <= 0 for all. (long; default:  -1) [default=-1].
.. py:attribute:: visir_img_reduce.param.trimlow

    Burst data only. Number of additional planes to cut from before each  plane with chopper movement. (long; default: 0) [default=0].
.. py:attribute:: visir_img_reduce.param.trimhigh

    Burst data only. Number of additional planes to cut from after each  plane with chopper movement.  A value of -1 does not skip the plane of  the movement. (long; default: 0) [default=0].
.. py:attribute:: visir_img_reduce.param.template

    Correlation template used to detect shifts and reject bad images.  If  none given an averaged image is used (str; default: 'NONE') [default="NONE"].
.. py:attribute:: visir_img_reduce.param.min_correlation

    Minimal correlation to the template required to be accepted (float;  default: 0.5) [default=0.5].
.. py:attribute:: visir_img_reduce.param.max_shift

    Maximal allowed object shift for an image to be accepted (float;  default: 10.0) [default=10.0].
.. py:attribute:: visir_img_reduce.param.max_mad

    Maximal allowed median absolute deviation for an image to be accepted.  <= 0 equals no limit (float; default: 0.0) [default=0.0].
.. py:attribute:: visir_img_reduce.param.naverage

    Number of planes to average before attempting to detect the shifts.  (long; default: 1) [default=1].
.. py:attribute:: visir_img_reduce.param.method

    Method to determine beam shifts.  xcorrelate: use the cross  correlation shift.  brightest: use the position of the brightest pixel  (str; default: 'xcorrelate') [default="xcorrelate"].
.. py:attribute:: visir_img_reduce.param.no_shift

    Sets whether to apply the determined shifts in following recipes. Set  to TRUE of shifts appear too large. (bool; default: False) [default=False].
.. py:attribute:: visir_img_reduce.param.no_reject

    If true images with bad statistics will not be rejected and no shift  correction is done (bool; default: True) [default=True].
.. py:attribute:: visir_img_reduce.param.beampos

    Define the positions of the beams. These positions are cut by the  window to extract the single beam images.  Format:  sign:x,y,window;sign:x,y,window;...   where sign is "pos" or "neg"  depending on whether the beam is positive or negative.  The window is  optional and defines the size of the cut image around the beam. The  default window is the chop throw.  E.g.: pos:50,60;neg:50,160;  By  default autodetection is attempted.  (str; default: 'NONE') [default="NONE"].
.. py:attribute:: visir_img_reduce.param.eccmax

    The maximum eccentricity allowed in the combination of the three (in  parallel nod/chopping) or four (in perpendicular nod/chopping) beams.  In parallel mode, three perfectly aligned points spaced with the  chopnod throw will have eccentricity 0, while in perpedicular mode a  square with the chopnod throw as the side length will have  eccentricity 0 (float; default: 0.25) [default=0.25].
.. py:attribute:: visir_img_reduce.param.keepfrac

    The fraction of pixels to keep for the initialmedian (float; default:  0.9) [default=0.9].
.. py:attribute:: visir_img_reduce.param.kappa

    Clip outside + or - kappa * sigma (the standard deviation) (float;  default: 5.0) [default=5.0].
.. py:attribute:: visir_img_reduce.param.maxite

    Max number of kappa-sigma clipping iterations (long; default: 3) [default=3].
.. py:attribute:: visir_img_reduce.param.shift_beams

    Account for movements of the object defined in CRPIX[12] (bool;  default: True) [default=True].
.. py:attribute:: visir_img_reduce.param.error_source

    Defines the way errors are generated:  img-stdev: stdev of image  timeseries: stdev of each pixel over the time axis of the cube  none:  no error generation (str; default: 'img-stdev') [default="img-stdev"].
.. py:attribute:: visir_img_reduce.param.badimage

    If percentage of clipped pixels above this value the whole image is  considered bad (float; default: 0.2) [default=0.2].
.. py:attribute:: visir_img_reduce.param.output_all

    Output a coadded image for each input file in addition to the complete  coaddition. (bool; default: False) [default=False].
.. py:attribute:: visir_img_reduce.param.extra_config

    Additional configuration parameters (str; default: 'NONE') [default="NONE"].
.. py:attribute:: visir_img_reduce.param.config_fname

    Swarp configure file name. (str; default: '/usr/share/cpl-  plugins/visir-4.1.0/config/visir_default.swarp') [default="/usr/share/cpl-plugins/visir-4.1.0/config/visir_default.swarp"].
.. py:attribute:: visir_img_reduce.param.nprocs

    Maximum number of swarp processes that can be spawned simultaneously.  (long; default: -1) [default=-1].
.. py:attribute:: visir_img_reduce.param.jy_val

    The flux of the standard star in Jansky (float; default: -999.0) [default=-999.0].
.. py:attribute:: visir_img_reduce.param.radii

    Radii : star_max bg_int bg_ext (str; default: '20-20-30') [default="20-20-30"].
.. py:attribute:: visir_img_reduce.param.delete_temp

    Delete temporary files created during processing (bool; default: True) [default=True].


The following code snippet shows the default settings for the available 
parameters.

::

   import cpl
   visir_img_reduce = cpl.Recipe("visir_img_reduce")

   visir_img_reduce.param.planestart = 0
   visir_img_reduce.param.ncycles = -1
   visir_img_reduce.param.trimlow = 0
   visir_img_reduce.param.trimhigh = 0
   visir_img_reduce.param.template = "NONE"
   visir_img_reduce.param.min_correlation = 0.5
   visir_img_reduce.param.max_shift = 10.0
   visir_img_reduce.param.max_mad = 0.0
   visir_img_reduce.param.naverage = 1
   visir_img_reduce.param.method = "xcorrelate"
   visir_img_reduce.param.no_shift = False
   visir_img_reduce.param.no_reject = True
   visir_img_reduce.param.beampos = "NONE"
   visir_img_reduce.param.eccmax = 0.25
   visir_img_reduce.param.keepfrac = 0.9
   visir_img_reduce.param.kappa = 5.0
   visir_img_reduce.param.maxite = 3
   visir_img_reduce.param.shift_beams = True
   visir_img_reduce.param.error_source = "img-stdev"
   visir_img_reduce.param.badimage = 0.2
   visir_img_reduce.param.output_all = False
   visir_img_reduce.param.extra_config = "NONE"
   visir_img_reduce.param.config_fname = "/usr/share/cpl-plugins/visir-4.1.0/config/visir_default.swarp"
   visir_img_reduce.param.nprocs = -1
   visir_img_reduce.param.jy_val = -999.0
   visir_img_reduce.param.radii = "20-20-30"
   visir_img_reduce.param.delete_temp = True


You may also set or overwrite some or all parameters by the recipe 
parameter `param`, as shown in the following example:

::

   import cpl
   visir_img_reduce = cpl.Recipe("visir_img_reduce")
   [...]
   res = visir_img_reduce( ..., param = {"planestart":0, "ncycles":-1})


.. seealso:: `cpl.Recipe <http://packages.python.org/python-cpl/recipe.html>`_
   for more information about the recipe object.

Bug reports
-----------

Please report any problems to `Julian Taylor <jtaylor@partner.eso.org>`_. Alternatively, you may 
send a report to the `ESO User Support Department <usd-help@eso.org>`_.

Copyright
---------

This file is part of the VISIR Instrument Pipeline
Copyright (C) 2015 European Southern Observatory

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., 51 Franklin St, Fifth Floor, Boston, 
MA  02111-1307  USA

.. codeauthor:: Julian Taylor <jtaylor@partner.eso.org>
