The xsh_lingain recipe
===============================================================

.. data:: xsh_lingain

Synopsis
--------

Computes detector's gain/linearity-map

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

This recipe computes detector linearity coefficients and gain
Input Frames : 
  arm = UVB-VIS: 
  - A set of n RAW linearity frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)
  - A set of n RAW bias frames (Format=RAW, n >=1, Tag = LINEARITY_arm_OFF)
  arm = NIR:
  - A set of n RAW linearity on frames (Format=RAW, n >=8, Tag = LINEARITY_arm_ON)
  - A set of n RAW linearity off frames (Format=RAW, n >=8, Tag = LINEARITY_arm_OFF)
  - [OPTIONAL] a static bad pixel map (PRO.CATG=BP_MAP_RP_arm) 
  Note: on and off frames are taken in pairs sequence: OFF-ON-ON-OFF, 
  at least 16 frames.

Products : 
  - A linearity map table, PRO.CATG = BP_MAP_LIN_NIR
  - A gain table, PRO.CATG = GAIN_INFO
  - A cube cointaining the linearity coefficients, PRO.CATG = COEFFS_CUBE_arm
  - A linearity map image (RAW format), PRO.CATG = RAW_BP_MAP_NL_arm
  - A linearity map image (PRE format), PRO.CATG = BP_MAP_NL_arm

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

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

   Create an object for the recipe xsh_lingain.

::

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

Parameters
----------

.. py:attribute:: xsh_lingain.param.keep_temp

    If 'no', temporary files are deleted. (str; default: 'no') [default="no"].
.. py:attribute:: xsh_lingain.param.debug_level

    Additional xshooter debug level. One of 'none', 'low', 'medium',  'high' (str; default: 'none') [default="none"].
