The xsh_scired_slit_stare recipe
===============================================================

.. data:: xsh_scired_slit_stare

Synopsis
--------

Reduce science exposure in SLIT configuration and stare mode

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

This recipe reduces science exposure in SLIT configuration and stare mode
Input Frames : 
  - A set of n Science frames ( n == 1 or >=3, Tag = OBJECT_SLIT_STARE_UVB)
  - A spectral format table (Tag = SPECTRAL_FORMAT_TAB_arm)
  - [UVB,VIS] A master bias frame (Tag = MASTER_BIAS_arm)
  - [OPTIONAL]A master dark frame (Tag = MASTER_DARK_arm)
  - A master flat frame (Tag = MASTER_FLAT_SLIT_arm)
  - An order table frame(Tag = ORDER_TAB_EDGES_SLIT_arm)
  - [OPTIONAL] A table with dispersion coefficients (Tag = DISP_TAB_arm,
    required in poly mode
  - [poly mode] A wave solution frame(Tag = WAVE_TAB_2D_arm)
  - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_TAB_arm)
  - [OPTIONAL] A table specifying multiplying factor for break points 
    (Tag = SKY_SUB_BKPTS_arm) to generate
  - [OPTIONAL] A non-linear badpixel map (Tag = BP_MAP_NL_arm)
  - [OPTIONAL] A reference badpixel map (Tag = BP_MAP_RP_arm)
  - [OPTIONAL,physmod mode] A table listing sky line positions (Tag = SKY_LINE_LIST_arm)
    this is used to be able to control quality of sky subtraction, for example
    projecting guess positions on the product SCI_SLIT_STARE_SUB_SKY_arm
    and is required if sky-method=BSPLINE
  - [OPTIONAL] The instrument response table (Tag = RESPONSE_MERGE1D_SLIT_arm)
  - [OPTIONAL] An atmospheric extinction table (Tag = ATMOS_EXT_arm)
  - [OPTIONAL] A telluric mask (Tag = TELL_MASK_arm)
  - [OPTIONAL] The instrument master response table (Tag = MRESPONSE_MERGE1D_SLIT_arm).

    If both master and individual response are provided the individual response is preferred.

Products : 
  - PREFIX_ORDER2D_arm extracted spectrum, order-by-order, 2D
  - PREFIX_ORDER1D_arm extracted spectrum, order-by-order, 1D
  - PREFIX_MERGE2D_arm merged spectrum, 2D
  - PREFIX_MERGE1D_arm merged spectrum, 1D
  - SKY_SLIT_MERGE2D_arm merged spectrum sky, 2D
  - PREFIX_SUB_BACK_SLIT_arm sci frame bias, (dark), inter-order bkg subtracted
  - PREFIX_WAVE_MAP_arm, wave map image
  - PREFIX_SLIT_MAP_arm, slit map image
  - PREFIX_DIVFF_arm as PREFIX_SUB_BACK_SLIT_arm, flat fielded
  - PREFIX_SUB_SKY_arm, as PREFIX_DIVFF_arm, sky subtracted
  - PREFIX_SKY_arm, 2D sky frame
  - PREFIX_SKY_ORD1D_arm, 1D sky image (order-by-order)
  - PREFIX_BACK_SLIT_arm, inter order background image 
  - where PREFIX is SCI, FLUX, TELL if input raw DPR.TYPE contains OBJECT or FLUX or TELLURIC
  - [OPTIONAL, if response and atm ext are provided]  PREFIX_FLUX_ORDER2D_arm (2 dimension)
  - [OPTIONAL, if response and atm ext are provided]  PREFIX_FLUX_ORDER1D_arm (1 dimension)
  - [OPTIONAL, if response and atm ext are provided]  PREFIX_FLUX_MERGE2D_arm (2 dimension)
  - [OPTIONAL, if response and atm ext are provided]  PREFIX_FLUX_MERGE1D_arm (1 dimension)
  - PREFIX_ON_arm bias (dark) subtracted sci frame

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

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

   Create an object for the recipe xsh_scired_slit_stare.

::

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

Parameters
----------

.. py:attribute:: xsh_scired_slit_stare.param.keep_temp

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

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

    Add timestamp to product file name. (bool; default: False) [default=False].
.. py:attribute:: xsh_scired_slit_stare.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_scired_slit_stare.param.pre_overscan_corr

    pre-overscan correction. 0: no correction 1: mean overscan correction  2: mean prescan correction 3: (mean pre+mean overscan)/2 correction  (int; default: 1) [default=1].
