def medianThresholdFilter(self, activeOnly, threshold, length): if activeOnly: active = self.getActiveCurve() if not active: return else: x, y, legend, info = active self.removeCurve(legend) spectra = [active] else: spectra = self.getAllCurves() for (idx, spec) in enumerate(spectra): x, y, legend, info = spec filtered = medfilt1d(y, length) diff = filtered-y mean = diff.mean() sigma = (y-mean)**2 sigma = numpy.sqrt(sigma.sum()/float(len(sigma))) ynew = numpy.where(abs(diff) > threshold * sigma, filtered, y) legend = info.get('selectionlegend',legend) + ' SR' if (idx==0) and (len(spectra)!=1): self.addCurve(x,ynew,legend,info, replace=True, replot=False) elif idx == (len(spectra)- 1): self.addCurve(x,ynew,legend,info, replace=False, replot=True) else: self.addCurve(x,ynew,legend,info, replace=False, replot=False)