FUNCTION CRAYFIX,im0,n=n,threshold=threshold ;Identify NxN-pixel cosmic rays events in image and replace with median ; of surrounding pixels using subroutine BPIXFIX. ;Create AHB 02/04 if not KEYWORD_SET(n) then n=1 if not KEYWORD_SET(threshold) then threshold=10.0 npix = N_ELEMENTS(im0) dev = im0 - MEDIAN(im0,n+2) ;subtract boxcar median sig = SQRT(TOTAL(dev^2) / (npix-1.)) ;std. dev. (mean = 0) w = WHERE( ABS(dev) gt threshold*sig) ;ID those above threshold if w[0] ne -1 then begin bpix = BYTE(im0) bpix[*] = 0B bpix[w] = 1B im1 = BPIXFIX(im0,bpix) endif else im1 = im0 RETURN,im1 END