; ---------------------------------------------------------------------- ; Compute highest weighted deviation and index number. ; Also return: ; 'yrms' (RMS of Y values from median of Y values (ww>0), excluding 20% worse values ). ; 'devmed' (median of deviations from fit (ww>0) ). ; 'devrms' (RMS of deviations from fit (ww>0), excluding 20% worse values ). ; 'hidev' (high deviation from fit (ww>0) ). ; pro nsx_hidevrms, nn, xx, yy, ww, order, xoff, coef, yrms, devmed, devrms, hidev, hiii devarr = dblarr(3000) arr = dblarr(3000) ; Y values: Median and rms. narr=0 for ii=0,nn-1 do begin if (ww[ii] gt 0.) then begin arr[narr] = yy[ii] ++narr endif endfor ymedian = cfind_median8(narr,arr) ; Y values: Compute RMS excluding the 20% largest deviations. */ for ii=0,narr-1 do devarr[ii] = ABS((arr[ii] - ymedian)) cqcksrt8,narr,devarr narr80 = cnint( 0.8 * double(narr) ) sum = 0. for ii=0L, narr80-1 do sum = sum + (devarr[ii] * devarr[ii]) yrms = sqrt(( sum / double(narr80) )) ; Fit deviations: compute RMS relative to fit excluding 20% largest deviations. narr=0 for ii=0,nn-1 do begin if (ww[ii] gt 0.) then begin ff = cpolyval(order+1,coef,(xx[ii]-xoff)) devarr[narr] = ABS(( yy[ii] - ff )) ++narr endif endfor devmed = cfind_median8(narr,devarr) narr80 = cnint( 0.8 * double(narr) ) sum = 0. for ii=0,narr80-1 do sum = sum + (devarr[ii] * devarr[ii]) devrms = sqrt(( sum / double(narr80) )) ; Highest deviation. */ hidev=-1. hiii=-1 for ii=0,nn-1 do begin if (ww[ii] gt 0.) then begin ff = cpolyval(order+1,coef,(xx[ii]-xoff)) dev = ABS(( yy[ii] - ff )) if (dev gt hidev) then begin hidev=dev hiii=ii endif endif endfor end