def updateGraph(self, ddict): points = ddict['points'] degree = ddict['degree'] order = ddict['order'] self.background = SGModule.getSavitzkyGolay(self.spectrum, points, degree=degree, order=order) # if the x are decreasing the result is not correct if order % 2: if self.xValues is not None: if self.xValues[0] > self.xValues[-1]: self.background *= -1 if order > 0: maptoy2 = "right" else: maptoy2 = "left" self.graph.addCurve(self.xValues, self.background, "Filtered Spectrum", replace=False, yaxis=maptoy2) #Force information update legend = self.graph.getActiveCurve(just_legend=True) if legend.startswith('Filtered'): self.graph.setActiveCurve(legend)
def _pymca_SG(ydat, npoints=3, degree=1, order=0): """call to symmetric Savitzky-Golay filter in PyMca Parameters ---------- ydat : 1D array contaning the data to smooth npoints : integer [3], means that 2*npoints+1 values contribute to the smoother. degree : degree of fitting polynomial order : is degree of implicit differentiation 0 means that filter results in smoothing of function 1 means that filter results in smoothing the first derivative of function. and so on ... Returns ------- ys : smoothed array """ if HAS_SGMODULE: return SGModule.getSavitzkyGolay(ydat, npoints=npoints, degree=degree, order=order) else: raise NameError( "SGModule is not available -- this operation cannot be performed!")
def estimateXANESEdge(spectrum, energy=None, full=False): if energy is None: x = numpy.arange(len(spectrum)).astype(numpy.float) else: x = numpy.array(energy, dtype=numpy.float, copy=True) y = numpy.array(spectrum, dtype=numpy.float, copy=True) # make sure data are sorted idx = energy.argsort(kind='mergesort') x = numpy.take(energy, idx) y = numpy.take(spectrum, idx) # make sure data are strictly increasing delta = x[1:] - x[:-1] dmin = delta.min() dmax = delta.max() if delta.min() <= 1.0e-10: # force data are strictly increasing # although we do not consider last point idx = numpy.nonzero(delta>0)[0] x = numpy.take(x, idx) y = numpy.take(y, idx) delta = None sortedX = x sortedY = y # use a regularly spaced spectrum if dmax != dmin: # choose the number of points or deduce it from # the input data length? nchannels = 2 * len(spectrum) xi = numpy.linspace(x[1], x[-2], nchannels).reshape(-1, 1) x.shape = -1 y.shape = -1 y = SpecfitFuns.interpol([x], y, xi, y.min()) x = xi x.shape = -1 y.shape = -1 # take the first derivative npoints = 7 xPrime = x[npoints:-npoints] yPrime = SGModule.getSavitzkyGolay(y, npoints=npoints, degree=2, order=1) # get the index at maximum value iMax = numpy.argmax(yPrime) # get the center of mass w = 2 * npoints selection = yPrime[iMax-w:iMax+w+1] edge = (selection * xPrime[iMax-w:iMax+w+1]).sum(dtype=numpy.float)/\ selection.sum(dtype=numpy.float) if full: # return intermediate information return edge, sortedX, sortedY, xPrime, yPrime else: # return the corresponding x value return edge
def estimateXANESEdge(spectrum, energy=None, full=False): if energy is None: x = numpy.arange(len(spectrum)).astype(numpy.float) else: x = numpy.array(energy, dtype=numpy.float, copy=True) y = numpy.array(spectrum, dtype=numpy.float, copy=True) # make sure data are sorted idx = energy.argsort(kind='mergesort') x = numpy.take(energy, idx) y = numpy.take(spectrum, idx) # make sure data are strictly increasing delta = x[1:] - x[:-1] dmin = delta.min() dmax = delta.max() if delta.min() <= 1.0e-10: # force data are strictly increasing # although we do not consider last point idx = numpy.nonzero(delta > 0)[0] x = numpy.take(x, idx) y = numpy.take(y, idx) delta = None sortedX = x sortedY = y # use a regularly spaced spectrum if dmax != dmin: # choose the number of points or deduce it from # the input data length? nchannels = 2 * len(spectrum) xi = numpy.linspace(x[1], x[-2], nchannels).reshape(-1, 1) x.shape = -1 y.shape = -1 y = SpecfitFuns.interpol([x], y, xi, y.min()) x = xi x.shape = -1 y.shape = -1 # take the first derivative npoints = 7 xPrime = x[npoints:-npoints] yPrime = SGModule.getSavitzkyGolay(y, npoints=npoints, degree=2, order=1) # get the index at maximum value iMax = numpy.argmax(yPrime) # get the center of mass w = 2 * npoints selection = yPrime[iMax - w:iMax + w + 1] edge = (selection * xPrime[iMax-w:iMax+w+1]).sum(dtype=numpy.float)/\ selection.sum(dtype=numpy.float) if full: # return intermediate information return edge, sortedX, sortedY, xPrime, yPrime else: # return the corresponding x value return edge
def getE0SavitzkyGolay(energy, mu, points=5, full=False): # It does not check anything, data have to be prepared before!!! # take the first derivative yPrime = SGModule.getSavitzkyGolay(mu, npoints=points, degree=2, order=1) xPrime = energy[:] # get the index at maximum value iMax = numpy.argmax(yPrime) # get the center of mass w = points selection = yPrime[iMax - w : iMax + w + 1] edge = (selection * xPrime[iMax - w : iMax + w + 1]).sum(dtype=numpy.float) / selection.sum(dtype=numpy.float) if full: # return intermediate information return {"edge": edge, "iMax": iMax, "xPrime": xPrime, "yPrime": yPrime} else: # return the corresponding x value return edge
def updateGraph(self, ddict): points = ddict['points'] degree = ddict['degree'] order = ddict['order'] self.background = SGModule.getSavitzkyGolay(self.spectrum, points, degree=degree, order=order) if order > 0: maptoy2 = True else: maptoy2 = False self.graph.newCurve(self.xValues, self.background, "Filtered Spectrum", replace=False, maptoy2=maptoy2) #Force information update legend = self.graph.getActiveCurve(just_legend=True) if legend.startswith('Filtered'): self.graph.setActiveCurve(legend)
def updateGraph(self, ddict): points = ddict['points'] degree = ddict['degree'] order = ddict['order'] self.background = SGModule.getSavitzkyGolay(self.spectrum, points, degree=degree, order=order) if order > 0: yaxis = "right" else: yaxis = "left" self.graph.addCurve(self.xValues, self.background, "Filtered Spectrum", replace=False, yaxis=yaxis) #Force information update legend = self.graph.getActiveCurve(just_legend=True) if legend.startswith('Filtered'): self.graph.setActiveCurve(legend)
def _pymca_SG(ydat, npoints=3, degree=1, order=0): """call to symmetric Savitzky-Golay filter in PyMca Parameters ---------- ydat : 1D array contaning the data to smooth npoints : integer [3], means that 2*npoints+1 values contribute to the smoother. degree : degree of fitting polynomial order : is degree of implicit differentiation 0 means that filter results in smoothing of function 1 means that filter results in smoothing the first derivative of function. and so on ... Returns ------- ys : smoothed array """ if HAS_SGMODULE: return SGModule.getSavitzkyGolay(ydat, npoints=npoints, degree=degree, order=order) else: raise NameError("SGModule is not available -- this operation cannot be performed!")
def getE0SavitzkyGolay(energy, mu, points=5, full=False): # It does not check anything, data have to be prepared before!!! # take the first derivative yPrime = SGModule.getSavitzkyGolay(mu, npoints=points, degree=2, order=1) xPrime = energy[:] # get the index at maximum value iMax = numpy.argmax(yPrime) # get the center of mass w = points selection = yPrime[iMax-w:iMax+w+1] edge = (selection * xPrime[iMax-w:iMax+w+1]).sum(dtype=numpy.float64)/\ selection.sum(dtype=numpy.float64) if full: # return intermediate information return {"edge":edge, "iMax": iMax, "xPrime": xPrime, "yPrime": yPrime} else: # return the corresponding x value return edge