The xsh_2dmap recipe
===============================================================

.. data:: xsh_2dmap

Synopsis
--------

Creates a wavelength and spatial resampling solution, a clean arc line list

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

This recipe creates a wavelength and spatial resampling solution, a clean arc line list.

 a residual map and a wave map.

Input Frames:
  Raw Frame (Tag = WAVE_arm)
  Arc Line List (Tag = ARC_LINE_LIST_arm)
  Order Table (Tag = ORDER_TAB_EDGES_arm)
  Master Bias (Tag = MASTER_BIAS_arm)
  [poly mode] Wave Solution (Tag = WAVE_TAB_GUESS_arm)
  [poly mode] Theoretical Map (Tag = THEO_TAB_MULT_arm)
  [physical model mode] model cfg table (Tag = XSH_MOD_CFG_OPT_FMT_arm)
  [OPTIONAL] Master Dark (Tag = MASTER_DARK_arm)
  [OPTIONAL] Non-linear Bad Pixel Map (Tag = BP_MAP_NL_arm)
  [OPTIONAL] Reference Bad Pixel Map (Tag = BP_MAP_RP_arm)
  [OPTIONAL] Reference list to monitor line intensity (Tag = ARC_LINE_LIST_INTMON_arm)
 Prepare the frames.

For UVB,VIS:
   Subtract Master Bias.

   Subtract Master Dark.

For NIR:
  Subtract ON OFF 
  Compute Wavelength Solution, clean arc line list, residual table, wave map
  Products:
   Wavelength table solution, PRO.CATG = WAVE_TAB_2D_arm [poly mode]
   A Residual tab, PRO.CATG=WAVE_RESID_TAB_SLIT_arm
   A Wavelelength image map, PRO.CATG=WAVE_MAP_arm. [if model-wavemap-compute=TRUE]
   A Slit image map, PRO.CATG=SLIT_MAP_NIR [if model-wavemap-compute=TRUE]
   A Dispersion solution table, PRO.CATG=DISP_TAB_NIR
   An Arc frame in pre format bias subtracted, 
   PRO.CATG=WAVE_ON_arm
   The optimized model cfg frame, PRO.CATG=XSH_MOD_CFG_OPT_2D_arm [if physical model mode].


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

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

   Create an object for the recipe xsh_2dmap.

::

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

Parameters
----------

.. py:attribute:: xsh_2dmap.param.keep_temp

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

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

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

    Half window size (HWS) in pixels for the line 2D fitting window (total  window size = 2*HWS+1) (int; default: 6) [default=6].
.. py:attribute:: xsh_2dmap.param.detectarclines_search_win_hsize

    Half window size (HWS) in pixels for the line search box around the  expected position (total window size = 2*HWS+1) [bin units] (int;  default: 3) [default=3].
.. py:attribute:: xsh_2dmap.param.detectarclines_running_median_hsize

    Half window size in pixels (HWS) for the running median box (int;  default: 0) [default=0].
.. py:attribute:: xsh_2dmap.param.detectarclines_wavesol_deg_lambda

    Degree in lambda in the polynomial solution X=f(lambda,order,slit) and  Y=f(lambda,order,slit) (POLY mode) (int; default: 5) [default=5].
.. py:attribute:: xsh_2dmap.param.detectarclines_wavesol_deg_order

    Degree in order in the polynomial solution X=f(lambda,order,slit) and  Y=f(lambda,order,slit) (POLY mode) (int; default: 4) [default=4].
.. py:attribute:: xsh_2dmap.param.detectarclines_wavesol_deg_slit

    Degree in slit in the polynomial solution X=f(lambda,order,slit) and  Y=f(lambda,order,slit) (POLY mode) (int; default: 1) [default=1].
.. py:attribute:: xsh_2dmap.param.detectarclines_min_sn

    Minimum signal-to-noise ratio to filter lines [xsh_predict:  UVB,VIS=5,NIR=4; xsh_2dmap: UVB=3, VIS=6, NIR=10] (float; default:  5.0) [default=5.0].
