Viewing contents of file '../idllib/ssw/allpro/asmooth.pro'
FUNCTION ASMOOTH,ARRAY,WIDTH,MISSING=MISSING
;+
; Project : SOHO - CDS
;
; Name : ASMOOTH()
;
; Purpose : Smooths a one or two-dimensional array.
;
; Category : Image-processing, SU:SERTSIM, Class3
;
; Explanation : Does the same thing as the IDL built-in SMOOTH function, except
; that:
;
; 1. The effect tapers off at the edges of the array, instead
; of abruptly stopping as in SMOOTH.
;
; 2. Missing pixels are handled.
;
; Syntax : Result = ASMOOTH( ARRAY, WIDTH )
;
; Examples :
;
; Inputs : ARRAY = One or two-dimensional array to be smoothed.
; WIDTH = Width of the smoothing box.
;
; Opt. Inputs : None.
;
; Outputs : The result of the function is the smoothed array.
;
; Opt. Outputs: None.
;
; Keywords : MISSING = The value representing missing pixels.
;
; Calls : GET_IM_KEYWORD
;
; Common : None.
;
; Restrictions: ARRAY must be one or two-dimensional.
;
; Side effects: None.
;
; Prev. Hist. : Originally written for the SERTS project, February 1993.
;
; History : Version 1, 14-Aug-1998, William Thompson, GSFC
; Version 2, 29-Oct-1998, William Thompson, GSFC
; Fixed bug at edges of array when MISSING is not used.
; Version 3, 02-Dec-1998, William Thompson, GSFC
; Fixed bug when WIDTH is even, and MISSING not passed.
;
; Contact : WTHOMPSON
;-
;
ON_ERROR,2
;
; Check the number of parameters.
;
IF N_PARAMS() NE 2 THEN MESSAGE, $
'Syntax: Result = ASMOOTH(ARRAY,WIDTH)'
;
; Check the size of the array.
;
SZ = SIZE(ARRAY)
IF SZ(0) EQ 0 THEN MESSAGE,'ARRAY not defined'
IF SZ(0) GT 2 THEN MESSAGE,'ARRAY must be one- or two-dimensional'
NX = SZ(1)
IF SZ(0) EQ 2 THEN NY = SZ(2) ELSE NY = 1
;
; Get the size of the border to add onto the array.
;
IF N_ELEMENTS(WIDTH) NE 1 THEN MESSAGE, $
'WIDTH must be a scalar'
WIDTHX = WIDTH
IF SZ(0) EQ 2 THEN WIDTHY = WIDTH ELSE WIDTHY = 1
WX = FIX(WIDTHX/2)
WY = FIX(WIDTHY/2)
;
; Get the value of the missing keyword.
;
GET_IM_KEYWORD, MISSING, !IMAGE.MISSING
;
; Form the larger array to apply the smoothing function to.
;
A = FLTARR(NX+2*WX, NY+2*WY)
N = A
AA = ARRAY
IF N_ELEMENTS(MISSING) EQ 1 THEN BEGIN
MASK = ARRAY NE MISSING
W = WHERE(AA EQ MISSING, COUNT)
IF COUNT GT 0 THEN AA(W) = 0
END ELSE MASK = 1
;
; Apply the smoothing function by adding up the boxcar.
;
FOR I=-WX,WIDTHX-WX-1 DO BEGIN
FOR J=-WY,WIDTHY-WY-1 DO BEGIN
I1 = I+WX & I2 = I1+NX-1
J1 = J+WY & J2 = J1+NY-1
A(I1:I2,J1:J2) = A(I1:I2,J1:J2) + AA
N(I1:I2,J1:J2) = N(I1:I2,J1:J2) + MASK
ENDFOR
ENDFOR
;
; Divide out the number of pixels making up the sum. Make sure that missing
; pixels are properly set, and extract the part corresponding to the original
; array.
;
A = A / (N > 1)
W = WHERE(N EQ 0, COUNT)
IF (COUNT GT 0) AND (N_ELEMENTS(MISSING) EQ 1) THEN A(W) = MISSING
IF SZ(0) EQ 1 THEN A = A(WX:NX+WX-1) ELSE A = A(WX:NX+WX-1,WY:NY+WY-1)
;
RETURN, A
END