コード例 #1
0
 def _getSmooth(self, x, y): 
     f=[0.25,0.5,0.25]
     try:
         if hasattr(y, "shape"):
             if len(y.shape) > 1:
                 result=SpecfitFuns.SavitskyGolay(numpy.ravel(y).astype(numpy.float), 
                                 self._fitConfiguration['fit']['stripfilterwidth'])
             else:                                
                 result=SpecfitFuns.SavitskyGolay(numpy.array(y).astype(numpy.float), 
                                 self._fitConfiguration['fit']['stripfilterwidth'])
         else:
             result=SpecfitFuns.SavitskyGolay(numpy.array(y).astype(numpy.float),
                                 self._fitConfiguration['fit']['stripfilterwidth'])
     except:
         err = sys.exc_info()[1]
         raise ValueError("Unsuccessful Savitsky-Golay smoothing: %s" % err)
         result=numpy.array(y).astype(numpy.float)
     if len(result) > 1:
         result[1:-1]=numpy.convolve(result,f,mode=0)
         result[0]=0.5*(result[0]+result[1])
         result[-1]=0.5*(result[-1]+result[-2])
     return result
コード例 #2
0
    def update(self):
        if self._y is None:
            return

        pars = self.getParameters()

        #smoothed data
        y = numpy.ravel(numpy.array(self._y)).astype(numpy.float)
        ysmooth = SpecfitFuns.SavitskyGolay(y, pars['stripfilterwidth'])
        f = [0.25, 0.5, 0.25]
        ysmooth[1:-1] = numpy.convolve(ysmooth, f, mode=0)
        ysmooth[0] = 0.5 * (ysmooth[0] + ysmooth[1])
        ysmooth[-1] = 0.5 * (ysmooth[-1] + ysmooth[-2])

        #loop for anchors
        x = self._x
        niter = pars['stripiterations']
        anchorslist = []
        if pars['stripanchorsflag']:
            if pars['stripanchorslist'] is not None:
                ravelled = x
                for channel in pars['stripanchorslist']:
                    if channel <= ravelled[0]: continue
                    index = numpy.nonzero(ravelled >= channel)[0]
                    if len(index):
                        index = min(index)
                        if index > 0:
                            anchorslist.append(index)
        if niter > 1000:
            stripBackground = SpecfitFuns.subac(ysmooth, pars['stripconstant'],
                                                niter, pars['stripwidth'],
                                                anchorslist)
            #final smoothing
            stripBackground = SpecfitFuns.subac(stripBackground,
                                                pars['stripconstant'], 500, 1,
                                                anchorslist)
        elif niter > 0:
            stripBackground = SpecfitFuns.subac(ysmooth, pars['stripconstant'],
                                                niter, pars['stripwidth'],
                                                anchorslist)
        else:
            stripBackground = 0.0 * ysmooth + ysmooth.min()

        if len(anchorslist) == 0:
            anchorslist = [0, len(ysmooth) - 1]
        anchorslist.sort()
        snipBackground = 0.0 * ysmooth
        lastAnchor = 0
        width = pars['snipwidth']
        for anchor in anchorslist:
            if (anchor > lastAnchor) and (anchor < len(ysmooth)):
                snipBackground[lastAnchor:anchor] =\
                            SpecfitFuns.snip1d(ysmooth[lastAnchor:anchor], width, 0)
                lastAnchor = anchor
        if lastAnchor < len(ysmooth):
            snipBackground[lastAnchor:] =\
                            SpecfitFuns.snip1d(ysmooth[lastAnchor:], width, 0)

        self.graphWidget.addCurve(x, y, \
                                  legend='Input Data',\
                                  replace=True,
                                  replot=False)
        self.graphWidget.addCurve(x, stripBackground,\
                                  legend='Strip Background',\
                                  replot=False)
        self.graphWidget.addCurve(x, snipBackground,\
                                  legend='SNIP Background',
                                  replot=True)