.. py:attribute:: xsh_2dmap.param.detectarclines_find_lines_center

    Method used to find the center of the lines: gaussian, barycenter.  Gaussian method applies a Gaussian fit to the line. Barycenter method  computes the line centroid. (str; default: 'gaussian') [default="gaussian"].
.. py:attribute:: xsh_2dmap.param.detectarclines_clip_sigma

    Kappa value in sigma clipping during the polynomial solution fit (POLY  mode) (float; default: 2.0) [default=2.0].
.. py:attribute:: xsh_2dmap.param.detectarclines_clip_niter

    Number of iterations in sigma clipping during the polynomial solution  fit (POLY mode) (int; default: 0) [default=0].
.. py:attribute:: xsh_2dmap.param.detectarclines_clip_frac

    Minimal fractions of bad pixel allowed in sigma clipping duringthe  polynomial solution fit (POLY mode) (float; default: 0.7) [default=0.7].
.. py:attribute:: xsh_2dmap.param.dispersol_deg_x

    Degree in X in the polynomial dispersion solution lambda=f(X,Y) and  slit=f(X,Y) (int; default: 4) [default=4].
.. py:attribute:: xsh_2dmap.param.dispersol_deg_y

    Degree in Y in the polynomial dispersion solution lambda=f(X,Y) and  slit=f(X,Y) (int; default: 5) [default=5].
.. py:attribute:: xsh_2dmap.param.model_maxit

    Number/10 of annealing iterations (physical model mode). (int;  default: 500) [default=500].
.. py:attribute:: xsh_2dmap.param.model_anneal_factor

    Multiplier applied to the automatic parameter ranges (i.e. when  scenario!=0). For routine operations should be 1.0. (physical model  mode). (float; default: 1.0) [default=1.0].
.. py:attribute:: xsh_2dmap.param.model_scenario

    selects preset flag and range combinations appropriate to common  scenarios:   0 - No scenario, input cfg flags and limitsused.  1 -  scenario appropriate for the startuprecipe (large ranges for  parameters affecting single ph exposures, dist coeff fixed)  2 - Like  1, but includes parameters affecting all ph positions  3 - Scenario  for use in fine tuning cfg to match routine single pinhole exposures.  All parameters affecting 1ph exposures except dist coeffs are included  and parameter ranges are small. (For use by predict in 1ph case).  4 -  Like 3 but includes parameters affecting all ph positions (Standard  for use by predict in 9ph case and 2dmap).  (int; default: 4) [default=4].


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

::

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

   xsh_2dmap.param.keep_temp = "no"
   xsh_2dmap.param.debug_level = "none"
   xsh_2dmap.param.time_stamp = False
   xsh_2dmap.param.decode_bp = 2144337919
   xsh_2dmap.param.pre_overscan_corr = 1
   xsh_2dmap.param.detectarclines_fit_win_hsize = 6
   xsh_2dmap.param.detectarclines_search_win_hsize = 3
   xsh_2dmap.param.detectarclines_running_median_hsize = 0
   xsh_2dmap.param.detectarclines_wavesol_deg_lambda = 5
   xsh_2dmap.param.detectarclines_wavesol_deg_order = 4
   xsh_2dmap.param.detectarclines_wavesol_deg_slit = 1
   xsh_2dmap.param.detectarclines_min_sn = 5.0
   xsh_2dmap.param.detectarclines_find_lines_center = "gaussian"
   xsh_2dmap.param.detectarclines_clip_sigma = 2.0
   xsh_2dmap.param.detectarclines_clip_niter = 0
   xsh_2dmap.param.detectarclines_clip_frac = 0.7
   xsh_2dmap.param.dispersol_deg_x = 4
   xsh_2dmap.param.dispersol_deg_y = 5
   xsh_2dmap.param.model_maxit = 500
   xsh_2dmap.param.model_anneal_factor = 1.0
   xsh_2dmap.param.model_scenario = 4


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

::

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