.. py:attribute:: xsh_scired_slit_stare.param.stack_method

    Method used to build master frame. (str; default: 'median') [default="median"].
.. py:attribute:: xsh_scired_slit_stare.param.klow

    Kappa used to clip low level values, when method is set to 'mean'  (float; default: 5.0) [default=5.0].
.. py:attribute:: xsh_scired_slit_stare.param.khigh

    Kappa used to clip high level values, when method is set to 'mean'  (float; default: 5.0) [default=5.0].
.. py:attribute:: xsh_scired_slit_stare.param.background_edges_margin

    X margin to order edge to define background sampling points (int;  default: 1) [default=1].
.. py:attribute:: xsh_scired_slit_stare.param.background_poly_deg_y

    Poly mode fit deg along Y. (int; default: 9) [default=9].
.. py:attribute:: xsh_scired_slit_stare.param.background_poly_deg_x

    Poly mode fit deg along X. (int; default: 9) [default=9].
.. py:attribute:: xsh_scired_slit_stare.param.background_poly_kappa

    Poly mode kappa value of kappa-sigma-clip outliers removal. (float;  default: 10.0) [default=10.0].
.. py:attribute:: xsh_scired_slit_stare.param.removecrhsingle_sigmalim

    Poisson fluctuation threshold to flag CRHs (see van Dokkum,  PASP,113,2001,p1420-27) (float; default: 20.0) [default=20.0].
.. py:attribute:: xsh_scired_slit_stare.param.removecrhsingle_flim

    Minimum contrast between the Laplacian image and the fine structure  image that a point must have to be flagged as CRH. (see van Dokkum,  PASP,113,2001,p1420-27) (float; default: 2.0) [default=2.0].
.. py:attribute:: xsh_scired_slit_stare.param.removecrhsingle_niter

    Max number of iterations (int; default: 4) [default=4].
.. py:attribute:: xsh_scired_slit_stare.param.rectify_kernel

    Name of the Interpolation Kernel Used. Possible values are:  tanh,  sinc, sinc2, lanczos, hamming, hann. (str; default: 'tanh') [default="tanh"].
.. py:attribute:: xsh_scired_slit_stare.param.rectify_radius

    Rectify Interpolation radius [bin units]. (float; default: 2.0) [default=2.0].
.. py:attribute:: xsh_scired_slit_stare.param.rectify_bin_lambda

    Wavelength step in the output spectrum [nm] (float; default: -1.0) [default=-1.0].
.. py:attribute:: xsh_scired_slit_stare.param.rectify_bin_slit

    Spatial step along the slit in the output spectrum [arcsec] (float;  default: -1.0) [default=-1.0].
.. py:attribute:: xsh_scired_slit_stare.param.localize_method

    Localization method (MANUAL, MAXIMUM, GAUSSIAN) used to detect the  object centroid and height on the slit (str; default: 'MANUAL') [default="MANUAL"].
.. py:attribute:: xsh_scired_slit_stare.param.localize_chunk_nb

    Number of chunks in the full spectrum to localize the object (int;  default: 10) [default=10].
.. py:attribute:: xsh_scired_slit_stare.param.localize_thresh

    Threshold relative to the peak intensity below which the edges of the  object are detected for MAXIMUM localization (float; default: 0.1) [default=0.1].
.. py:attribute:: xsh_scired_slit_stare.param.localize_deg_lambda

    Degree in lambda in the localization polynomial expression  slit=f(lambda), used only for MAXIMUM and GAUSSIAN (int; default: 0) [default=0].
.. py:attribute:: xsh_scired_slit_stare.param.localize_slit_position

    Object position on the slit for MANUAL localization [arcsec] (float;  default: 0.0) [default=0.0].
.. py:attribute:: xsh_scired_slit_stare.param.localize_slit_hheight

    Object half height on the slit for MANUAL localization [arcsec]  (float; default: 2.0) [default=2.0].
.. py:attribute:: xsh_scired_slit_stare.param.localize_kappa

    Kappa value for sigma clipping in the localization polynomial fit  (float; default: 3.0) [default=3.0].
.. py:attribute:: xsh_scired_slit_stare.param.localize_niter

    Number of iterations for sigma clipping in the localization polynomial  fit (int; default: 3) [default=3].
.. py:attribute:: xsh_scired_slit_stare.param.localize_use_skymask

    TRUE if we want to mask sky lines using SKY_LINE_LIST file. (bool;  default: False) [default=False].