.. py:attribute:: xsh_lingain.param.time_stamp

    Add timestamp to product file name. (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.decode_bp

    Integer representation of the bits to be considered bad when decoding  the bad pixel mask pixel values.   Most frequent codes relevant for  the user:   0: good pixel,   8: pick-up noise,   16: cosmic-ray  removed,   32: cosmic-ray unremoved,   128: calibration file defect,  256: hot pixel,   512: dark pixel,   4096: A/D converted saturation,  32768: non linear pixel,   1048576: extrapolated flux in NIR,  4194304: Interpolated flux during extraction. (int; default:  2144337919) [default=2144337919].
.. py:attribute:: xsh_lingain.param.method

    Method to be used when computing GAIN. Methods appliable: <PTC | MED>.  By default PTC method will be applied. (str; default: 'PTC') [default="PTC"].
.. py:attribute:: xsh_lingain.param.order

    Polynomial order for the fit (Linearity) (int; default: 3) [default=3].
.. py:attribute:: xsh_lingain.param.kappa

    Kappa value for the kappa-sigma clipping (Gain) (float; default: 3.0) [default=3.0].
.. py:attribute:: xsh_lingain.param.niter

    Number of iterations to compute rms (Gain) (int; default: 5) [default=5].
.. py:attribute:: xsh_lingain.param.llx

    x coordinate of the lower-left point of the region of interest. If not  modified, default value will be 1. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly

    y coordinate of the lower-left point of the region of interest. If not  modified, default value will be 1. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx

    x coordinate of the upper-right point of the region of interest. If  not modified, default value will be X dimension of the input image.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury

    y coordinate of the upper-right point of the region of interest. If  not modified, default value will be Y dimension of the input image.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ref_level

    User reference level (int; default: 10000) [default=10000].
.. py:attribute:: xsh_lingain.param.intermediate

    De-/Activate intermediate products (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.autocorr

    De-/Activate the autocorr option (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.collapse

    De-/Activate the collapse option (bool; default: True) [default=True].
.. py:attribute:: xsh_lingain.param.rescale

    De-/Activate the image rescale option (bool; default: True) [default=True].
.. py:attribute:: xsh_lingain.param.pix2pix

    De-/Activate the computation with pixel to pixel accuracy (bool;  default: True) [default=True].
.. py:attribute:: xsh_lingain.param.bpmbin

    De-/Activate the binary bpm option (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.m

    Maximum x-shift for the autocorr (int; default: 26) [default=26].
.. py:attribute:: xsh_lingain.param.filter

    Upper limit of Median flux to be filtered (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.n

    Maximum y-shift for the autocorr (int; default: 26) [default=26].
.. py:attribute:: xsh_lingain.param.tolerance

    Tolerance for pair discrimination (float; default: 0.1) [default=0.1].
.. py:attribute:: xsh_lingain.param.pafgen

    Generate PAF file (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.pafname

    Specific name for PAF file (str; default: 'xsh_lingain') [default="xsh_lingain"].
.. py:attribute:: xsh_lingain.param.exts

    Activate the multi-exts option. Choose -1 to process all extensions.  Choose an extension number to process the appropriate extension. (int;  default: 0) [default=0].
.. py:attribute:: xsh_lingain.param.fpn_method

    Method for computing Fixed Pattern Noise (SMOOTH or HISTOGRAM) (str;  default: 'HISTOGRAM') [default="HISTOGRAM"].
.. py:attribute:: xsh_lingain.param.fpn_smooth

    template size in pixels for smoothing during FPN computation (only for  SMOOTH method) (int; default: 13) [default=13].
.. py:attribute:: xsh_lingain.param.saturation_limit

    all frames with mean saturation above the limit would not be used in  linearity calculation (float; default: 65535.0) [default=65535.0].
.. py:attribute:: xsh_lingain.param.gain_threshold

    all frames with mean flux above the threshold would not be used in  gain calculation (float; default: 65535.0) [default=65535.0].
.. py:attribute:: xsh_lingain.param.coeffs_cube_split

    if TRUE, the recipe writes as many COEFFS_CUBE_Pi (i=0..order) as the  value of the order parameter in a separate file (bool; default: False) [default=False].
.. py:attribute:: xsh_lingain.param.llx1

    x coord of the lower-left point of the first field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly1

    y coord of the lower-left point of the first field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx1

    x coord of the upper-right point of the first field used for  contamination measurement. If not modified, default value will be X  dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury1

    y coord of the upper-right point of the first field used for  contamination measurement. If not modified, default value will be Y  dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.llx2

    x coord of the lower-left point of the second field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly2

    y coord of the lower-left point of the second field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx2

    x coord of the upper-right point of the second field used for  contamination measurement. If not modified, default value will be half  of the X dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury2

    y coord of the upper-right point of the second field used for  contamination measurement. If not modified, default value will be half  of the Y dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.llx3

    x coord of the lower-left point of the third field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly3

    y coord of the lower-left point of the third field used for  contamination measurement. If not modified, default value will be half  of the Y dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx3

    x coord of the upper-right point of the third field used for  contamination measurement. If not modified, default value will be half  of X dimension of the image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury3

    y coord of the upper-right point of the third field used for  contamination measurement. If not modified, default value will be Y  dimension of the image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.llx4

    x coord of the lower-left point of the fourth field used for  contamination measurement. If not modified, default value will be half  of X dimension of the image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly4

    y coord of the lower-left point of the fourth field used for  contamination measurement. If not modified, default value will be half  of the Y dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx4

    x coord of the upper-right point of the fourth field used for  contamination measurement. If not modified, default value will be X  dimension of the image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury4

    y coord of the upper-right point of the fourth field used for  contamination measurement. If not modified, default value will be Y  dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.llx5

    x coord of the lower-left point of the fifth field used for  contamination measurement. If not modified, default value will be half  of the X dimension of the input image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.lly5

    y coord of the lower-left point of the fifth field used for  contamination measurement. If not modified, default value will be 1.  (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.urx5

    x coord of the upper-right point of the fifth field used for  contamination measurement. If not modified, default value will be X  dimension of the image. (int; default: -1) [default=-1].
.. py:attribute:: xsh_lingain.param.ury5

    y coord of the upper-right point of the fifth field used for  contamination measurement. If not modified, default value will be half  of Y dimension of the input image. (int; default: -1) [default=-1].


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

::

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

   xsh_lingain.param.keep_temp = "no"
   xsh_lingain.param.debug_level = "none"
   xsh_lingain.param.time_stamp = False
   xsh_lingain.param.decode_bp = 2144337919
   xsh_lingain.param.method = "PTC"
   xsh_lingain.param.order = 3
   xsh_lingain.param.kappa = 3.0
   xsh_lingain.param.niter = 5
   xsh_lingain.param.llx = -1
   xsh_lingain.param.lly = -1
   xsh_lingain.param.urx = -1
   xsh_lingain.param.ury = -1
   xsh_lingain.param.ref_level = 10000
   xsh_lingain.param.intermediate = False
   xsh_lingain.param.autocorr = False
   xsh_lingain.param.collapse = True
   xsh_lingain.param.rescale = True
   xsh_lingain.param.pix2pix = True
   xsh_lingain.param.bpmbin = False
   xsh_lingain.param.m = 26
   xsh_lingain.param.filter = -1
   xsh_lingain.param.n = 26
   xsh_lingain.param.tolerance = 0.1
   xsh_lingain.param.pafgen = False
   xsh_lingain.param.pafname = "xsh_lingain"
   xsh_lingain.param.exts = 0
   xsh_lingain.param.fpn_method = "HISTOGRAM"
   xsh_lingain.param.fpn_smooth = 13
   xsh_lingain.param.saturation_limit = 65535.0
   xsh_lingain.param.gain_threshold = 65535.0
   xsh_lingain.param.coeffs_cube_split = False
   xsh_lingain.param.llx1 = -1
   xsh_lingain.param.lly1 = -1
   xsh_lingain.param.urx1 = -1
   xsh_lingain.param.ury1 = -1
   xsh_lingain.param.llx2 = -1
   xsh_lingain.param.lly2 = -1
   xsh_lingain.param.urx2 = -1
   xsh_lingain.param.ury2 = -1
   xsh_lingain.param.llx3 = -1
   xsh_lingain.param.lly3 = -1
   xsh_lingain.param.urx3 = -1
   xsh_lingain.param.ury3 = -1
   xsh_lingain.param.llx4 = -1
   xsh_lingain.param.lly4 = -1
   xsh_lingain.param.urx4 = -1
   xsh_lingain.param.ury4 = -1
   xsh_lingain.param.llx5 = -1
   xsh_lingain.param.lly5 = -1
   xsh_lingain.param.urx5 = -1
   xsh_lingain.param.ury5 = -1


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

::

   import cpl
   xsh_lingain = cpl.Recipe("xsh_lingain")
   [...]
   res = xsh_lingain( ..., param = {"keep_temp":"no", "debug_level":"none"})


.. 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 `Lander de Bilbao,A.Modigliani <amodigli@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 X-shooter Instrument Pipeline
Copyright (C) 2006 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., 59 Temple Place, Suite 330, Boston, 
MA  02111-1307  USA

.. codeauthor:: Lander de Bilbao,A.Modigliani <amodigli@eso.org>
