The fors_normalise_flat recipe
===============================================================

.. data:: fors_normalise_flat

Synopsis
--------

Normalise master flat spectrum

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

This recipe is used to normalise a master flat field frame dividing it
by its large scale illumination trend. This recipe can be applied both
to generic multi-slit (MOS/MXU) and to long slit exposures (either LSS, or
LSS-like MOS/MXU), even if different normalisation methods are applied in
such different cases. The input master flat field image is the product
of the recipe fors_flat. The input spectral curvature table, product of
the recipe fors_detect_spectra, is only required in the case of multi-slit
data.


In the case of multi-slit data, the flat field spectra are spatially
rectified, heavily smoothed, and then mapped back on the CCD. Then the
master flat image is divided by its smoothed counterpart. The smoothing
may be obtained either by applying a running median filter of specified
sizes, or by polynomial fitting along the dispersion direction performed
independently for each row of the spatially remapped spectra.


In the case of long-slit data, the smoothing can still be obtained either
by applying a running median filter or by polynomial fitting, but the
polynomial fitting will be performed along the spatial direction, for
each column of the spectrum.


In the table below the MXU acronym can be alternatively read as MOS or
LSS.


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

  DO category:               Type:       Explanation:         Required:
  MASTER_SCREEN_FLAT_MXU     Calib       Master flat frame       Y
  DISP_COEFF_MXU             Calib       Wavelength calibration  Y
  CURV_COEFF_MXU             Calib       Spectral curvature      .

  SLIT_LOCATION_MXU          Calib       Slit detection          .

  GRISM_TABLE                Calib       Grism table             Y

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

  DO category:               Data type:  Explanation:
  MASTER_NORM_FLAT_MXU       FITS image  Normalised flat field


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

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

   Create an object for the recipe fors_normalise_flat.

::

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

Parameters
----------

.. py:attribute:: fors_normalise_flat.param.dispersion

    Expected spectral dispersion (Angstrom/pixel) (float; default: 0.0) [default=0.0].
.. py:attribute:: fors_normalise_flat.param.startwavelength

    Start wavelength in spectral extraction (float; default: 0.0) [default=0.0].
.. py:attribute:: fors_normalise_flat.param.endwavelength

    End wavelength in spectral extraction (float; default: 0.0) [default=0.0].
.. py:attribute:: fors_normalise_flat.param.spa_polydegree

    Polynomial degree for the flat field fitting along spatial direction  (int; default: -1) [default=-1].
.. py:attribute:: fors_normalise_flat.param.sradius

    Smooth box radius for flat field along spatial direction (used if  spa_knots < 0) (int; default: 10) [default=10].
.. py:attribute:: fors_normalise_flat.param.disp_nknots

    Number of knots in flat field fitting splines along dispersion  direction (int; default: -1) [default=-1].
.. py:attribute:: fors_normalise_flat.param.dradius

    Smooth box radius for flat field along dispersion direction (if  disp_knots < 0) (int; default: 10) [default=10].
.. py:attribute:: fors_normalise_flat.param.splfit_threshold

    Threshold percentage for flat spline fittingwith respect to the  maximum (float; default: 0.01) [default=0.01].


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

::

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

   fors_normalise_flat.param.dispersion = 0.0
   fors_normalise_flat.param.startwavelength = 0.0
   fors_normalise_flat.param.endwavelength = 0.0
   fors_normalise_flat.param.spa_polydegree = -1
   fors_normalise_flat.param.sradius = 10
   fors_normalise_flat.param.disp_nknots = -1
   fors_normalise_flat.param.dradius = 10
   fors_normalise_flat.param.splfit_threshold = 0.01


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

::

   import cpl
   fors_normalise_flat = cpl.Recipe("fors_normalise_flat")
   [...]
   res = fors_normalise_flat( ..., param = {"dispersion":0.0, "startwavelength":0.0})


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

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

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

Copyright
---------

This file is currently part of the FORS Instrument Pipeline
Copyright (C) 2002-2010 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  02110-1301  USA


.. codeauthor:: Carlo Izzo <usd-help@eso.org>
