; docformat = 'rst' ; ; NAME: ; evalGauss ; PURPOSE: ; Evaluate the ordinate (Y) coordinates of a 1-D Gaussian function ; ;+ ; :Description: ; Evaluate the ordinate (Y) coordinates of a 1-D Gaussian function ; ; :Categories: ; Maths, Evaluation ; ; :Params: ; X: in, required, type=float ; Array (any dimension) of x values. ; P: in, required, type=float ; The parameters of the Gaussian:: ; P[0] = Peak Value ; P[1] = Peak Centroid ; P[2] = Gaussian Sigma ; P[3] = Background Level (Optional) ; P[4] = Background Slope (Optional) ; ; :Returns: The evaluated ordinates at positions X ; ; :Keywords: ; _EXTRA: in, optional, type=struct ; Can suppleant P in inversion code s(see MPFITFUN) ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in August 2014, B. Carry (IMCCE) ; 2016 Nov - B. Carry (OCA) - Added idl2 ;- function evalGauss, X, P, _EXTRA=_EXTRA ;-------------------------------------------------------------------------------- ;--I-- Initialization And Input Verification ----------------------------------- ;--I.1-- Make Compilation Silent COMPILE_OPT hidden, idl2 ;--I.2-- Check Presence of Arguments ; if N_params() LT 2 then begin ; print,'Syntax - Y = evalGauss( X, P )' ; return, -1 ; endif ;--I.3-- Handle Extra Keyword (e.g., for use in MPFIT): replace P by _EXTRA.P if keyword_set( _extra ) then p = _extra.p ;--I.4-- Convert Inputs to Float X=float(X) P=float(P) ;-------------------------------------------------------------------------------- ;--II-- Function Evaluation ---------------------------------------------------- u = (x - p[1])/p[2] gauss = p[0] * exp(-0.5*u^2) ;-------------------------------------------------------------------------------- ;--III-- Background Evaluation ------------------------------------------------- nterms = n_elements( p ) case nterms of 3: plane=x*0. 4: plane=p[3] 5: plane=p[3] + x*p[4] endcase ;-------------------------------------------------------------------------------- ;--IV-- Return Gaussian Peak with Background ----------------------------------- return, (gauss+plane) end