The kmo_combine recipe
===============================================================

.. data:: kmo_combine

Synopsis
--------

Combine reconstructed cubes

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

This recipe shifts several exposures of an object and combines them. The diffe-
rent methods to match the exposures are described below (--method parameter).

The output cube is larger than the input cubes, according to the shifts to be
applied. Additionally a border of NaN values is added. The WCS is the same as
for the first exposure.

For each spatial/spectral pixel a new value will be calculated (according the
--cmethod parameter) and written into the output cube.

Only exposures with equal orientation regarding the WCS can be combined (except
-–method=”none”), north must point to the same direction. It is recommended to
apply any rotation possibly after combining.


The behavior of the selection of IFUs to combine differs for some templates and
can be controlled with the parameters --name and --ifus.

If the input data cubes stem from templates KMOS_spec_obs_mapping8 or
KMOS_spec_obs_mapping24 all extensions from all input frames are combined into
a single map by default (like in recipe kmo_sci_red). If just the area of a
specific IFU should be combined, the parameter --ifus can be specified, or more
easily --name.

If the input data cubes stem from other templates like e.g.

KMOS_spec_obs_freedither all extensions of all input frames are combined into
several output frames by default. The input IFUs are grouped according their
targeted object name stored in the keywords ESO OCS ARMx NAME. If just a
specific object should be combined, its name can be specified with parameter
--name. If arbitrary IFUs shoukd be comined, one can specify these with the
parameter --ifus.


The default mapping mode is done via the --name parameter, where the name of
the object has to be provided. The recipe searches in all input data cubes IFUs
pointing to that object.


Input files
^^^^^^^^^^^^
::

   DO                      KMOS                                                
   category                Type   Explanation                  Required #Frames
   --------                -----  -----------                  -------- -------
   <none or any>           F3I    data frame                       Y      2-n  

Output files
^^^^^^^^^^^^
::

   DO                      KMOS
   category                Type   Explanation
   --------                -----  -----------
   COMBINE_<ESO PRO CATG>  F3I    Combined data cube
   EXP_MASK_<ESO PRO CATG> F3I    Exposure time mask


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

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

   Create an object for the recipe kmo_combine.

::

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

Parameters
----------

.. py:attribute:: kmo_combine.param.name

    Name of the object to combine. (str; default: '') [default=""].
.. py:attribute:: kmo_combine.param.ifus

    The indices of the IFUs to combine. "ifu1;ifu2;..." (str; default: '') [default=""].
.. py:attribute:: kmo_combine.param.method

    The shifting method:   'none': no shifting, combined directly  (default), 'header': shift according to WCS, 'center': centering  algorithm, 'user': read shifts from file (str; default: 'none') [default="none"].
.. py:attribute:: kmo_combine.param.fmethod

    The fitting method (applies only when method='center'):   'gauss': fit  a gauss function to collapsed image (default), 'moffat': fit a moffat  function to collapsed image (str; default: 'gauss') [default="gauss"].
.. py:attribute:: kmo_combine.param.filename

    The path to the file with the shift vectors.(Applies only to  method='user') (str; default: '') [default=""].
.. py:attribute:: kmo_combine.param.flux

    Apply flux conservation: (TRUE (apply) or FALSE (don't apply) (bool;  default: False) [default=False].
.. py:attribute:: kmo_combine.param.edge_nan

    Set borders of cubes to NaN before combining them.(TRUE (apply) or  FALSE (don't apply) (bool; default: False) [default=False].
.. py:attribute:: kmo_combine.param.suppress_extension

    Suppress arbitrary filename extension.(TRUE (apply) or FALSE (don't  apply) (bool; default: False) [default=False].
.. py:attribute:: kmo_combine.param.cmethod

    Either apply "average", "median", "sum", "min_max." or "ksigma". (str;  default: 'ksigma') [default="ksigma"].
.. py:attribute:: kmo_combine.param.cpos_rej

    The positive rejection threshold for kappa-sigma-clipping (sigma).  (float; default: 3.0) [default=3.0].
.. py:attribute:: kmo_combine.param.cneg_rej

    The negative rejection threshold for kappa-sigma-clipping (sigma).  (float; default: 3.0) [default=3.0].
.. py:attribute:: kmo_combine.param.citer

    The number of iterations for kappa-sigma-clipping. (long; default: 3) [default=3].
.. py:attribute:: kmo_combine.param.cmax

    The number of maximum pixel values to clip with min/max-clipping.  (long; default: 1) [default=1].
.. py:attribute:: kmo_combine.param.cmin

    The number of minimum pixel values to clip with min/max-clipping.  (long; default: 1) [default=1].


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

::

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

   kmo_combine.param.name = ""
   kmo_combine.param.ifus = ""
   kmo_combine.param.method = "none"
   kmo_combine.param.fmethod = "gauss"
   kmo_combine.param.filename = ""
   kmo_combine.param.flux = False
   kmo_combine.param.edge_nan = False
   kmo_combine.param.suppress_extension = False
   kmo_combine.param.cmethod = "ksigma"
   kmo_combine.param.cpos_rej = 3.0
   kmo_combine.param.cneg_rej = 3.0
   kmo_combine.param.citer = 3
   kmo_combine.param.cmax = 1
   kmo_combine.param.cmin = 1


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

::

   import cpl
   kmo_combine = cpl.Recipe("kmo_combine")
   [...]
   res = kmo_combine( ..., param = {"name":"", "ifus":""})


.. 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 `Alex Agudo Berbel <kmos-spark@mpe.mpg.de>`_. Alternatively, you may 
send a report to the `ESO User Support Department <usd-help@eso.org>`_.

Copyright
---------

This file is part of the KMOS Instrument Pipeline
Copyright (C) 2002,2003 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, 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA

.. codeauthor:: Alex Agudo Berbel <kmos-spark@mpe.mpg.de>
