The muse_dark recipe
===============================================================

.. data:: muse_dark

Synopsis
--------

Combine several separate dark images into one master dark file and locate hot pixels.

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

This recipe combines several separate dark images into one master dark file. The master dark contains the combined pixel values of the raw dark exposures, with respect to the image combination method used and normalization time specified. Processing trims the raw data and records the overscan statistics, subtracts the bias (taking account of the overscan, if --overscan is not "none") from each raw input image, converts them from adu to count, scales them according to their exposure time, and combines them using input parameters. Hot pixels are then identified using image statistics and marked in the data quality extension. The combined image is normalized to 1 hour exposure time. QC statistics are computed on the output master dark. If --model=true, a smooth polynomial model of the combined master dark is computed, created from several individual 2D polynomials to describe different features visible in MUSE dark frames. It is only advisable to use this, if the master dark is the result of at least 50 individual long dark exposures.


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

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

   Create an object for the recipe muse_dark.

::

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

Parameters
----------

.. py:attribute:: muse_dark.param.nifu

    IFU to handle. If set to 0, all IFUs are processed serially. If set to  -1, all IFUs are processed in parallel. (int; default: 0) [default=0].
.. py:attribute:: muse_dark.param.overscan

    If this is "none", stop when detecting discrepant overscan levels (see  ovscsigma), for "offset" it assumes that the mean overscan level  represents the real offset in the bias levels of the exposures  involved, and adjusts the data accordingly; for "vpoly", a polynomial  is fit to the vertical overscan and subtracted from the whole  quadrant. (str; default: 'vpoly') [default="vpoly"].
.. py:attribute:: muse_dark.param.ovscreject

    This influences how values are rejected when computing overscan  statistics. Either no rejection at all ("none"), rejection using the  DCR algorithm ("dcr"), or rejection using an iterative constant fit  ("fit"). (str; default: 'dcr') [default="dcr"].
.. py:attribute:: muse_dark.param.ovscsigma

    If the deviation of mean overscan levels between a raw input image and  the reference image is higher than |ovscsigma x stdev|, stop the  processing. If overscan="vpoly", this is used as sigma rejection level  for the iterative polynomial fit (the level comparison is then done  afterwards with |100 x stdev| to guard against incompatible settings).  Has no effect for overscan="offset". (float; default: 30.0) [default=30.0].
.. py:attribute:: muse_dark.param.ovscignore

    The number of pixels of the overscan adjacent to the data section of  the CCD that are ignored when computing statistics or fits. (int;  default: 3) [default=3].
.. py:attribute:: muse_dark.param.combine

    Type of image combination to use. (str; default: 'sigclip') [default="sigclip"].
.. py:attribute:: muse_dark.param.nlow

    Number of minimum pixels to reject with minmax. (int; default: 1) [default=1].
.. py:attribute:: muse_dark.param.nhigh

    Number of maximum pixels to reject with minmax. (int; default: 1) [default=1].
.. py:attribute:: muse_dark.param.nkeep

    Number of pixels to keep with minmax. (int; default: 1) [default=1].
.. py:attribute:: muse_dark.param.lsigma

    Low sigma for pixel rejection with sigclip. (float; default: 3.0) [default=3.0].
.. py:attribute:: muse_dark.param.hsigma

    High sigma for pixel rejection with sigclip. (float; default: 3.0) [default=3.0].
.. py:attribute:: muse_dark.param.scale

    Scale the individual images to a common exposure time before combining  them. (bool; default: True) [default=True].
.. py:attribute:: muse_dark.param.normalize

    Normalize the master dark to this exposure time (in seconds). To  disable normalization, set this to a negative value. (float; default:  3600.0) [default=3600.0].
.. py:attribute:: muse_dark.param.hotsigma

    Sigma level, in terms of median deviation above the median dark level,  above which a pixel is detected and marked as 'hot'. (float; default:  5.0) [default=5.0].
.. py:attribute:: muse_dark.param.model

    Model the master dark using a set of polynomials. (bool; default:  False) [default=False].
.. py:attribute:: muse_dark.param.merge

    Merge output products from different IFUs into a common file. (bool;  default: False) [default=False].


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

::

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

   muse_dark.param.nifu = 0
   muse_dark.param.overscan = "vpoly"
   muse_dark.param.ovscreject = "dcr"
   muse_dark.param.ovscsigma = 30.0
   muse_dark.param.ovscignore = 3
   muse_dark.param.combine = "sigclip"
   muse_dark.param.nlow = 1
   muse_dark.param.nhigh = 1
   muse_dark.param.nkeep = 1
   muse_dark.param.lsigma = 3.0
   muse_dark.param.hsigma = 3.0
   muse_dark.param.scale = True
   muse_dark.param.normalize = 3600.0
   muse_dark.param.hotsigma = 5.0
   muse_dark.param.model = False
   muse_dark.param.merge = False


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

::

   import cpl
   muse_dark = cpl.Recipe("muse_dark")
   [...]
   res = muse_dark( ..., param = {"nifu":0, "overscan":"vpoly"})


.. 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 `Peter Weilbacher <usd-help@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 MUSE Instrument Pipeline
Copyright (C) 2005, 2019 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:: Peter Weilbacher <usd-help@eso.org>
