Example #1
0
 def testOnes(self):  # make new datasets with ones
     print("test ones")
     dds = np.ones(3, dtype=np.float)
     if isjava:
         self.assertEqual(1, dds.dtype.elements)
     self.assertEqual(1, dds.ndim)
     self.assertEqual(3, dds.shape[0])
     self.assertEqual(1, dds[0])
     dds = np.ones((2, 3), np.float)
     if isjava:
         self.assertEqual(1, dds.dtype.elements)
     self.assertEqual(2, dds.ndim)
     self.assertEqual(2, dds.shape[0])
     self.assertEqual(3, dds.shape[1])
     self.assertEqual(1, dds[0, 0])
     dds = np.ones_like(dds)
     if isjava:
         self.assertEqual(1, dds.dtype.elements)
     self.assertEqual(2, dds.ndim)
     self.assertEqual(2, dds.shape[0])
     self.assertEqual(3, dds.shape[1])
     self.assertEqual(1, dds[0, 0])
     dds = np.ones(np.array([1, 2]), dtype=np.float)
     self.assertEqual((1, 2), dds.shape)
     self.assertEqual(1, dds[0, 0])
     dds = np.ones_like(np.array([1, 2]), dtype=np.float)
     self.assertEqual((2, ), dds.shape)
     self.assertEqual(1, dds[0])
Example #2
0
 def testOnes(self): # make new datasets with ones
     print("test ones")
     dds = np.ones(3, dtype=np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(1, dds.ndim)
     self.assertEquals(3, dds.shape[0])
     self.assertEquals(1, dds[0])
     dds = np.ones((2,3), np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(1, dds[0,0])
     dds = np.ones_like(dds)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(1, dds[0,0])
     dds = np.ones(np.array([1,2]), dtype=np.float)
     self.assertEqual((1,2), dds.shape)
     self.assertEquals(1, dds[0,0])
     dds = np.ones_like(np.array([1,2]), dtype=np.float)
     self.assertEquals((2,), dds.shape)
     self.assertEquals(1, dds[0])
Example #3
0
 def testOnes(self): # make new datasets with ones
     print "test ones"
     dds = np.ones(3, np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(1, dds.ndim)
     self.assertEquals(3, dds.shape[0])
     self.assertEquals(1, dds[0])
     dds = np.ones((2,3), np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(1, dds[0,0])
Example #4
0
 def testScisoft(self):
     a = np.ones([3,4])
     print(a.shape)
     a.shape = [2,6]
     print(a.shape)
     a.shape = 12
     print(a.shape)
     a.shape = (2,6)
     print(a.shape)
     print(a)
     print(a*2)
     b = np.arange(12)
     print(b)
     print(b[0])
     b[2] = 2.3
     print(b[1:8:3])
     b[6:2:-1] = -2.1
     b.shape = [2,6]
     print(b + 2)
     print(2 + b)
     b += 2
     print(b[1,3])
     b[0,5] = -2.3
     print(b[0,2:5])
     b[:,1] = -7.1
     print(b)
     try:
         c = np.add(a, b)
         print(c)
     except:
         print("Failed with an IAE as expected")
Example #5
0
 def testScisoft(self):
     a = np.ones([3,4])
     print a.shape
     a.shape = [2,6]
     print a.shape
     a.shape = 12
     print a.shape
     a.shape = (2,6)
     print a.shape
     print a
     print a*2
     b = np.arange(12)
     print b
     print b[0]
     b[2] = 2.3
     print b[1:8:3]
     b[6:2:-1] = -2.1
     b.shape = [2,6]
     print b + 2
     print 2 + b
     b += 2.
     print b[1,3]
     b[0,5] = -2.3
     print b[0,2:5]
     b[:,1] = -7.1
     print b
     try:
         c = np.add(a, b)
         print c
     except:
         print "Failed with an IAE as expected"
Example #6
0
    def testStack(self):
        print 'Stack testing'
        self.checkitems([1,1,1], np.hstack(np.ones(3)))
        self.checkitems([[1],[1],[1]], np.vstack(np.ones(3)))
        self.checkitems([[[1,1,1]]], np.dstack(np.ones(3)))

        a = np.array([1,2,3])
        b = np.array([2,3,4])
        self.checkitems([1,2,3,2,3,4], np.hstack((a, b)))
        self.checkitems([[1,2], [2,3], [3,4]], np.hstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[1,2,3],[2,3,4]], np.vstack((a, b)))
        self.checkitems([[1], [2], [3], [2], [3], [4]], np.vstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[[1,2], [2,3], [3,4]]], np.dstack((a, b)))
        self.checkitems([[[1,2]], [[2,3]], [[3,4]]], np.dstack((a.reshape(3,1), b.reshape(3,1))))
Example #7
0
    def testStack(self):
        print 'Stack testing'
        self.checkitems([1,1,1], np.hstack(np.ones(3)))
        self.checkitems([[1],[1],[1]], np.vstack(np.ones(3)))
        self.checkitems([[[1,1,1]]], np.dstack(np.ones(3)))

        a = np.array([1,2,3])
        b = np.array([2,3,4])
        self.checkitems([1,2,3,2,3,4], np.hstack((a, b)))
        self.checkitems([[1,2], [2,3], [3,4]], np.hstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[1,2,3],[2,3,4]], np.vstack((a, b)))
        self.checkitems([[1], [2], [3], [2], [3], [4]], np.vstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[[1,2], [2,3], [3,4]]], np.dstack((a, b)))
        self.checkitems([[[1,2]], [[2,3]], [[3,4]]], np.dstack((a.reshape(3,1), b.reshape(3,1))))
