示例#1
0
 def testSums(self):
     print 'test sum'
     ds = np.arange(12).reshape((3,4))
     self.assertEquals(np.sum(ds), 66)
     self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
     self.checkitems([ 6, 22, 38], np.sum(ds, 1))
     
     print 'test cumsum'
     self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66], np.cumsum(ds))
     self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]], np.cumsum(ds, 0))
     self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]], np.cumsum(ds, 1))
示例#2
0
    def testSums(self):
        print 'test sum'
        ds = np.arange(12).reshape((3,4))
        self.assertEquals(np.sum(ds), 66)
        self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
        self.checkitems([ 6, 22, 38], np.sum(ds, 1))
        lds = np.arange(1024*1024, dtype=np.int32)
        self.assertEquals(np.sum(lds, dtype=np.int32), -524288)
        self.assertEquals(np.sum(lds, dtype=np.int64), 549755289600)

        print 'test cumsum'
        self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66], np.cumsum(ds))
        self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]], np.cumsum(ds, 0))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]], np.cumsum(ds, 1))
示例#3
0
def simpleFitGaussian(data, x=None, plotPanel=None):
	if x is None:
		x=dnp.arange(data.size)

	mu=sum(x*data)/sum(data)
	sigma = math.sqrt(abs(dnp.sum((x-mu)**2*data)/dnp.sum(data)))
	peak=data.max();
	area=sum(data);
    
	if plotPanel is not None:
		print("To plot the fitted data")
		y1=myGaussianFunc(mu, sigma, peak, [x]);
		dnp.plot.line(x, [data, y1] ) # plot line of evaluated function

	return [mu, sigma, peak, area]
示例#4
0
    def testSums(self):
        print 'test sum'
        ds = np.arange(12).reshape((3, 4))
        self.assertEquals(ds.sum(), 66)
        self.assertEquals(np.sum(ds), 66)
        self.checkitems([12, 15, 18, 21], ds.sum(0))
        self.checkitems([12, 15, 18, 21], ds.sum(-2))
        self.checkitems([12, 15, 18, 21], np.sum(ds, 0))
        self.checkitems([12, 15, 18, 21], np.sum(ds, -2))
        self.checkitems([6, 22, 38], ds.sum(1))
        self.checkitems([6, 22, 38], ds.sum(-1))
        self.checkitems([6, 22, 38], np.sum(ds, 1))
        self.checkitems([6, 22, 38], np.sum(ds, -1))
        lds = np.arange(1024 * 1024, dtype=np.int32)
        self.assertEquals(np.sum(lds, dtype=np.int32), -524288)
        self.assertEquals(np.sum(lds, dtype=np.int64), 549755289600)

        print 'test cumsum'
        self.checkitems([0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66],
                        np.cumsum(ds))
        self.checkitems([[0, 1, 2, 3], [4, 6, 8, 10], [12, 15, 18, 21]],
                        np.cumsum(ds, 0))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]],
                        np.cumsum(ds, 1))
        self.checkitems([[0, 1, 3, 6], [4, 9, 15, 22], [8, 17, 27, 38]],
                        np.cumsum(ds, -1))
def scan_temps(start,stop,step,fwhm):
	fg.setParameterValues(0.1,start,0,1,0,fwhm)
	test = fg.calculateValues([x])
	temps = dnp.arange(start,stop,step)
	result = dnp.zeros(temps.shape)
	count = 0
	for temp in temps:
		fg.setParameterValues(0.1,temp,0,1,0,0.0)
		comp = fg.calculateValues([x])
		result[count] = dnp.sum(dnp.square(dnp.array(test)-dnp.array(comp)))
		count+=1
	dnp.plot.line(temps,result)
	return temps[result.minPos().tolist()]
def scan_temps(start, stop, step, fwhm):
    fg.setParameterValues(0.1, start, 0, 1, 0, fwhm)
    test = fg.calculateValues([x])
    temps = dnp.arange(start, stop, step)
    result = dnp.zeros(temps.shape)
    count = 0
    for temp in temps:
        fg.setParameterValues(0.1, temp, 0, 1, 0, 0.0)
        comp = fg.calculateValues([x])
        result[count] = dnp.sum(dnp.square(dnp.array(test) - dnp.array(comp)))
        count += 1
    dnp.plot.line(temps, result)
    return temps[result.minPos().tolist()]
示例#7
0
 def testSum(self):
     a = dnp.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
     self.assertEqual(dnp.sum(a, keepdims=True).shape, (1, 1, 1))
     self.checkitems(dnp.sum(a, keepdims=True), dnp.array([[[36]]]))
示例#8
0
 def testSum(self):
     a = dnp.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
     self.assertEquals(dnp.sum(a, keepdims=True).shape, (1, 1, 1))
     self.checkitems(dnp.sum(a, keepdims=True), dnp.array([[[36]]]))