The muse_scibasic recipe
===============================================================

.. data:: muse_scibasic

Synopsis
--------

Remove the instrumental signature from the data of each CCD and convert them from an image into a pixel table.

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

Processing handles each raw input image separately: it trims the raw data and records the overscan statistics, subtracts the bias (taking account of the overscan, if --overscan is not "none"), optionally detects cosmic rays (note that by default cosmic ray rejection is handled in the post processing recipes while the data is reformatted into a datacube, so that the default setting is cr="none" here), converts the images from adu to count, subtracts the dark, divides by the flat-field, and (optionally) propagates the integrated flux value from the twilight-sky cube. The reduced image is then saved (if --saveimage=true). The input calibrations geometry table, trace table, and wavelength calibration table are used to assign 3D coordinates to each CCD-based pixel, thereby creating a pixel table for each exposure. If --skylines contains one or more wavelengths for (bright and isolated) sky emission lines, these lines are used to correct the wavelength calibration using an offset. The data is then cut to a useful wavelength range (if --crop=true). If an ILLUM exposure was given as input, it is then used to correct the relative illumination between all slices of one IFU. For this, the data of each slice is multiplied by the normalized median flux of that slice in the ILLUM exposure. As last step, the data is divided by the normalized twilight cube (if given), using the 3D coordinate of each pixel in the pixel table to interpolate the twilight correction onto the data. This pre-reduced pixel table for each exposure is then saved to disk.


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

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

   Create an object for the recipe muse_scibasic.

::

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

Parameters
----------

.. py:attribute:: muse_scibasic.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_scibasic.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_scibasic.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_scibasic.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_scibasic.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_scibasic.param.crop

    Automatically crop the output pixel tables in wavelength depending on  the expected useful wavelength range of the active instrument mode  (4750-9350 Angstrom for nominal mode and NFM, 4700-9350 Angstrom for  nominal AO mode, and 4600-9350 Angstrom for the extended modes).  (bool; default: True) [default=True].
.. py:attribute:: muse_scibasic.param.cr

    Type of cosmic ray cleaning to use (for quick-look data processing).  (str; default: 'none') [default="none"].
.. py:attribute:: muse_scibasic.param.xbox

    Search box size in x. Only used if cr=dcr. (int; default: 15) [default=15].
.. py:attribute:: muse_scibasic.param.ybox

    Search box size in y. Only used if cr=dcr. (int; default: 40) [default=40].
.. py:attribute:: muse_scibasic.param.passes

    Maximum number of cleaning passes. Only used if cr=dcr. (int; default:  2) [default=2].
.. py:attribute:: muse_scibasic.param.thres

    Threshold for detection gap in factors of standard deviation. Only  used if cr=dcr. (float; default: 5.8) [default=5.8].
.. py:attribute:: muse_scibasic.param.combine

    Type of combination to use. Note that in most cases, science exposures  cannot easily be combined on the CCD level, so this should usually be  kept as "none"! This does not pay attention about the type of input  data, and will combine all raw inputs! (str; default: 'none') [default="none"].
.. py:attribute:: muse_scibasic.param.nlow

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

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

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

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

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

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

    Save the pre-processed CCD-based image of each input exposure before  it is transformed into a pixel table. (bool; default: True) [default=True].
.. py:attribute:: muse_scibasic.param.skylines

    List of wavelengths of sky emission lines (in Angstrom) to use as  reference for wavelength offset correction using a Gaussian fit. It  can contain multiple (isolated) lines, as comma-separated list,  individual shifts are then combined into one weighted average offset.  Set to "none" to deactivate. (str; default: '5577.339,6300.304') [default="5577.339,6300.304"].
.. py:attribute:: muse_scibasic.param.skyhalfwidth

    Half-width of the extraction box (in Angstrom) around each sky  emission line. (float; default: 5.0) [default=5.0].
.. py:attribute:: muse_scibasic.param.skybinsize

    Size of the bins (in Angstrom per pixel) for the intermediate spectrum  to do the Gaussian fit to each sky emission line. (float; default:  0.1) [default=0.1].
.. py:attribute:: muse_scibasic.param.skyreject

    Sigma clipping parameters for the intermediate spectrum to do the  Gaussian fit to each sky emission line. Up to three comma-separated  numbers can be given, which are interpreted as high sigma-clipping  limit (float), low limit (float), and number of iterations (integer),  respectively. (str; default: '15.,15.,1') [default="15.,15.,1"].
.. py:attribute:: muse_scibasic.param.resample

    Resample the input science data into 2D spectral images using all  supplied calibrations for a visual check. Note that the image produced  will show small wiggles even when the input calibrations are good and  were applied successfully! (bool; default: False) [default=False].
.. py:attribute:: muse_scibasic.param.dlambda

    Wavelength step (in Angstrom per pixel) to use for resampling. (float;  default: 1.25) [default=1.25].
.. py:attribute:: muse_scibasic.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_scibasic = cpl.Recipe("muse_scibasic")

   muse_scibasic.param.nifu = 0
   muse_scibasic.param.overscan = "vpoly"
   muse_scibasic.param.ovscreject = "dcr"
   muse_scibasic.param.ovscsigma = 30.0
   muse_scibasic.param.ovscignore = 3
   muse_scibasic.param.crop = True
   muse_scibasic.param.cr = "none"
   muse_scibasic.param.xbox = 15
   muse_scibasic.param.ybox = 40
   muse_scibasic.param.passes = 2
   muse_scibasic.param.thres = 5.8
   muse_scibasic.param.combine = "none"
   muse_scibasic.param.nlow = 1
   muse_scibasic.param.nhigh = 1
   muse_scibasic.param.nkeep = 1
   muse_scibasic.param.lsigma = 3.0
   muse_scibasic.param.hsigma = 3.0
   muse_scibasic.param.scale = True
   muse_scibasic.param.saveimage = True
   muse_scibasic.param.skylines = "5577.339,6300.304"
   muse_scibasic.param.skyhalfwidth = 5.0
   muse_scibasic.param.skybinsize = 0.1
   muse_scibasic.param.skyreject = "15.,15.,1"
   muse_scibasic.param.resample = False
   muse_scibasic.param.dlambda = 1.25
   muse_scibasic.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_scibasic = cpl.Recipe("muse_scibasic")
   [...]
   res = muse_scibasic( ..., 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 <https://support.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 <https://support.eso.org>
