% @(#)backgreche.hlq	19.1 (ESO-IPG) 02/25/03 14:18:31 
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%.COPYRIGHT  (c)  1990 European Southern Observatory
%.IDENT      backgreche.hlq
%.AUTHOR     Pascal Ballester, IPG/ESO
%.KEYWORDS   MIDAS, help files, BACKGROUND/ECHELLE
%.PURPOSE    On-line help file for the command: BACKGROUND/ECHELLE
%.VERSION    1.0  19-SEP-1990 : Creation, PB
%                 22-JUN-1999 : bkgmea option added, SW
%----------------------------------------------------------------
\se
SECTION./ECHE
\es\co
BACKGROUND/ECHELLE					22-JUN-1999 PB
\oc\su
BACKGROUND/ECHELLE in out [radx,rady,step] [degree] [smooth] [method] [bkgmea]
	estimate interorder scattered light  of an echelle spectrum
\us\pu
Purpose:    
            Compute the background of the echelle raw spectrum in the
            sampling space pixel-pixel. This command requires the table
            Background values are estimated at reference positions 
            between the orders and interpolated either by smoothing 
            spline or bivariate polynomial interpolation. Commands
            SCAN/ECHELLE and SELECT/BACKGROUND can be used before.
\up\sy
Syntax:     
            BACKGROUND/ECHELLE in out [radx,rady,[step]] [deg] [smooth] SPLINE
            BACKGROUND/ECHELLE in out [degx,degy,[step]]  P6=POLY   (see note)
\ys\pa
            input     = input raw spectrum, sampled in pixel-pixel space
\ap\pa
            output    = computed background image
\ap\pa
            radx,rady = radius of the window for median estimate of
                        the background. The quantity 2*rady+1 must be
                        smaller than the interorder width. The window 
                        is tilted to follow the orders, so that the
                        distance 2*radx+1 is parallel to the orders.
                        
                        Echelle keyword is BKGRAD; it is shown in SHOW/ECHEL\\
                        if BKGMTD=SPLINE. Default value is 6,2.
\ap\pa
            degx,degy = Degrees of the bivariate polynomial in method POLY.
                        Echelle keyword is BKGPOL and is displayed
                        by SHOW/ECHELLE if BKGMTD=POLY. Default value is 2,3.
\ap\pa
            step      = step along X axis between background reference 
                        positions. Echelle keyword is BKGSTEP.
\ap\pa
            deg       = Degree of the spline polynomials used to define
                        the background values in method SPLINE.

                        degree=0 is not allowed

                        Echelle keyword is BKGDEG; is displayed by SHOW/ECHE \\
                        if BKGMTD=SPLINE. Default is 3.
\ap\pa
            smooth    = Value of the smoothing factor in SPLINE method.
                        Echelle keyword is BKGSMO and is displayed by
                        SHOW/ECHE if BKGMTD=SPLINE. Default is 1000.
\ap\pa
            method    = POLY or SPLINE. Echelle keyword is BKGMTD, 
                        default is POLY.
\ap\pa
            bkgmea    = Specify the measuring method at background position
                        in case of bkgmtd=SPLINE. Usually the median within
                        the box defined by BKGRAD centered on the background
                        position read from table BAKTAB is used to determine
                        the background. In some cases it is useful to take
                        the MINIMUM instead.
                        Default: bkgmea=MEDIAN.
\ap\sa
See also:   
            BACKGR/SMOOTH, SCAN/ECHELLE, SELECT/BACKGROUND, \\
            SUBTRACT/BACKGR
\as\no
Note:       
            This command enables to choose between two methods to estimate
            the interorder background. The selection of the method depends on
            the value of parameter P6 or echelle keyword BKGMTD (see syntax).

            1) Bivariate Polynomial Method

            A bivariate polynomial is fitted to the values of interorder
            background measured at positions defined by columns :X and
            :YBKG of the table back.tbl. 

            Parameters degX and degY are respectively the degree of the
            polynomial along X and Y axis. Defaults are degX=2 and degY=3.

            Null degrees are allowed by polynomial method

            2) Spline Method
        
            The background is approximated using a smoothing spline
            algorithm. Reference positions of the background are defined
            in columns :X and :YBKG of the table back.tbl created by 
            DEFINE/ECHELLE or DEFINE/HOUGH.\\
            Only the selected positions of the table back.tbl are used
            to estimate the background. It is possible to unselect positions
            with the command SELECT/BACK.

            The background level on each of these reference positions is 
            defined as the median value estimated on a window which radius
            is radx,rady. The estimated values are written in column :BKG
            of table middummb.tbl.

            The values are then approximated using a smoothing spline
            algorithm. The smoothing factor allows to interpolate the values
            (smooth=0.) or to smooth them (the optimal smoothing factor
            depends on the standard-deviation of the background values).

            For more details on how to optimize background parameters,
            see MIDAS documentation, Vol. B, Chapt. 8: Echelle Package.

            Bugs\\       
            The descriptor HISTORY of the output frame is the same as the
            one of the input frame, except for the last line, which is
            overwritten by a message describing the background computation
            parameters.
\on\exs
Examples:
\ex
            BACKGROUND/ECHELLE obj backobj 10,2,5   3    0.  SPLINE
\xe\ex
            BACKGROUND/ECHELLE obj backobj     P6=SPLINE
\xe\ex
            BACKGROUND/ECHELLE obj bak  3,4    P6=POLY
\xe \sxe