.. py:attribute:: xsh_scired_slit_stare.param.sky_subtract

    TRUE to use subtract sky single. (bool; default: True) [default=True].
.. py:attribute:: xsh_scired_slit_stare.param.sky_bspline_nbkpts_first

    Nb of break points for Bezier curve fitting (without localization)  (int; default: 3000) [default=3000].
.. py:attribute:: xsh_scired_slit_stare.param.sky_bspline_nbkpts_second

    Nb of break points for Bezier curve fitting (with localization) (int;  default: 3000) [default=3000].
.. py:attribute:: xsh_scired_slit_stare.param.sky_bspline_order

    Bezier spline order (int; default: 7) [default=7].
.. py:attribute:: xsh_scired_slit_stare.param.sky_bspline_niter

    Nb of iterations (int; default: 20) [default=20].
.. py:attribute:: xsh_scired_slit_stare.param.sky_bspline_kappa

    Kappa value used to kappa-sigma-clip object (float; default: 5.0) [default=5.0].
.. py:attribute:: xsh_scired_slit_stare.param.sky_method

    Sky subtract Method (BSPLINE, BSPLINE1, BSPLINE2 MEDIAN). BSPLINE is  equivalent to BSPLINE1 (str; default: 'MEDIAN') [default="MEDIAN"].
.. py:attribute:: xsh_scired_slit_stare.param.bspline_sampling

    BSPLINE sampling. UNIFORM-uses the user defined nbkpts value,  corrected for binning, for all orders. FINE: multiplies the user  defined nbkpts value, corrected for binning, by a hard coded  coefficient optimized on each arm-order) (str; default: 'FINE') [default="FINE"].
.. py:attribute:: xsh_scired_slit_stare.param.sky_median_hsize

    Half size of the running median. If sky-method=MEDIAN . (int; default:  20) [default=20].
.. py:attribute:: xsh_scired_slit_stare.param.sky_slit_edges_mask

    Size of edges mask in arcsec (float; default: 0.5) [default=0.5].
.. py:attribute:: xsh_scired_slit_stare.param.sky_position1

    Central position of the sky window #1 [arcsec] (float; default: 0.0) [default=0.0].
.. py:attribute:: xsh_scired_slit_stare.param.sky_hheight1

    Half size of sky window #1 [arcsec] (float; default: 0.0) [default=0.0].
.. py:attribute:: xsh_scired_slit_stare.param.sky_position2

    Central position of the sky window #2 [arcsec] (float; default: 0.0) [default=0.0].
.. py:attribute:: xsh_scired_slit_stare.param.sky_hheight2

    Half size of the sky window #2 [arcsec] (float; default: 0.0) [default=0.0].
.. py:attribute:: xsh_scired_slit_stare.param.stdextract_interp_hsize

    Half size of mask used to define object cross order profile (int;  default: 30) [default=30].
.. py:attribute:: xsh_scired_slit_stare.param.do_optextract

    TRUE if we do the optimal extraction (bool; default: False) [default=False].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_oversample

    Oversample factor for the science image (int; default: 5) [default=5].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_box_half_size

    Extraction box [pixel] (int; default: 10) [default=10].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_chunk_size

    Chunk size [bin] (int; default: 50) [default=50].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_step_lambda

    Lambda step [nm] (float; default: 0.02) [default=0.02].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_clip_kappa

    Kappa for cosmics ray hits rejection (float; default: 3.0) [default=3.0].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_clip_frac

    Maximum bad pixels fraction for cosmics ray hits rejection (float;  default: 0.4) [default=0.4].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_clip_niter

    Maximum number of iterations for cosmics ray hits rejection (int;  default: 2) [default=2].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_niter

    Number of iterations (int; default: 1) [default=1].
.. py:attribute:: xsh_scired_slit_stare.param.optextract_method

    Extraction method GAUSSIAN | GENERAL (str; default: 'GAUSSIAN') [default="GAUSSIAN"].
.. py:attribute:: xsh_scired_slit_stare.param.cut_uvb_spectrum

    TRUE if recipe cuts the UVB spectrum at 556 nm (dichroich) (bool;  default: True) [default=True].
.. py:attribute:: xsh_scired_slit_stare.param.generate_SDP_format

    TRUE if additional files should be generated in Science Data Product  (SDP) format. (bool; default: False) [default=False].
.. py:attribute:: xsh_scired_slit_stare.param.dummy_association_keys

    Sets the number of dummy (empty) ASSONi, ASSOCi and ASSOMi keywords to  create. (int; default: 0) [default=0].


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