Example #8
0
 def testScisoft(self):
     a = np.ones([3, 4])
     print a.shape
     a.shape = [2, 6]
     print a.shape
     a.shape = 12
     print a.shape
     a.shape = (2, 6)
     print a.shape
     print a
     print a * 2
     b = np.arange(12)
     print b
     print b[0]
     b[2] = 2.3
     print b[1:8:3]
     b[6:2:-1] = -2.1
     b.shape = [2, 6]
     print b + 2
     print 2 + b
     b += 2.
     print b[1, 3]
     b[0, 5] = -2.3
     print b[0, 2:5]
     b[:, 1] = -7.1
     print b
     try:
         c = np.add(a, b)
         print c
     except:
         print "Failed with an IAE as expected"
Example #9
0
 def testScisoft(self):
     a = np.ones([3, 4])
     print(a.shape)
     a.shape = [2, 6]
     print(a.shape)
     a.shape = 12
     print(a.shape)
     a.shape = (2, 6)
     print(a.shape)
     print(a)
     print(a * 2)
     b = np.arange(12)
     print(b)
     print(b[0])
     b[2] = 2.3
     print(b[1:8:3])
     b[6:2:-1] = -2.1
     b.shape = [2, 6]
     print(b + 2)
     print(2 + b)
     b += 2
     print(b[1, 3])
     b[0, 5] = -2.3
     print(b[0, 2:5])
     b[:, 1] = -7.1
     print(b)
     try:
         c = np.add(a, b)
         print(c)
     except:
         print("Failed with an IAE as expected")
Example #10
0
 def testSaveArgs(self):
     self.checkArgs(None)
     self.checkArgs(([None, None], [None,]))
     self.checkArgs(([None, 1, 1.5], [None,]))
     self.checkArgs(([None, 1, 1.5], (None,)))
     self.checkArgs(([None, 1, 1.5], dnp.arange(12)))
     self.checkArgs(([None, 1, 1.5], {'blah':dnp.arange(12), 'foo': dnp.ones((3,4)), 'boo': -2.345}))
Example #11
0
    def testStack(self):
        print('Stack testing')
        self.checkitems([1,1,1], np.hstack(np.ones(3)))
        self.checkitems([[1],[1],[1]], np.vstack(np.ones(3)))
        self.checkitems([[[1,1,1]]], np.dstack(np.ones(3)))

        a = np.array([1,2,3])
        b = np.array([2,3,4])
        self.checkitems([1,2,3,2,3,4], np.hstack((a, b)))
        self.checkitems([[1,2], [2,3], [3,4]], np.hstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[1,2,3],[2,3,4]], np.vstack((a, b)))
        self.checkitems([[1], [2], [3], [2], [3], [4]], np.vstack((a.reshape(3,1), b.reshape(3,1))))

        self.checkitems([[[1,2], [2,3], [3,4]]], np.dstack((a, b)))
        self.checkitems([[[1,2]], [[2,3]], [[3,4]]], np.dstack((a.reshape(3,1), b.reshape(3,1))))
        self.checkitems([[1,2], [2,3], [3,4]], np.column_stack((a, b)))
        self.checkitems([[1,2, 0, 1, 2], [2,3, 3, 4, 5], [3,4, 6, 7, 8]], np.column_stack((a, b, np.arange(9).reshape(3,3))))
