示例#1
0
 def derivate(self,xdata,ydata, xlimits=None):
     x=numpy.array(xdata, copy=False, dtype=numpy.float)
     y=numpy.array(ydata, copy=False, dtype=numpy.float)
     if xlimits is not None:
         i1=numpy.nonzero((xdata>=xlimits[0])&\
                            (xdata<=xlimits[1]))[0]
         x=numpy.take(x,i1)
         y=numpy.take(y,i1)
     i1 = numpy.argsort(x)
     x=numpy.take(x,i1)
     y=numpy.take(y,i1)  
     deltax=x[1:] - x[:-1]
     i1=numpy.nonzero(abs(deltax)>0.0000001)[0]
     x=numpy.take(x, i1)
     y=numpy.take(y, i1)
     minDelta = deltax.min()
     xInter = numpy.arange(x[0]-minDelta,x[-1]+minDelta,minDelta)
     yInter = numpy.interp(xInter, x, y, left=y[0], right=y[-1])
     if len(yInter) > 499:
         npoints = 5
     else:
         npoints = 3
     degree = 1
     order = 1
     coeff = SGModule.calc_coeff(npoints, degree, order)
     N = int(numpy.size(coeff-1)/2)
     yInterPrime = numpy.convolve(yInter, coeff, mode='valid')/minDelta
     i1 = numpy.nonzero((x>=xInter[N+1]) & (x <= xInter[-N]))[0]
     x = numpy.take(x, i1)
     result = numpy.interp(x, xInter[(N+1):-N],
                           yInterPrime[1:],
                           left=yInterPrime[1],
                           right=yInterPrime[-1])
     return x, result