::

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

   xsh_scired_slit_stare.param.keep_temp = "no"
   xsh_scired_slit_stare.param.debug_level = "none"
   xsh_scired_slit_stare.param.time_stamp = False
   xsh_scired_slit_stare.param.decode_bp = 2144337919
   xsh_scired_slit_stare.param.pre_overscan_corr = 1
   xsh_scired_slit_stare.param.stack_method = "median"
   xsh_scired_slit_stare.param.klow = 5.0
   xsh_scired_slit_stare.param.khigh = 5.0
   xsh_scired_slit_stare.param.background_edges_margin = 1
   xsh_scired_slit_stare.param.background_poly_deg_y = 9
   xsh_scired_slit_stare.param.background_poly_deg_x = 9
   xsh_scired_slit_stare.param.background_poly_kappa = 10.0
   xsh_scired_slit_stare.param.removecrhsingle_sigmalim = 20.0
   xsh_scired_slit_stare.param.removecrhsingle_flim = 2.0
   xsh_scired_slit_stare.param.removecrhsingle_niter = 4
   xsh_scired_slit_stare.param.rectify_kernel = "tanh"
   xsh_scired_slit_stare.param.rectify_radius = 2.0
   xsh_scired_slit_stare.param.rectify_bin_lambda = -1.0
   xsh_scired_slit_stare.param.rectify_bin_slit = -1.0
   xsh_scired_slit_stare.param.localize_method = "MANUAL"
   xsh_scired_slit_stare.param.localize_chunk_nb = 10
   xsh_scired_slit_stare.param.localize_thresh = 0.1
   xsh_scired_slit_stare.param.localize_deg_lambda = 0
   xsh_scired_slit_stare.param.localize_slit_position = 0.0
   xsh_scired_slit_stare.param.localize_slit_hheight = 2.0
   xsh_scired_slit_stare.param.localize_kappa = 3.0
   xsh_scired_slit_stare.param.localize_niter = 3
   xsh_scired_slit_stare.param.localize_use_skymask = False
   xsh_scired_slit_stare.param.sky_subtract = True
   xsh_scired_slit_stare.param.sky_bspline_nbkpts_first = 3000
   xsh_scired_slit_stare.param.sky_bspline_nbkpts_second = 3000
   xsh_scired_slit_stare.param.sky_bspline_order = 7
   xsh_scired_slit_stare.param.sky_bspline_niter = 20
   xsh_scired_slit_stare.param.sky_bspline_kappa = 5.0
   xsh_scired_slit_stare.param.sky_method = "MEDIAN"
   xsh_scired_slit_stare.param.bspline_sampling = "FINE"
   xsh_scired_slit_stare.param.sky_median_hsize = 20
   xsh_scired_slit_stare.param.sky_slit_edges_mask = 0.5
   xsh_scired_slit_stare.param.sky_position1 = 0.0
   xsh_scired_slit_stare.param.sky_hheight1 = 0.0
   xsh_scired_slit_stare.param.sky_position2 = 0.0
   xsh_scired_slit_stare.param.sky_hheight2 = 0.0
   xsh_scired_slit_stare.param.stdextract_interp_hsize = 30
   xsh_scired_slit_stare.param.do_optextract = False
   xsh_scired_slit_stare.param.optextract_oversample = 5
   xsh_scired_slit_stare.param.optextract_box_half_size = 10
   xsh_scired_slit_stare.param.optextract_chunk_size = 50
   xsh_scired_slit_stare.param.optextract_step_lambda = 0.02
   xsh_scired_slit_stare.param.optextract_clip_kappa = 3.0
   xsh_scired_slit_stare.param.optextract_clip_frac = 0.4
   xsh_scired_slit_stare.param.optextract_clip_niter = 2
   xsh_scired_slit_stare.param.optextract_niter = 1
   xsh_scired_slit_stare.param.optextract_method = "GAUSSIAN"
   xsh_scired_slit_stare.param.cut_uvb_spectrum = True
   xsh_scired_slit_stare.param.generate_SDP_format = False
   xsh_scired_slit_stare.param.dummy_association_keys = 0


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

::

   import cpl
   xsh_scired_slit_stare = cpl.Recipe("xsh_scired_slit_stare")
   [...]
   res = xsh_scired_slit_stare( ..., 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 `P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, 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:: P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, D. Bramich, A. Modigliani <amodigli@eso.org>