Example #12
0
    def testStack(self):
        print('Stack testing')
        self.checkitems([1, 1, 1], np.hstack(np.ones(3)))
        self.checkitems([[1], [1], [1]], np.vstack(np.ones(3)))
        self.checkitems([[[1, 1, 1]]], np.dstack(np.ones(3)))

        a = np.array([1, 2, 3])
        b = np.array([2, 3, 4])
        self.checkitems([1, 2, 3, 2, 3, 4], np.hstack((a, b)))
        self.checkitems([[1, 2], [2, 3], [3, 4]],
                        np.hstack((a.reshape(3, 1), b.reshape(3, 1))))

        self.checkitems([[1, 2, 3], [2, 3, 4]], np.vstack((a, b)))
        self.checkitems([[1], [2], [3], [2], [3], [4]],
                        np.vstack((a.reshape(3, 1), b.reshape(3, 1))))

        self.checkitems([[[1, 2], [2, 3], [3, 4]]], np.dstack((a, b)))
        self.checkitems([[[1, 2]], [[2, 3]], [[3, 4]]],
                        np.dstack((a.reshape(3, 1), b.reshape(3, 1))))
        self.checkitems([[1, 2], [2, 3], [3, 4]], np.column_stack((a, b)))
        self.checkitems([[1, 2, 0, 1, 2], [2, 3, 3, 4, 5], [3, 4, 6, 7, 8]],
                        np.column_stack((a, b, np.arange(9).reshape(3, 3))))
Example #13
0
 def testOnes(self):  # make new datasets with ones
     print "test ones"
     dds = np.ones(3, dtype=np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(1, dds.ndim)
     self.assertEquals(3, dds.shape[0])
     self.assertEquals(1, dds[0])
     dds = np.ones((2, 3), np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(1, dds[0, 0])
     dds = np.ones_like(dds)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(1, dds[0, 0])
Example #14
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
Example #15
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
Example #16
0
	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
Example #17
0
 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
Example #18
0
    def testRandom(self):
        import os
        if os.name == 'java':
            import jarray
            ja = jarray.array([1, 2], 'i')
        else:
            ja = np.array([1, 2])
        print np.asIterable(ja)

        print rnd.rand()
        print rnd.rand(1)
        print rnd.rand(2, 4)
        print rnd.randn()
        print rnd.randn(1)
        print rnd.randn(2, 4)
        for i in range(10):
            print i, rnd.randint(1)
        print rnd.randint(2)
        print rnd.randint(5, size=[2, 4])
        print rnd.random_integers(1)
        print rnd.random_integers(5, size=[2, 4])
        print rnd.exponential(1.1)
        print rnd.exponential(1.1, [2, 4])
        print rnd.poisson(1.1)
        print rnd.poisson(1.1, [2, 4])
        a = np.ones([2, 3])
        print rnd.poisson(1.2, a.shape)
        rnd.seed()
        print rnd.rand(2, 3)
        rnd.seed()
        print rnd.rand(2, 3)
        rnd.seed(12343)
        print rnd.rand(2, 3)
        rnd.seed(12343)
        print rnd.rand(2, 3)
        a = rnd.rand(200, 300)
        print a.mean(), a.std()
Example #19
0
    def testRandom(self):
        import os
        if os.name == 'java':
            import jarray
            ja = jarray.array([1,2], 'i')
        else:
            ja = np.array([1,2])
        print np.asIterable(ja)

        print rnd.rand()
        print rnd.rand(1)
        print rnd.rand(2,4)
        print rnd.randn()
        print rnd.randn(1)
        print rnd.randn(2,4)
        for i in range(10):
            print i, rnd.randint(1)
        print rnd.randint(2)
        print rnd.randint(5, size=[2,4])
        print rnd.random_integers(1)
        print rnd.random_integers(5, size=[2,4])
        print rnd.exponential(1.1)
        print rnd.exponential(1.1, [2,4])
        print rnd.poisson(1.1)
        print rnd.poisson(1.1, [2,4])
        a = np.ones([2,3])
        print rnd.poisson(1.2, a.shape)
        rnd.seed()
        print rnd.rand(2,3)
        rnd.seed()
        print rnd.rand(2,3)
        rnd.seed(12343)
        print rnd.rand(2,3)
        rnd.seed(12343)
        print rnd.rand(2,3)
        a = rnd.rand(200,300)
        print a.mean(), a.std()