pro despike_lc,data,nsig,badval,hnew ; Routine despikes an input array using a variance threshhold ; A linear trend is taken off the data before despiking - the output ; array, however, is not linearly detrended. ; Must have compiled detren.pro ; INPUTS: ; DATA is the input array, assumed to be a time series. ; NSIG is the number of standard deviations outside which an element ; in the array is assumed to be a spike (bad value). ; BADVAL is the value used to represent missing or errant data. ; OUTPUTS: ; DATA is the despiked data array, where spikes have been replaced with ; BADVAL. Note that the original array IS modified. ; linearly detrend input array ; Modified by VSinha and BWBerger 8/17/98 to remove nsig=4 line that was below ; (nsig is supposed to be an input parameter). detren_lc,data,ddata,dmean,trend,badval hold=-1 hnew=0 ; Uncomment the while loop to try an iterative routine. May be necessary ; if the spikes have a wide range of values. Beware of setting NSIG too ; low and wiping out the entire data array! ;while (hnew-hold gt 0) do begin ;iterative g=where(ddata ne badval,num) ; hold=hnew ;iterative ; Compute standard deviation if (num gt 1) then begin sig=stdev(ddata(g)) ; h=where(abs(ddata) gt nsig*sig,hnew) ; ddata(h)=badval ;iterative if (h(0) gt -1) then data(h)=badval endif ;endwhile ;iterative return end