def testCopyItems(self): if isjava: import jarray print "test copy items" da = np.array(self.db, np.float) ta = np.zeros(da.getShape()) da.copyItemsFromAxes(None, None, ta) print ta.getBuffer() ta = np.array(self.m) da.setItemsOnAxes(None, None, ta.getBuffer()) print da.getBuffer() print '2' da = np.array(self.db, np.float) ta = np.zeros((2,)) axes = [ True, False ] da.copyItemsFromAxes(None, axes, ta) print ta.getBuffer() ta = jarray.array([ -2, -3.4 ], 'd') da.setItemsOnAxes(None, axes, ta) print da.getBuffer() print '3' da = np.array(self.db, np.float) ta = np.zeros((2,)) axes = [ False, True ] da.copyItemsFromAxes(None, axes, ta) print ta.getBuffer() ta = jarray.array([ -2.5, -3.4 ], 'd') da.setItemsOnAxes(None, axes, ta) print da.getBuffer()
def testMethods(self): print('Methods testing') print(np.arange(6, dtype=np.int32)) print(np.arange(6, dtype=np.float)) a = np.array([4, 3.]) print(type(a)) print(np.sort(a, None)) self.checkitems([3., 4], np.sort(a, None)) print(a.sort()) self.checkitems([3., 4], a) a = np.array([4, 3.]) self.checkitems([1, 0], a.argsort()) self.checkitems([1, 0], np.argsort(a, None)) a = np.arange(6, dtype=np.float) print(a.take([0, 2, 4])) print(a.take([0, 2, 4], 0)) d = np.take(a, [0, 2, 4], 0) print(type(d), d) d = np.diag([0, 2, 3]) print(type(d), d) a.shape = 2, 3 self.checkitems([1, 2], a.take([1, 2])) self.checkitems([[1, 2], [4, 5]], a.take([1, 2], 1)) self.checkitems([0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5], a.repeat(2)) self.checkitems([[0, 1, 2], [0, 1, 2], [3, 4, 5], [3, 4, 5]], a.repeat(2, axis=0)) self.checkitems([[0, 0, 1, 1, 2, 2], [3, 3, 4, 4, 5, 5]], a.repeat(2, axis=1))
def testZeros(self): # make new datasets with zeros print("test zeros") dds = np.zeros(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(0, dds[0]) dds = np.zeros((2, 3), dtype=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(0, dds[0, 0]) dds = np.zeros_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(0, dds[0, 0]) dds = np.zeros(np.array([1, 2]), dtype=np.float) self.assertEqual((1, 2), dds.shape) self.assertEqual(0, dds[0, 0]) dds = np.zeros_like(np.array([1, 2]), dtype=np.float) self.assertEqual((2, ), dds.shape) self.assertEqual(0, dds[0])
def testCopyItems(self): if isjava: import jarray print "test copy items" da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros(da.shape) jda.copyItemsFromAxes(None, None, ta._jdataset()) print ta.data ta = np.array(self.m) jda.setItemsOnAxes(None, None, ta.data) print da.data print '2' da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros((2, )) axes = [True, False] jda.copyItemsFromAxes(None, axes, ta._jdataset()) print ta.data ta = jarray.array([-2, -3.4], 'd') jda.setItemsOnAxes(None, axes, ta) print da.data print '3' da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros((2, )) axes = [False, True] jda.copyItemsFromAxes(None, axes, ta._jdataset()) print ta.data ta = jarray.array([-2.5, -3.4], 'd') jda.setItemsOnAxes(None, axes, ta) print da.data
def testCopyItems(self): if isjava: import jarray print "test copy items" da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros(da.shape) jda.copyItemsFromAxes(None, None, ta._jdataset()) print ta.data ta = np.array(self.m) jda.setItemsOnAxes(None, None, ta.data) print da.data print '2' da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros((2,)) axes = [ True, False ] jda.copyItemsFromAxes(None, axes, ta._jdataset()) print ta.data ta = jarray.array([ -2, -3.4 ], 'd') jda.setItemsOnAxes(None, axes, ta) print da.data print '3' da = np.array(self.db, np.float) jda = da._jdataset() ta = np.zeros((2,)) axes = [ False, True ] jda.copyItemsFromAxes(None, axes, ta._jdataset()) print ta.data ta = jarray.array([ -2.5, -3.4 ], 'd') jda.setItemsOnAxes(None, axes, ta) print da.data
def testAmin(self): a = dnp.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) self.assertEqual(dnp.amin(a, axis=(0, 1)).shape, (2, )) self.assertEqual( dnp.amin(a, axis=(0, 1), keepdims=True).shape, (1, 1, 2)) self.checkitems(dnp.amin(a, axis=(0, 1), keepdims=True), dnp.array([[[1, 2]]]))
def tensor_product(self, other): if isinstance(other, Vector): other = dnp.array([[other.x], [other.y], [other.z]]) other = dnp.transpose(other) vector = dnp.array([[self.x], [self.y], [self.z]]) M = dnp.dot(vector, other) return M
def testHistogramdd(self): print('Histogramdd testing') h, (v, w) = np.histogramdd(np.column_stack( (np.array([1, 2, 1, 0]), np.array([2, 3, 1, 3]))), bins=[[0, 1, 2], [2, 3, 4]]) self.checkitems([[0, 1], [1, 1]], h) self.checkitems([0, 1, 2], v) self.checkitems([2, 3, 4], w) h, (v, w) = np.histogramdd(np.array([[0, 1, 2, 1], [2, 3, 1, 3]]).T, bins=2) self.checkitems([[0, 1], [1, 2]], h) self.checkitems([0, 1, 2], v) self.checkitems([1, 2, 3], w) h, (v, w) = np.histogramdd(np.array([[0, 1, 2, 1], [2, 3, 1, 3]]).T, bins=2, weights=np.full(4, 0.25)) self.checkitems([[0, 0.25], [0.25, 0.5]], h) self.checkitems([0, 1, 2], v) self.checkitems([1, 2, 3], w) h, (v, w) = np.histogramdd(np.column_stack( (np.arange(4), np.arange(1, 5))), bins=4, range=[[0, 4], [1, 5]]) self.checkitems([1, 1, 1, 1], np.array([h[i, i] for i in range(len(h))])) self.checkitems([0, 1, 2, 3, 4], v) self.checkitems([1, 2, 3, 4, 5], w)
def testMethods(self): print('Methods testing') print(np.arange(6, dtype=np.int32)) print(np.arange(6, dtype=np.float)) a = np.array([4,3.]) print(type(a)) print(np.sort(a, None)) self.checkitems([3.,4], np.sort(a, None)) print(a.sort()) self.checkitems([3.,4], a) a = np.array([4,3.]) self.checkitems([1,0], a.argsort()) self.checkitems([1,0], np.argsort(a, None)) a = np.arange(6, dtype=np.float) print(a.take([0, 2, 4])) print(a.take([0, 2, 4], 0)) d = np.take(a, [0, 2, 4], 0) print(type(d), d) d = np.diag([0, 2, 3]) print(type(d), d) a.shape = 2,3 self.checkitems([1,2], a.take([1,2])) self.checkitems([[1,2], [4,5]], a.take([1,2],1)) self.checkitems([0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5], a.repeat(2)) self.checkitems([[0, 1, 2], [0, 1, 2], [3, 4, 5], [3, 4, 5]], a.repeat(2, axis=0)) self.checkitems([[0, 0, 1, 1, 2, 2], [3, 3, 4, 4, 5, 5]], a.repeat(2, axis=1))
def getInnerAndDetDatasetForGivenOuterValue(self, outerValue): mush = [[o, i, d] for o,i,d in zip(self.outer, self.inner, self.det) if o==float(outerValue)] x = dnp.array([a[1] for a in mush]) y = dnp.array([a[2] for a in mush]) return x, y
def save(self, collectionNumber=None): voltages=[] electrometers=[] if collectionNumber == None: filename = self.filename+"_"+self.getName()+".dat" print "concatenating data points to produce P-E data..." for each in self.voltages: voltages += each voltages += [] for each in self.electrometers: electrometers += each electrometers += [] else: filename = self.filename+"_"+self.getName()+"_"+str(collectionNumber)+".dat" print "summing data points to produce P-E data..." voltages = sum_datasets(self.voltages) electrometers = sum_datasets(self.electrometers) print "%s: saving data to %s" % (self.getName(), filename) if len(voltages) != len(electrometers): print "***Warning: voltage nord: %d, electrometer nord: %d" % (len(voltages),len(electrometers)) self.file=open(filename, "w") for voltage, electrometer in zip(voltages, electrometers): self.file.write("%f\t%f\n"%(voltage, electrometer)) self.file.close() print "%s: save data to %s completed." % (self.getName(), filename) voltagearray=scisoftpy.array(voltages) electrometerarray=scisoftpy.array(electrometers) vds=scisoftpy.toDS(voltagearray) eds=scisoftpy.toDS(electrometerarray) print "plotting PE-loop in 'DataPlot' panel..." if self.firstData: Plotter.plot("DataPlot", vds, eds) self.firstData=False else: Plotter.plotOver("DataPlot", vds, eds)
def testZeros(self): # make new datasets with zeros print("test zeros") dds = np.zeros(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(0, dds[0]) dds = np.zeros((2,3), dtype=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(0, dds[0,0]) dds = np.zeros_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(0, dds[0,0]) dds = np.zeros(np.array([1,2]), dtype=np.float) self.assertEqual((1,2), dds.shape) self.assertEquals(0, dds[0,0]) dds = np.zeros_like(np.array([1,2]), dtype=np.float) self.assertEquals((2,), dds.shape) self.assertEquals(0, dds[0])
def demoRealDataFitting(): m6Data=dnp.io.load("/dls/i06-1/data/2012/si7816-1/68917.dat", formats=['srs'], asdict=True); # m6Data=dnp.io.load("/dls/i06-1/data/2012/si7816-1/68918.dat", formats=['srs'], asdict=True); x, y=m6Data['m6qg'], m6Data['ca62sr']; # [mu, sigma, peak, gf] = fineGaussianFitting(y, x, "Plot 2"); [mu, sigma, peak, gf] = fineGaussianFitting(y, x); # One vertical line on the peak point: # xx, yy=dnp.array([mu-1, mu+1]), dnp.array([0, peak]); xx, yy=dnp.array([mu-1, mu, mu+1]), dnp.array([0, peak, 0]); xxx, yyy=dnp.array([mu]), dnp.array([peak]); # To find the closest data point to the peak; cPos=(dnp.abs(x-mu)).minpos()[0]; cX, cY=x[cPos], y[cPos]; print("To plot the fitted data." ) x1=dnp.linspace(x[0], x[x.size-1], 500); y1=myGaussianFunc(mu, sigma, peak, [x1]); #Line plot does not work, #dnp.plot.line(x, [y, y1] ) # plot line of evaluated function #dnp.plot.updateline(xx, yy) dnp.plot.points(x, y, None, 5); sleep(1); dnp.plot.addpoints(x1, y1, None, 1) sleep(1); dnp.plot.addpoints(xxx, yyy, None, 10); return [mu, sigma, peak, gf];
def getTrace(self, par): # floating point with 8 bytes / 64 bits per number #self.write("SYST:ERR:CLE") #print self.query("*OPC?") #print self.query("SYST:ERR?") #returns "No Error" self.write(":CALC:PAR%1d:DATA:SDAT?" % par) head = self.sock.recv(2) # header part 1 head = self.sock.recv(int(head[1])) # header part 2 MSGLEN = int(head) # extrace message len from header chunks = [] bytes_recd = 0 while bytes_recd < MSGLEN: chunk = self.sock.recv(min(MSGLEN - bytes_recd, 2048)) chunks.append(chunk) bytes_recd = bytes_recd + len(chunk) data = ''.join(chunks) extra = self.sock.recv(2048) #print len(extra) #print chr(extra) #print len(data), " bytes, ", len(data)/8, " numbers" num = len(data) / 8 [ data, ] = struct.unpack('%dd' % num, data), #return [np.array(data[::2]), np.array(data[1::2]) ] return dnp.array(data[::2]) + dnp.array(data[1::2]) * 1j
def testDiv(self): print("test div") da = np.array(self.db, np.int) dr = da // (da + 1) self.checkitemsdiv(self.db, self.db, dr, convert=toInt) dr = da.copy() dr //= da + 1 self.checkitemsdiv(self.db, self.db, dr, convert=toInt) dr = da / 1.2 self.checkitemsdivconst(self.db, 1.2, dr, convert=toInt) # dr = da.copy() # dr /= 1.2 # self.checkitemsdivconst2(self.db, 1.2, dr, convert=toInt) da = np.array(self.db, np.float) dr = da / (da + 1) self.checkitemsdiv(self.db, self.db, dr) dr = da.copy() dr /= da + 1 self.checkitemsdiv(self.db, self.db, dr) dr = da / 1.2 self.checkitemsdivconst(self.db, 1.2, dr) dr = 1.2 / (da + 1) self.checkitemsdivconst(1.2, self.db, dr) dr = da.copy() dr /= 1.2 self.checkitemsdivconst(self.db, 1.2, dr) za = np.array(self.zb, np.complex) zr = za / (za + 1) self.checkitemsdiv(self.zb, self.zb, zr, iscomplex=True) zr = za.copy() zr /= za + 1 self.checkitemsdiv(self.zb, self.zb, zr, iscomplex=True) zr = za / (1.3 + 0.2j) self.checkitemsdivconst(self.zb, (1.3 + 0.2j), zr, iscomplex=True) zr = za.copy() zr /= (1.3 + 0.2j) self.checkitemsdivconst(self.zb, (1.3 + 0.2j), zr, iscomplex=True) a = np.arange(-4, 4, dtype=np.int8) import sys py3 = sys.hexversion >= 0x03000000 if py3: self.checkitems([-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5], a / 2) self.checkitems([2, 1.5, 1, 0.5, 0, -0.5, -1, -1.5], a / -2) else: self.checkitems([-2, -2, -1, -1, 0, 0, 1, 1], a / 2) self.checkitems([2, 1, 1, 0, 0, -1, -1, -2], a / -2) self.checkitems([-2, -2, -1, -1, 0, 0, 1, 1], a // 2) self.checkitems([0, 1, 0, 1, 0, 1, 0, 1], a % 2) self.checkitems([2, 1, 1, 0, 0, -1, -1, -2], a // -2) self.checkitems([0, -1, 0, -1, 0, -1, 0, -1], a % -2) self.checkitems([-1.6, -1.2, -0.8, -0.4, 0., 0.4, 0.8, 1.2], a / 2.5) self.checkitems([-2., -2., -1., -1., 0., 0., 0., 1.], a // 2.5) self.checkitems([1., 2., 0.5, 1.5, 0., 1., 2., 0.5], a % 2.5) self.checkitems([1.6, 1.2, 0.8, 0.4, -0., -0.4, -0.8, -1.2], a / -2.5) self.checkitems([1., 1., 0., 0., -0., -1., -1., -2.], a // -2.5) self.checkitems([-1.5, -0.5, -2., -1., 0., -1.5, -0.5, -2.], a % -2.5)
def testDiv(self): print("test div") da = np.array(self.db, np.int) dr = da // (da+1) self.checkitemsdiv(self.db, self.db, dr, convert=toInt) dr = da.copy() dr //= da + 1 self.checkitemsdiv(self.db, self.db, dr, convert=toInt) dr = da / 1.2 self.checkitemsdivconst(self.db, 1.2, dr, convert=toInt) # dr = da.copy() # dr /= 1.2 # self.checkitemsdivconst2(self.db, 1.2, dr, convert=toInt) da = np.array(self.db, np.float) dr = da / (da+1) self.checkitemsdiv(self.db, self.db, dr) dr = da.copy() dr /= da + 1 self.checkitemsdiv(self.db, self.db, dr) dr = da / 1.2 self.checkitemsdivconst(self.db, 1.2, dr) dr = 1.2 / (da+1) self.checkitemsdivconst(1.2, self.db, dr) dr = da.copy() dr /= 1.2 self.checkitemsdivconst(self.db, 1.2, dr) za = np.array(self.zb, np.complex) zr = za / (za + 1) self.checkitemsdiv(self.zb, self.zb, zr, iscomplex=True) zr = za.copy() zr /= za + 1 self.checkitemsdiv(self.zb, self.zb, zr, iscomplex=True) zr = za / (1.3 + 0.2j) self.checkitemsdivconst(self.zb, (1.3 + 0.2j), zr, iscomplex=True) zr = za.copy() zr /= (1.3 + 0.2j) self.checkitemsdivconst(self.zb, (1.3 + 0.2j), zr, iscomplex=True) a = np.arange(-4, 4, dtype=np.int8) import sys py3 = sys.hexversion >= 0x03000000 if py3: self.checkitems([-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5], a / 2) self.checkitems([2, 1.5, 1, 0.5, 0, -0.5, -1, -1.5], a / -2) else: self.checkitems([-2, -2, -1, -1, 0, 0, 1, 1], a / 2) self.checkitems([2, 1, 1, 0, 0, -1, -1, -2], a / -2) self.checkitems([-2, -2, -1, -1, 0, 0, 1, 1], a // 2) self.checkitems([0, 1, 0, 1, 0, 1, 0, 1], a % 2) self.checkitems([2, 1, 1, 0, 0, -1, -1, -2], a // -2) self.checkitems([0, -1, 0, -1, 0, -1, 0, -1], a % -2) self.checkitems([-1.6, -1.2, -0.8, -0.4, 0. , 0.4, 0.8, 1.2], a / 2.5) self.checkitems([-2., -2., -1., -1., 0., 0., 0., 1.], a // 2.5) self.checkitems([1., 2., 0.5, 1.5, 0., 1., 2., 0.5], a % 2.5) self.checkitems([1.6, 1.2, 0.8, 0.4, -0., -0.4, -0.8, -1.2], a / -2.5) self.checkitems([1., 1., 0., 0., -0., -1., -1., -2.], a // -2.5) self.checkitems([-1.5, -0.5, -2., -1., 0., -1.5, -0.5, -2.], a % -2.5)
def testSelect(self): print 'test select' tm = np.select([ np.array([[[False, True], [True, False]], [[True, True], [False, False]]]) ], [np.array(self.mm)], -2.3) self.checkitems([[[-2.3, 2.], [6., -2.3]], [[20., 30.], [-2.3, -2.3]]], tm)
def mgrid(x, y): y0=[y]*len(x) Y=dnp.array(y0); x0=[x]*len(y); X=dnp.array( zip(*x0) ) return X, Y;
def testInteger(self): print 'test integer get and set' tm = np.array(self.mm).flatten() d = tm[np.array([2, 4, 7])] self.checkitems([6., 20., 56.], d) tm[np.array([3, 4, 5, 6, 7])] = -2.3 self.checkitems([0., 2., 6., -2.3, -2.3, -2.3, -2.3, -2.3], tm)
def testInteger(self): print 'test integer get and set' tm = np.array(self.mm).flatten() d = tm[np.array([2, 4, 7])] self.checkitems([ 6., 20., 56. ], d) tm[np.array([3, 4, 5, 6, 7])] = -2.3 self.checkitems([ 0., 2., 6., -2.3, -2.3, -2.3, -2.3, -2.3 ], tm)
def project(self, energy, UB, pixels, gamma, delta, omega, alpha, nu): # put the detector at the right position dx, dy, dz = pixels # convert angles to radians gamma, delta, alpha, omega, nu = numpy.radians( (gamma, delta, alpha, omega, nu)) RGam = numpy.matrix([[1, 0, 0], [0, cos(gamma), -sin(gamma)], [0, sin(gamma), cos(gamma)]]) RDel = (numpy.matrix([[cos(delta), -sin(delta), 0], [sin(delta), cos(delta), 0], [0, 0, 1]])).getI() RNu = numpy.matrix([[cos(nu), 0, sin(nu)], [0, 1, 0], [-sin(nu), 0, cos(nu)]]) # calculate Cartesian coordinates for each pixel using clever matrix stuff M = numpy.mat( numpy.concatenate( (dx.flatten(0), dy.flatten(0), dz.flatten(0))).reshape(3, dx.shape[0] * dx.shape[1])) XYZp = RGam * RDel * RNu * M xp = dnp.array(XYZp[0]).reshape(dx.shape) yp = dnp.array(XYZp[1]).reshape(dy.shape) zp = dnp.array(XYZp[2]).reshape(dz.shape) # don't bother with the part about slits... # Calculate effective gamma and delta for each pixel d_ds = dnp.sqrt(xp**2 + yp**2 + zp**2) Gam = dnp.arctan2(zp, yp) Del = -1 * dnp.arcsin(-xp / d_ds) # wavenumber k = 2 * math.pi / 12.398 * energy # Define the needed matrices. The notation follows the article by Bunk & # Nielsen. J.Appl.Cryst. (2004) 37, 216-222. M1 = k * numpy.matrix( cos(omega) * sin(Del) - sin(omega) * (cos(alpha) * (cos(Gam) * cos(Del) - 1) + sin(alpha) * sin(Gam) * cos(Del))) M2 = k * numpy.matrix( sin(omega) * sin(Del) + cos(omega) * (cos(alpha) * (cos(Gam) * cos(Del) - 1) + sin(alpha) * sin(Gam) * cos(Del))) M3 = k * numpy.matrix(-sin(alpha) * (cos(Gam) * cos(Del) - 1) + cos(alpha) * sin(Gam) * cos(Del)) # invert UB matrix UBi = numpy.matrix(UB).getI() # calculate HKL H = UBi[0, 0] * M1 + UBi[0, 1] * M2 + UBi[0, 2] * M3 K = UBi[1, 0] * M1 + UBi[1, 1] * M2 + UBi[1, 2] * M3 L = UBi[2, 0] * M1 + UBi[2, 1] * M2 + UBi[2, 2] * M3 return (H, K, L)
def display_parameters(self, parameter_number): keys = self.results.keys() keys.sort() data = [] for key in keys: result = self.results[key][2] data.append(result[parameter_number]) y = dnp.array(data) x = dnp.array(keys) dnp.plot.line(x, y, name=self.calibration_window)
def testTwos(self): # make new datasets with twos print("test twos") dds = np.full(3, 2.) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(1, dds.ndim) self.assertEquals(3, dds.shape[0]) self.assertEquals(2., dds[0]) dds = np.full((2,3), 2.) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(2, dds.ndim) self.assertEquals(2, dds.shape[0]) self.assertEquals(3, dds.shape[1]) self.assertEquals(2., dds[0,0]) dds = np.full_like(dds, 2.) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(2, dds.ndim) self.assertEquals(2, dds.shape[0]) self.assertEquals(3, dds.shape[1]) self.assertEquals(2., dds[0,0]) dds = np.full(3, 2, dtype=np.float) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(1, dds.ndim) self.assertEquals(3, dds.shape[0]) self.assertEquals(2., dds[0]) dds = np.full((2,3), 2, dtype=np.float) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(2, dds.ndim) self.assertEquals(2, dds.shape[0]) self.assertEquals(3, dds.shape[1]) self.assertEquals(2., dds[0,0]) dds = np.full_like(dds, 2, dtype=np.float) if isjava: self.assertEquals(1, dds.dtype.elements) self.assertEquals(np.float64, dds.dtype) self.assertEquals(2, dds.ndim) self.assertEquals(2, dds.shape[0]) self.assertEquals(3, dds.shape[1]) self.assertEquals(2., dds[0,0]) dds = np.full(np.array([1,2]), 2, dtype=np.float) self.assertEqual((1,2), dds.shape) self.assertEquals(2, dds[0,0]) dds = np.full_like(np.array([1,2]), 2, dtype=np.float) self.assertEquals((2,), dds.shape) self.assertEquals(2, dds[0])
def testDatasetSlice(self): print 'test slicing with start and stop' ds = np.arange(16) dr = ds[2:10] self.checkitems(range(2,10), dr) print 'test slicing with steps' dr = ds[::2] self.checkitems(range(0,16,2), dr) print 'test slicing 3D' dr = self.dda[1:,::2,1::2] self.checkitems(self.t, dr) print 'test putting in a 3D slice' dr = self.dda.copy() dr[:,1::2,::2] = 7. self.checkitems(self.u, dr) print 'test putting a list in a 3D slice' dr = self.dda.copy() print dr[:,1::2,::2].shape dr[:,1::2,::2] = np.array([7., 7]).reshape(2,1,1) self.checkitems(self.u, dr) print 'test slicing with ellipse' dr = ds[...] self.checkitems(range(16), dr) print 'test slicing 3D with ellipse' dr = self.dda[...,1::2] self.checkitems(self.t, dr[1:, ::2]) print 'test putting in a 3D slice with ellipsis' dr = self.dda.copy() dr[...,1::2,::2] = 7. self.checkitems(self.u, dr) print 'test putting a list in a 3D slice with ellipsis' dr = self.dda.copy() print dr[...,1::2,::2].shape dr[...,1::2,::2] = np.array([7., 7]).reshape(2,1,1) self.checkitems(self.u, dr) print 'test slice shape reduction' dr = np.arange(120).reshape(4,3,5,2) s = dr[:2,...,1:].shape print s self.assertEquals(s, (2,3,5,1)) s = dr[:2,...,1].shape print s self.assertEquals(s, (2,3,5)) s = dr[:2,...,...,1].shape print s self.assertEquals(s, (2,3,5))
def testTwos(self): # make new datasets with twos print("test twos") dds = np.full(3, 2.) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(1, dds.ndim) self.assertEqual(3, dds.shape[0]) self.assertEqual(2., dds[0]) dds = np.full((2, 3), 2.) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(2, dds.ndim) self.assertEqual(2, dds.shape[0]) self.assertEqual(3, dds.shape[1]) self.assertEqual(2., dds[0, 0]) dds = np.full_like(dds, 2.) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(2, dds.ndim) self.assertEqual(2, dds.shape[0]) self.assertEqual(3, dds.shape[1]) self.assertEqual(2., dds[0, 0]) dds = np.full(3, 2, dtype=np.float) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(1, dds.ndim) self.assertEqual(3, dds.shape[0]) self.assertEqual(2., dds[0]) dds = np.full((2, 3), 2, dtype=np.float) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(2, dds.ndim) self.assertEqual(2, dds.shape[0]) self.assertEqual(3, dds.shape[1]) self.assertEqual(2., dds[0, 0]) dds = np.full_like(dds, 2, dtype=np.float) if isjava: self.assertEqual(1, dds.dtype.elements) self.assertEqual(np.float64, dds.dtype) self.assertEqual(2, dds.ndim) self.assertEqual(2, dds.shape[0]) self.assertEqual(3, dds.shape[1]) self.assertEqual(2., dds[0, 0]) dds = np.full(np.array([1, 2]), 2, dtype=np.float) self.assertEqual((1, 2), dds.shape) self.assertEqual(2, dds[0, 0]) dds = np.full_like(np.array([1, 2]), 2, dtype=np.float) self.assertEqual((2, ), dds.shape) self.assertEqual(2, dds[0])
def plotPEdata(self, *args, **kwargs): xarray=scisoftpy.array(kwargs[self.hv][args[0]]) yrarray=scisoftpy.array(kwargs[self.el][args[0]]) vds=scisoftpy.toDS(xarray) eds=scisoftpy.toDS(yrarray) print "plotting PE-loop in 'DataPlot' panel..." if self.firstData: Plotter.plot("DataPlot", vds, eds) self.firstData=False else: Plotter.plotOver("DataPlot", vds, eds)
def testBincount(self): print('Bincount testing') a = np.array([2, 1, 2, 4, 6, 0]) c = np.bincount(a) self.checkitems([1, 1, 2, 0, 1, 0, 1], c) c = np.bincount(a, None, 10) self.checkitems([1, 1, 2, 0, 1, 0, 1, 0, 0, 0], c) w = np.array([1, 1, 2, 4, 1, 0]) c = np.bincount(a, w) self.checkitems([0, 1, 3, 0, 4, 0, 1], c) c = np.bincount(a, w * 0.5) self.checkitems([0, 1, 3, 0, 4, 0, 1], 2 * c)
def testPut(self): print 'test put' ds = np.arange(6.) ds.put([2, 5], [-2, -5.5]) self.checkitems([0, 1, -2, 3, 4, -5.5], ds) ds.put(np.array([0, 4]), [-2, -5.5]) self.checkitems([-2, 1, -2, 3, -5.5, -5.5], ds) ds = np.arange(6.).reshape(2,3) ds.put([2, 5], [-2, -5.5]) self.checkitems([[0, 1, -2], [3, 4, -5.5]], ds) ds.put(np.array([0, 4]), [-2, -5.5]) self.checkitems([[-2, 1, -2], [3, -5.5, -5.5]], ds)
def testPut(self): print 'test put' ds = np.arange(6.) ds.put([2, 5], [-2, -5.5]) self.checkitems([0, 1, -2, 3, 4, -5.5], ds) ds.put(np.array([0, 4]), [-2, -5.5]) self.checkitems([-2, 1, -2, 3, -5.5, -5.5], ds) ds = np.arange(6.).reshape(2, 3) ds.put([2, 5], [-2, -5.5]) self.checkitems([[0, 1, -2], [3, 4, -5.5]], ds) ds.put(np.array([0, 4]), [-2, -5.5]) self.checkitems([[-2, 1, -2], [3, -5.5, -5.5]], ds)
def testBincount(self): print('Bincount testing') a = np.array([2, 1, 2, 4, 6, 0]) c = np.bincount(a) self.checkitems([1, 1, 2, 0, 1, 0, 1], c) c = np.bincount(a, None, 10) self.checkitems([1, 1, 2, 0, 1, 0, 1, 0, 0, 0], c) w = np.array([1, 1, 2, 4, 1, 0]) c = np.bincount(a, w) self.checkitems([0, 1, 3, 0, 4, 0, 1], c) c = np.bincount(a, w * 0.5) self.checkitems([0, 1, 3, 0, 4, 0, 1], 2*c)
def testSlicing(self): a = np.array([], dtype=np.float_) self.assertEquals(len(a), 0) a = np.zeros((2, )) self.assertEquals(len(a), 2) self.checkitems([0, 0], a[:]) self.assertEquals(a[1], 0) a[:] = 0.5 self.checkitems([0.5, 0.5], a[:]) a = np.zeros((2, 3)) self.assertEquals(len(a), 2) self.checkitems([0, 0, 0], a[0]) a[1] = 0.2 self.checkitems([0.2, 0.2, 0.2], a[1]) a = np.zeros((2, 3, 4)) self.assertEquals(len(a), 2) a = np.arange(10).reshape((5, 2)) a[3, :] = np.array([0, 0]) self.checkitems([0, 0], a[3]) a[3, :] = np.array([1, 1]).reshape(1, 2) self.checkitems([1, 1], a[3]) a[:2, 1] = np.array([2, 2]) self.checkitems([2, 2], a[:2, 1]) a = np.arange(7) c = range(7) self.checkitems(c[::2], a[::2]) self.checkitems(c[0::2], a[0::2]) self.checkitems(c[3::2], a[3::2]) self.checkitems(c[6::2], a[6::2]) self.checkitems(c[6:6:2], a[6:6:2]) self.checkitems(c[7::2], a[7::2]) self.checkitems(c[-1::2], a[-1::2]) self.checkitems(c[-2::2], a[-2::2]) self.checkitems(c[::-2], a[::-2]) self.checkitems(c[0::-2], a[0::-2]) self.checkitems(c[3::-2], a[3::-2]) self.checkitems(c[6::-2], a[6::-2]) self.checkitems(c[6:6:-2], a[6:6:-2]) self.checkitems(c[7::-2], a[7::-2]) self.checkitems(c[-1::-2], a[-1::-2]) self.checkitems(c[-2::-2], a[-2::-2]) self.checkitems(a[::-2], a[:-8:-2]) a = np.arange(24).reshape(6, 4) self.assertEqual((6, 4), a[:].shape) self.assertEqual((6, 4), a[:, ].shape) self.assertEqual((6, 3), a[:, :3].shape) self.assertEqual((0, 3), a[4:2, :3].shape) self.assertEqual((6, ), a[:, 3].shape) self.assertEqual((0, ), a[4:2, 3].shape)
def testSlicing(self): a = np.array([], dtype=np.float_) self.assertEquals(len(a), 0) a = np.zeros((2,)) self.assertEquals(len(a), 2) self.checkitems([0,0], a[:]) self.assertEquals(a[1], 0) a[:] = 0.5 self.checkitems([0.5,0.5], a[:]) a = np.zeros((2,3)) self.assertEquals(len(a), 2) self.checkitems([0,0,0], a[0]) a[1] = 0.2 self.checkitems([0.2,0.2,0.2], a[1]) a = np.zeros((2,3,4)) self.assertEquals(len(a), 2) a = np.arange(10).reshape((5,2)) a[3,:] = np.array([0,0]) self.checkitems([0,0], a[3]) a[3,:] = np.array([1,1]).reshape(1,2) self.checkitems([1,1], a[3]) a[:2,1] = np.array([2,2]) self.checkitems([2,2], a[:2,1]) a = np.arange(7) c = range(7) self.checkitems(c[::2], a[::2]) self.checkitems(c[0::2], a[0::2]) self.checkitems(c[3::2], a[3::2]) self.checkitems(c[6::2], a[6::2]) self.checkitems(c[6:6:2], a[6:6:2]) self.checkitems(c[7::2], a[7::2]) self.checkitems(c[-1::2], a[-1::2]) self.checkitems(c[-2::2], a[-2::2]) self.checkitems(c[::-2], a[::-2]) self.checkitems(c[0::-2], a[0::-2]) self.checkitems(c[3::-2], a[3::-2]) self.checkitems(c[6::-2], a[6::-2]) self.checkitems(c[6:6:-2], a[6:6:-2]) self.checkitems(c[7::-2], a[7::-2]) self.checkitems(c[-1::-2], a[-1::-2]) self.checkitems(c[-2::-2], a[-2::-2]) self.checkitems(a[::-2], a[:-8:-2]) a = np.arange(24).reshape(6,4) self.assertEqual((6,4), a[:].shape) self.assertEqual((6,4), a[:,].shape) self.assertEqual((6,3), a[:,:3].shape) self.assertEqual((0,3), a[4:2,:3].shape) self.assertEqual((6,), a[:,3].shape) self.assertEqual((0,), a[4:2,3].shape)
def createMask(self, low, high, dataset=None): if dataset is None: if self.dataset is None: print "No reference dataset to mask" return else: dataset = self.dataset maskArray = dnp.logical_and( dnp.array(dataset) >= low, dnp.array(dataset) <= high) self.mask = maskArray._jdataset() return self.mask
def testInteger(self): print 'test integer get and set' tm = np.array(self.mm).flatten() # self.mm = [ [[0., 2.], [6., 12.]], [[20., 30.], [42., 56.]] ] d = tm[np.array([2, 4, 7])] self.checkitems([ 6., 20., 56. ], d) # d = tm[np.array([2, 4, 7])] # self.checkitems([ 6., 20., 56. ], d) tm[np.array([3, 4, 5, 6, 7])] = -2.3 # self.checkitems([ [[0., 2.], [6., -2.3]], [[-2.3, -2.3], [-2.3, -2.3]] ], tm) self.checkitems([ 0., 2., 6., -2.3, -2.3, -2.3, -2.3, -2.3 ], tm)
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()]
def testCorrelate(self): print 'test correlate' da = np.array(self.da, np.float) ada = np.correlate(da, axes=[0]) self.checkitems(None, ada) a = np.array([1, 2, 3]) b = np.array([0, 1, 0.5]) self.checkitems([3.5], np.correlate(a, b)) self.checkitems([2., 3.5, 3.], np.correlate(a, b, "same")) self.checkitems([0.5, 2., 3.5, 3., 0.], np.correlate(a, b, "full")) self.checkitems([3.5], np.correlate(b, a)) self.checkitems([2., 3.5, 3.][::-1], np.correlate(b, a, "same")) self.checkitems([0.5, 2., 3.5, 3., 0.][::-1], np.correlate(b, a, "full"))
def testConvolve(self): print 'test convolve' # da = np.array(self.da, np.float) # ada = np.convolve(da, axes=[0]) # self.checkitems(None, ada) a = np.array([1, 2, 3]) b = np.array([0, 1, 0.5]) self.checkitems([0., 1., 2.5, 4., 1.5], np.convolve(a, b)) self.checkitems([1., 2.5, 4.], np.convolve(a, b, 'same')) self.checkitems([2.5], np.convolve(a, b, 'valid')) self.checkitems([0., 1., 2.5, 4., 1.5], np.convolve(b, a)) self.checkitems([1., 2.5, 4.], np.convolve(b, a, 'same')) self.checkitems([2.5], np.convolve(b, a, 'valid'))
def testAmin(self): a = dnp.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) self.assertEqual(dnp.amin(a, axis=0).shape, (2,3)) self.checkitems(dnp.amin(a, axis=0), dnp.array([[1, 2, 3], [4, 5, 6]])) self.assertEqual(dnp.amin(a, axis=2).shape, (2,2)) self.assertEqual(dnp.amin(a, axis=(0, 1)).shape, (3,)) self.checkitems(dnp.amin(a, axis=(0, 1)), dnp.array([1, 2, 3])) self.assertEqual(dnp.amin(a, axis=(0, 1, 2)), 1) self.assertEqual(dnp.amin(a, axis=0, keepdims=True).shape, (1, 2, 3)) self.assertEqual(dnp.amin(a, axis=2, keepdims=True).shape, (2, 2, 1)) self.assertEqual(dnp.amin(a, axis=(0, 1), keepdims=True).shape, (1, 1, 3)) self.checkitems(dnp.amin(a, axis=(0, 1), keepdims=True), dnp.array([[[1, 2, 3]]])) self.assertEqual(dnp.amin(a, axis=(0, 2), keepdims=True).shape, (1, 2, 1)) self.checkitems(dnp.amin(a, axis=(0, 2), keepdims=True), dnp.array([[[1], [4]]]))
def test2dInput(self): arr_input = dnp.array([[1, 2], [3, 4], [5, 6]]) list_input = [[1, 2], [3, 4], [5, 6]] zeros_output = dnp.array([[0, 0], [0, 0], [0, 0]]) zeros_like_arr = dnp.zeros_like(arr_input) zeros_like_list = dnp.zeros_like(list_input) self.assertEqual(zeros_like_arr.shape, (3, 2)) self.checkitems(zeros_like_arr, zeros_output) self.assertEqual(zeros_like_list.shape, (3, 2)) self.checkitems(zeros_like_list, zeros_output)
def testEmptyListInput(self): array_input = dnp.array([]) list_input = [] zeros_output = dnp.array([]) zeros_like_array = dnp.zeros_like(list_input) zeros_like_list = dnp.zeros_like(list_input) self.assertEqual(zeros_like_array.shape, (0, )) self.checkitems(zeros_like_array, zeros_output) self.assertEqual(zeros_like_list.shape, (0, )) self.checkitems(zeros_like_list, zeros_output)
def testEmptyListInput(self): array_input = dnp.array([]) list_input = [] zeros_output = dnp.array([]) zeros_like_array = dnp.zeros_like(list_input) zeros_like_list = dnp.zeros_like(list_input) self.assertEquals(zeros_like_array.shape, (0,)) self.checkitems(zeros_like_array, zeros_output) self.assertEquals(zeros_like_list.shape, (0,)) self.checkitems(zeros_like_list, zeros_output)
def test2dInput(self): arr_input = dnp.array([[1, 2], [3, 4], [5, 6]]) list_input = [[1, 2], [3, 4], [5, 6]] zeros_output = dnp.array([[0, 0], [0, 0], [0, 0]]) zeros_like_arr = dnp.zeros_like(arr_input) zeros_like_list = dnp.zeros_like(list_input) self.assertEquals(zeros_like_arr.shape, (3,2)) self.checkitems(zeros_like_arr, zeros_output) self.assertEquals(zeros_like_list.shape, (3,2)) self.checkitems(zeros_like_list, zeros_output)
def testAmin(self): a = dnp.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) self.assertEquals(dnp.amin(a, axis=0).shape, (2,3)) self.checkitems(dnp.amin(a, axis=0), dnp.array([[1, 2, 3], [4, 5, 6]])) self.assertEquals(dnp.amin(a, axis=2).shape, (2,2)) self.assertEquals(dnp.amin(a, axis=(0, 1)).shape, (3,)) self.checkitems(dnp.amin(a, axis=(0, 1)), dnp.array([1, 2, 3])) self.assertEquals(dnp.amin(a, axis=(0, 1, 2)), 1) self.assertEquals(dnp.amin(a, axis=0, keepdims=True).shape, (1, 2, 3)) self.assertEquals(dnp.amin(a, axis=2, keepdims=True).shape, (2, 2, 1)) self.assertEquals(dnp.amin(a, axis=(0, 1), keepdims=True).shape, (1, 1, 3)) self.checkitems(dnp.amin(a, axis=(0, 1), keepdims=True), dnp.array([[[1, 2, 3]]])) self.assertEquals(dnp.amin(a, axis=(0, 2), keepdims=True).shape, (1, 2, 1)) self.checkitems(dnp.amin(a, axis=(0, 2), keepdims=True), dnp.array([[[1], [4]]]))
def _process(self,xDataSet, yDataSet): if yDataSet.max()-yDataSet.min() == 0: raise ValueError("There is no peak") xDataSet = np.Sciwrap(xDataSet) yDataSet = np.Sciwrap(yDataSet) * self.scale funcs = [ holefunc ] initparams = [ xDataSet.mean(), (xDataSet.max() - xDataSet.min())* 0.90, yDataSet.min(), yDataSet.max()] fr = np.fit.fit(funcs, xDataSet, yDataSet, initparams, ptol=1e-4, optimizer='local') if self.plotPanel != None: fr.plot(self.plotPanel) initparams = [ p for p in fr.func.getParameterValues() ] start = initparams[0] - 0.5 * initparams[1] length = initparams[1] truncx = [] truncy = [] for i in range(xDataSet.size): val = xDataSet[i] if val >= start and val <= start+length: truncx.append(val) truncy.append(yDataSet[i]) lala = Generic1DFitter.fitPeaks(np.toDS(np.array(truncx)), np.toDS(np.array(truncy)), Gaussian(1,1,1,1), NelderMead(self.accuracy), 2, self.gaussians, 0.05, True, False) print lala if lala == None or len(lala) == 0: print "no peaks found" return [0, []] positions = [] cff = np.fit.fitcore.cfitfunc() for f in lala: print f.getParameter(1), f.getParameter(2) if f.getParameter(1).getValue() <= self.maxfwhm and f.getParameter(2).getValue() >= self.minarea: positions.append(f.getParameter(0).getValue()) cff.addFunction(f) else: print "removed one" if len(positions) == 0: print "too bad nothing found within threshold" else: print "plotting remaining found positions" if self.plotPanel != None: fire = np.fit.fitcore.fitresult(cff, [np.toDS(np.array(truncx))], np.array(truncy)) fire.plot(self.plotPanel) return [len(positions), positions]
def readTestInputs( filename="height.txt", idealname="ideal.txt", visit_directory="/dls/i12/data/2014/cm4963-2", input_directory="tmp", printres=False, ): infilename = "%s/%s/%s" % (visit_directory, input_directory, filename) idealfilename = "%s/%s/%s" % (visit_directory, input_directory, idealname) inlist = [] ideallist = [] try: infile = open(infilename, "r") except: print ("File %s not opened properly" % infilename) return None n = 0 for line in infile: if printres: print n, line n = n + 1 inlist.append(float(line)) infile.close() try: infile = open(idealfilename, "r") except: print ("File %s not opened properly" % idealfilename) return None for line in infile: if printres: print n, line n = n + 1 ideallist.append(float(line)) infile.close() if printres: print inlist print ideallist inarray = dnp.array(inlist) idealarray = dnp.array(ideallist) print len(inarray) angarray = dnp.linspace(0, dnp.pi * 2.0, len(inarray), True) horizarray = 2500.0 * dnp.cos(angarray) ofile = open("%s/%s/testpoints.txt" % (visit_directory, input_directory), "w") ofile.write("angle,X,idealY,noisyY\n") for i in range(0, len(angarray)): ofile.write("%g,%g,%g,%g\n" % (angarray[i], horizarray[i], idealarray[i], inarray[i])) ofile.close() return (horizarray, inarray, idealarray)
def testZeroRank(self): print 'Zero rank arrays testing' zi = np.array(1) print zi self.assertEquals(0, len(zi.shape)) self.assertEquals(1, zi[()]) self.assertEquals(np.array(1), zi[...]) zi[()] = -3 self.assertEquals(-3, zi[()]) zf = np.array(1.) self.assertEquals(0, len(zf.shape)) self.assertEquals(1., zf[()]) self.assertEquals(np.array(1.), zf[...]) zf[()] = -3 self.assertEquals(-3, zf[()])
def calc_bins_vrs_q(self): peaklist = self.get_peak_list_from_view() peakpos = [] for peak in peaklist: peakpos.append(peak.getPosition()) peakpos.sort() x = dnp.array(self.standard_peaks) y = dnp.array(peakpos) max_size = min(x.shape[0], y.shape[0]) x = x[0:max_size] y = y[0:max_size] x.name = "Calibration Values" y.name = "Peak positions" fr = dnp.fit.polyfit(y, x, 2, full=True) return (x, y, fr[1])
def testSavingBits(self): d = dnp.arange(12*32).reshape((12,32)) b = dnp.abs(dnp.array(d, dnp.int8)) b[b < 0] = 0 print b.min(), b.max() dnp.io.save(OutTestFolder+'uint.tiff', d, bits=32, signed=False) dnp.io.save(OutTestFolder+'ushort.tiff', d, bits=16, signed=False) dnp.io.save(OutTestFolder+'ubyte.tiff', b, bits=8, signed=False) dnp.io.save(OutTestFolder+'int.tiff', d, bits=32) dnp.io.save(OutTestFolder+'short.tiff', d, bits=16) dnp.io.save(OutTestFolder+'byte.tiff', dnp.array(d, dnp.int8), bits=8) dnp.io.save(OutTestFolder+'double.tiff', d, bits=33) dnp.io.save(OutTestFolder+'float.tiff', d, bits=33) dnp.io.save(OutTestFolder+'short.png', d, bits=16) dnp.io.save(OutTestFolder+'byte.png', b, bits=8)
def testSavingBits(self): d = dnp.arange(12 * 32).reshape((12, 32)) b = dnp.abs(dnp.array(d, dnp.int8)) b[b < 0] = 0 print(b.min(), b.max()) self.save('uint.tiff', d, bits=32, signed=False) self.save('ushort.tiff', d, bits=16, signed=False) self.save('ubyte.tiff', b, bits=8, signed=False) self.save('int.tiff', d, bits=32) self.save('short.tiff', d, bits=16) self.save('byte.tiff', dnp.array(d, dnp.int8), bits=8) self.save('double.tiff', d, bits=33) self.save('float.tiff', d, bits=33) self.save('short.png', d, bits=16) self.save('byte.png', b, bits=8)
def analyseData(dd): #ss = dd.sum(0) #dnp.plot.image(ss) ##ss is the flat field print "Calculating median for the dataset ..." med = dnp.median(dd, 0) print "Median calculated" if plotData: dnp.plot.image(med) sleep(2) #flatFieldCorrectedSum = ss/med #dnp.plot.image(flatFieldCorrectedSum) xVals = [] yVals = [] ## print "Calculating centroid ..." centroids = [] for i in range(18): #dnp.plot.image(dd[i, :, :] / med) im = dd[i, :, :] / med im = javaImage.medianFilter(im, [3, 3]) im = dnp.array(im) threshold = 0.85 if plotData: dnp.plot.image(im) if plotData: sleep(1) if plotData: dnp.plot.image(im < threshold) if plotData: sleep(1) cent = dnp.centroid(im < threshold) yVals.append(cent[0]) xVals.append(cent[1]) centroids.append(cent) print "y:" + ` yVals ` print('') print "x:" + ` xVals ` #help(dnp.fit.ellipsefit) if plotData: dnp.plot.line(dnp.array(xVals), dnp.array(yVals)) ellipseFitValues = dnp.fit.ellipsefit(xVals, yVals) print "major: " + ` ellipseFitValues[0] ` print "minor semi-axis: " + ` ellipseFitValues[1] ` print "major axis angle: " + ` ellipseFitValues[2] ` print "centre co-ord 1: " + ` ellipseFitValues[3] ` print "centre co-ord 2: " + ` ellipseFitValues[4] ` print "centroids:" + ` centroids ` xOffset = getXOffset(ellipseFitValues[1], ellipseFitValues[0]) zOffset = getZOffset(ellipseFitValues[2]) return xOffset, zOffset, centroids, ellipseFitValues
def analyseData(dd): #ss = dd.sum(0) #dnp.plot.image(ss) ##ss is the flat field print "Calculating median for the dataset ..." med = dnp.median(dd, 0) print "Median calculated" if plotData: dnp.plot.image(med) Sleep.sleep(2000) #flatFieldCorrectedSum = ss/med #dnp.plot.image(flatFieldCorrectedSum) xVals = [] yVals = [] ## print "Calculating centroid ..." centroids = [] for i in range(18): #dnp.plot.image(dd[i, :, :] / med) im = dd[i, :, :] / med im = javaImage.medianFilter(im, [3, 3]) im = dnp.array(im) threshold = 0.85 if plotData: dnp.plot.image(im) if plotData: Sleep.sleep(1000) if plotData: dnp.plot.image(im < threshold) if plotData: Sleep.sleep(1000) cent = dnp.centroid(im < threshold) yVals.append(cent[0]) xVals.append(cent[1]) centroids.append(cent) print "y:" + `yVals` print('') print "x:" + `xVals` #help(dnp.fit.ellipsefit) if plotData: dnp.plot.line(dnp.array(xVals), dnp.array(yVals)) ellipseFitValues = dnp.fit.ellipsefit(xVals, yVals) print "major: " + `ellipseFitValues[0]` print "minor semi-axis: " + `ellipseFitValues[1]` print "major axis angle: " + `ellipseFitValues[2]` print "centre co-ord 1: " + `ellipseFitValues[3]` print "centre co-ord 2: " + `ellipseFitValues[4]` print "centroids:" + `centroids` xOffset = getXOffset(ellipseFitValues[1], ellipseFitValues[0]) zOffset = getZOffset(ellipseFitValues[2]) return xOffset, zOffset, centroids, ellipseFitValues
def normalised_number_of_reflections(grouped_reflections): no_of_reflec_list = [] for group in grouped_reflections: no_of_reflec_list.append(len(group)) max_no = max(no_of_reflec_list) no_of_reflec_list = [(float(no)/float(max_no))*100.0 for no in no_of_reflec_list] return dnp.array(no_of_reflec_list)