def testGradient(self): print "Gradient testing" x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x) self.checkitems([1.0, 1.5, 2.5, 3.5, 4.5, 5.0], g) g = np.gradient(x, 2) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) a = np.arange(6, dtype=np.float) * 2 g = np.gradient(x, a) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) self.checkitems([[2.0, 2.0, -1.0], [2.0, 2.0, -1.0]], g[0]) self.checkitems([[1.0, 2.5, 4.0], [1.0, 1.0, 1.0]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2) self.checkitems([[1.0, 1.0, -0.5], [1.0, 1.0, -0.5]], g[0]) self.checkitems([[0.5, 1.25, 2.0], [0.5, 0.5, 0.5]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2, 1) self.checkitems([[1.0, 1.0, -0.5], [1.0, 1.0, -0.5]], g[0]) self.checkitems([[1.0, 2.5, 4.0], [1.0, 1.0, 1.0]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 1, np.array([1.0, 2.0, 5.0])) self.checkitems([[2.0, 2.0, -1.0], [2.0, 2.0, -1.0]], g[0]) self.checkitems([[1.0, 1.25, 4.0 / 3], [1.0, 0.5, 1.0 / 3]], g[1]) # test slice views x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x[2:]) self.checkitems([3, 3.5, 4.5, 5.0], g)
def testGradient(self): print 'Gradient testing' x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x) self.checkitems([1., 1.5, 2.5, 3.5, 4.5, 5.], g) g = np.gradient(x, 2) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) a = np.arange(6, dtype=np.float) * 2 g = np.gradient(x, a) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[0.5, 1.25, 2.], [0.5, 0.5, 0.5]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2, 1) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 1, np.array([1., 2., 5.])) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 1.25, 4. / 3], [1., 0.5, 1. / 3]], g[1]) # test slice views x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x[2:]) self.checkitems([3, 3.5, 4.5, 5.], g)
def testGradient(self): print 'Gradient testing' z = np.arange(200.) dz = np.gradient(z) self.assertEquals(1, len(dz.shape)) self.assertEquals(200, dz.size) self.assertEquals(1, dz[0])
def testGradient(self): print "Gradient testing" z = np.arange(200.0) dz = np.gradient(z) self.assertEquals(1, len(dz.shape)) self.assertEquals(200, dz.size) self.assertEquals(1, dz[0])
def baseline(self,xdataset, ydataset, smoothness): '''find the baseline y value for a peak in y dataset''' ymaxindex=ydataset.argMax() if smoothness > 1: wnd = dnp.ones(smoothness, dtype=dnp.float64)/smoothness ydataset = dnp.convolve(ydataset, wnd, 'same') result=dnp.gradient(ydataset, xdataset) leftresult=result[:ymaxindex] rightresult=result[ymaxindex+1:] leftminderivativeindex=dnp.abs(leftresult).argmin() rightminderivativeindex=dnp.abs(rightresult).argmin() leftbasey=ydataset.getElementDoubleAbs(leftminderivativeindex) rightbasey=ydataset.getElementDoubleAbs(rightminderivativeindex+1+leftresult.shape[0]) basey=(leftbasey+rightbasey)/2 return basey
def baseline(self, xdataset, ydataset, smoothness): '''find the baseline y value for a peak in y dataset''' ymaxindex = ydataset.argMax() if smoothness > 1: wnd = dnp.ones(smoothness, dtype=dnp.float64) / smoothness ydataset = dnp.convolve(ydataset, wnd, 'same') result = dnp.gradient(ydataset, xdataset) leftresult = result[:ymaxindex] rightresult = result[ymaxindex + 1:] leftminderivativeindex = dnp.abs(leftresult).argmin() rightminderivativeindex = dnp.abs(rightresult).argmin() leftbasey = ydataset.getElementDoubleAbs(leftminderivativeindex) rightbasey = ydataset.getElementDoubleAbs(rightminderivativeindex + 1 + leftresult.shape[0]) basey = (leftbasey + rightbasey) / 2 return basey
def baseline(self,xdataset, ydataset, smoothness): '''find the baseline y value for a peak in y dataset''' xdataset = dnp.asarray(xdataset) ydataset = dnp.asarray(ydataset) ymaxindex=ydataset.argmax() #TODO result=dnp.gradient(ydataset,xdataset) #derivative(xdataset, ydataset, smoothness) leftresult=result[:ymaxindex] rightresult=result[ymaxindex+1:] leftminderivativeindex=dnp.abs(leftresult).argmin() rightminderivativeindex=dnp.abs(rightresult).argmin() leftbasey=ydataset[leftminderivativeindex] rightbasey=ydataset[rightminderivativeindex+1+leftresult.shape[0]] basey=(leftbasey+rightbasey)/2 return basey
def baseline(self, xdataset, ydataset, smoothness): '''find the baseline y value for a peak in y dataset''' xdataset = dnp.asarray(xdataset) ydataset = dnp.asarray(ydataset) ymaxindex = ydataset.argmax() #TODO result = dnp.gradient(ydataset, xdataset) #derivative(xdataset, ydataset, smoothness) leftresult = result[:ymaxindex] rightresult = result[ymaxindex + 1:] leftminderivativeindex = dnp.abs(leftresult).argmin() rightminderivativeindex = dnp.abs(rightresult).argmin() leftbasey = ydataset[leftminderivativeindex] rightbasey = ydataset[rightminderivativeindex + 1 + leftresult.shape[0]] basey = (leftbasey + rightbasey) / 2 return basey
def testGradient(self): print('Gradient testing') z = np.arange(200.) dz = np.gradient(z) self.assertEqual(1, len(dz.shape)) self.assertEqual(200, dz.size) self.assertEqual(1, dz[0]) x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x) self.checkitems([1., 1.5, 2.5, 3.5, 4.5, 5.], g) g = np.gradient(x, 2) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) a = np.arange(6, dtype=np.float) * 2 g = np.gradient(x, a) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[0.5, 1.25, 2.], [0.5, 0.5, 0.5]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2, 1) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 1, np.array([1., 2., 5.])) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 1.25, 4. / 3], [1., 0.5, 1. / 3]], g[1]) # test slice views x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x[2:]) self.checkitems([3, 3.5, 4.5, 5.], g)
def testGradient(self): print 'Gradient testing' z = np.arange(200.) dz = np.gradient(z) self.assertEquals(1, len(dz.shape)) self.assertEquals(200, dz.size) self.assertEquals(1, dz[0]) x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x) self.checkitems([1., 1.5, 2.5, 3.5, 4.5, 5.], g) g = np.gradient(x, 2) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) a = np.arange(6, dtype=np.float)*2 g = np.gradient(x, a) self.checkitems([0.5, 0.75, 1.25, 1.75, 2.25, 2.5], g) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[0.5, 1.25, 2.], [0.5, 0.5, 0.5]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 2, 1) self.checkitems([[1., 1., -0.5], [1., 1., -0.5]], g[0]) self.checkitems([[1., 2.5, 4.], [1., 1., 1.]], g[1]) g = np.gradient(np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float), 1, np.array([1.,2.,5.])) self.checkitems([[2., 2., -1.], [2., 2., -1.]], g[0]) self.checkitems([[1., 1.25, 4./3], [1., 0.5, 1./3]], g[1]) # test slice views x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) g = np.gradient(x[2:]) self.checkitems([3, 3.5, 4.5, 5.], g)
def findBases(self, xdataset, ydataset, delta, smoothness): bases=[] peaks=self.findPeaksAndTroughs(ydataset, delta)[0] yslices=[] xslices=[] startindex=0 for index,value in peaks: #@UnusedVariable yslices.append(ydataset[startindex:index]) xslices.append(xdataset[startindex:index]) startindex=index+1 if smoothness > 1: wnd = dnp.ones(smoothness, dtype=dnp.float64)/smoothness for xset, yset in xslices, yslices: if smoothness > 1: yset = dnp.convolve(yset, wnd, 'same') result=dnp.gradient(yset, xset) minimumderivativeindex=dnp.abs(result).argmin() bases.append((xset[minimumderivativeindex],yset[minimumderivativeindex])) return bases
def findBases(self, xdataset, ydataset, delta, smoothness): bases = [] peaks = self.findPeaksAndTroughs(ydataset, delta)[0] yslices = [] xslices = [] startindex = 0 for index, value in peaks: #@UnusedVariable yslices.append(ydataset[startindex:index]) xslices.append(xdataset[startindex:index]) startindex = index + 1 if smoothness > 1: wnd = dnp.ones(smoothness, dtype=dnp.float64) / smoothness for xset, yset in xslices, yslices: if smoothness > 1: yset = dnp.convolve(yset, wnd, 'same') result = dnp.gradient(yset, xset) minimumderivativeindex = dnp.abs(result).argmin() bases.append( (xset[minimumderivativeindex], yset[minimumderivativeindex])) return bases
def findBasePoints(self, xdataset, ydataset, delta, smoothness): xdataset = dnp.asarray(xdataset) ydataset = dnp.asarray(ydataset) peaks=self.findPeaksAndTroughs(ydataset, delta)[0] #print peaks yslices=[] xslices=[] startindex=0 for index,value in peaks: #@UnusedVariable yslices.append(ydataset[startindex:index]) xslices.append(xdataset[startindex:index]) startindex=index+1 yslices.append(ydataset[startindex:]) xslices.append(xdataset[startindex:]) bases=[] for xset, yset in zip(xslices, yslices): result=dnp.gradient(yset, xset) minimumderivativeindex=dnp.abs(result).argmin() bases.append((xset[minimumderivativeindex],yset[minimumderivativeindex])) #print "Base Points (position, value) : ", bases return bases
def findBasePoints(self, xdataset, ydataset, delta, smoothness): xdataset = dnp.asarray(xdataset) ydataset = dnp.asarray(ydataset) peaks = self.findPeaksAndTroughs(ydataset, delta)[0] #print peaks yslices = [] xslices = [] startindex = 0 for index, value in peaks: #@UnusedVariable yslices.append(ydataset[startindex:index]) xslices.append(xdataset[startindex:index]) startindex = index + 1 yslices.append(ydataset[startindex:]) xslices.append(xdataset[startindex:]) bases = [] for xset, yset in zip(xslices, yslices): result = dnp.gradient(yset, xset) minimumderivativeindex = dnp.abs(result).argmin() bases.append( (xset[minimumderivativeindex], yset[minimumderivativeindex])) #print "Base Points (position, value) : ", bases return bases