def setUp(self): self.multiFrameFilename = UtilsTest.getimage("MultiFrame.edf.bz2")[:-4] self.Frame0Filename = UtilsTest.getimage("MultiFrame-Frame0.edf.bz2")[:-4] self.Frame1Filename = UtilsTest.getimage("MultiFrame-Frame1.edf.bz2")[:-4] self.ref = edfimage() self.frame0 = edfimage() self.frame1 = edfimage() self.ref.read(self.multiFrameFilename) self.frame0.read(self.Frame0Filename) self.frame1.read(self.Frame1Filename)
def setUp(self): self.multiFrameFilename = UtilsTest.getimage("MultiFrame.edf.bz2")[:-4] self.Frame0Filename = UtilsTest.getimage( "MultiFrame-Frame0.edf.bz2")[:-4] self.Frame1Filename = UtilsTest.getimage( "MultiFrame-Frame1.edf.bz2")[:-4] self.ref = edfimage() self.frame0 = edfimage() self.frame1 = edfimage() self.ref.read(self.multiFrameFilename) self.frame0.read(self.Frame0Filename) self.frame1.read(self.Frame1Filename)
def test_read(self): """ check we can read these images""" ref = edfimage() gzipped = edfimage() compressed = edfimage() refFile = "edfUncompressed_U16.edf" gzippedFile = "edfGzip_U16.edf" compressedFile = "edfCompressed_U16.edf" ref.read(os.path.join(self.im_dir, refFile)) gzipped.read(os.path.join(self.im_dir, gzippedFile)) compressed.read(os.path.join(self.im_dir, compressedFile)) self.assertEqual((ref.data - gzipped.data).max(), 0, "Gzipped data block is correct") self.assertEqual((ref.data - compressed.data).max(), 0, "Zlib compressed data block is correct")
def test_read(self): """ check we can read these images""" for line in TESTIMAGES.split("\n"): vals = line.split() name = vals[0] dim1, dim2 = [int(x) for x in vals[1:3]] mini, maxi, mean, stddev = [float(x) for x in vals[3:]] obj = edfimage() try: obj.read(os.path.join(self.im_dir, name)) except Exception: logger.error("Cannot read image %s", name) raise self.assertAlmostEqual(mini, obj.getmin(), 2, "testedfs: %s getmin()" % name) self.assertAlmostEqual(maxi, obj.getmax(), 2, "testedfs: %s getmax" % name) logger.info("%s Mean: exp=%s, obt=%s" % (name, mean, obj.getmean())) self.assertAlmostEqual(mean, obj.getmean(), 2, "testedfs: %s getmean" % name) logger.info("%s StdDev: exp=%s, obt=%s" % (name, stddev, obj.getstddev())) self.assertAlmostEqual(stddev, obj.getstddev(), 2, "testedfs: %s getstddev" % name) self.assertEqual(dim1, obj.dim1, "testedfs: %s dim1" % name) self.assertEqual(dim2, obj.dim2, "testedfs: %s dim2" % name) obj = None
def test_getstats(self): """ test statistics""" obj = edfimage() obj.read(self.filename) self.assertEqual(obj.getmean(), 10) self.assertEqual(obj.getmin(), 0) self.assertEqual(obj.getmax(), 20)
def test_read(self): """ check we can read these images""" ref = edfimage() gzipped = edfimage() compressed = edfimage() refFile = "edfUncompressed_U16.edf" gzippedFile = "edfGzip_U16.edf" compressedFile = "edfCompressed_U16.edf" ref.read(os.path.join(self.im_dir, refFile)) gzipped.read(os.path.join(self.im_dir, gzippedFile)) compressed.read(os.path.join(self.im_dir, compressedFile)) self.assertEqual((ref.data - gzipped.data).max(), 0, "Gzipped data block is correct") self.assertEqual((ref.data - compressed.data).max(), 0, "Zlib compressed data block is correct")
def testBzip2(self): self.filename = os.path.join(self.tmpdir, "merged.azim.gz") e = edfimage(data=self.data, header=self.header) e.write(self.filename) r = fabio.open(self.filename) self.assertTrue(r.header["toto"] == self.header["toto"], "header are OK") self.assertTrue(abs(r.data - self.data).max() == 0, "data are OK") self.assertEqual(int(r.header["EDF_HeaderSize"]), 512, "header size is one 512 block")
def test_rebin(self): """test the rebin of edfdata""" f = edfimage() f.read(os.path.join(self.im_dir, "F2K_Seb_Lyso0675.edf")) f.rebin(1024, 1024) self.assertEqual( abs(numpy.array([[1547, 1439], [1536, 1494]]) - f.data).max(), 0, "data are the same after rebin")
def testBzip2(self): self.filename = os.path.join(self.tmpdir, "merged.azim.gz") e = edfimage(data=self.data, header=self.header) e.write(self.filename) r = fabio.open(self.filename) self.assertTrue(r.header["toto"] == self.header["toto"], "header are OK") self.assertTrue(abs(r.data - self.data).max() == 0, "data are OK") self.assertEqual(int(r.header["EDF_HeaderSize"]), 512, "header size is one 512 block")
def setUp(self): """ initialize""" self.common_setup() self.filename = os.path.join(UtilsTest.tempdir, "im0000.edf") if not os.path.isfile(self.filename): outf = open(self.filename, "wb") assert len(self.MYHEADER) % 1024 == 0 outf.write(self.MYHEADER) outf.write(self.MYIMAGE.tostring()) outf.close() obj = edfimage() obj.read(self.filename) self.obj = obj
def setUp(self): """ initialize""" self.common_setup() self.filename = os.path.join(UtilsTest.tempdir, "im0000.edf") if not os.path.isfile(self.filename): outf = open(self.filename, "wb") assert len(self.MYHEADER) % 1024 == 0 outf.write(self.MYHEADER) outf.write(self.MYIMAGE.tostring()) outf.close() obj = edfimage() obj.read(self.filename) self.obj = obj
def test_read(self): """ check readable""" obj = edfimage() obj.read(self.filename) self.assertEqual(obj.dim1, 256, msg="dim1!=256 for file: %s" % self.filename) self.assertEqual(obj.dim2, 256, msg="dim2!=256 for file: %s" % self.filename) self.assertEqual(obj.bpp, 4, msg="bpp!=4 for file: %s" % self.filename) self.assertEqual(obj.bytecode, numpy.float32, msg="bytecode!=flot32 for file: %s" % self.filename) self.assertEqual(obj.data.shape, (256, 256), msg="shape!=(256,256) for file: %s" % self.filename) self.assertEqual(obj.header['History-1'], "something=something else")
def test_bug_27(self): """ import fabio obj = fabio.open("any.edf") obj.header["missing"]="blah" obj.write("any.edf") """ # create dummy image: shape = (32, 32) data = numpy.random.randint(0, 6500, size=shape[0] * shape[1]).astype("uint16").reshape(shape) fname = os.path.join(UtilsTest.tempdir, "bug27.edf") e = edfimage(data=data, header={"key1": "value1"}) e.write(fname) del e obj = fabio.open(fname) obj.header["missing"] = "blah" obj.write(fname) del obj
def test_bug_27(self): """ import fabio obj = fabio.open("any.edf") obj.header["missing"]="blah" obj.write("any.edf") """ # create dummy image: shape = (32, 32) data = numpy.random.randint(0, 6500, size=shape[0] * shape[1]).astype("uint16").reshape(shape) fname = os.path.join(UtilsTest.tempdir, "bug27.edf") e = edfimage(data=data, header={"key1": "value1"}) e.write(fname) del e obj = fabio.open(fname) obj.header["missing"] = "blah" obj.write(fname) del obj
def test_read(self): """ check we can read these images""" for line in TESTIMAGES.split("\n"): vals = line.split() name = vals[0] dim1, dim2 = [int(x) for x in vals[1:3]] mini, maxi, mean, stddev = [float(x) for x in vals[3:]] obj = edfimage() try: obj.read(os.path.join(self.im_dir, name)) except Exception: logger.error("Cannot read image %s", name) raise self.assertAlmostEqual(mini, obj.getmin(), 2, "testedfs: %s getmin()" % name) self.assertAlmostEqual(maxi, obj.getmax(), 2, "testedfs: %s getmax" % name) logger.info("%s Mean: exp=%s, obt=%s" % (name, mean, obj.getmean())) self.assertAlmostEqual(mean, obj.getmean(), 2, "testedfs: %s getmean" % name) logger.info("%s StdDev: exp=%s, obt=%s" % (name, stddev, obj.getstddev())) self.assertAlmostEqual(stddev, obj.getstddev(), 2, "testedfs: %s getstddev" % name) self.assertEqual(dim1, obj.dim1, "testedfs: %s dim1" % name) self.assertEqual(dim2, obj.dim2, "testedfs: %s dim2" % name) obj = None
def test_rebin(self): """test the rebin of edfdata""" f = edfimage() f.read(os.path.join(self.im_dir, "F2K_Seb_Lyso0675.edf")) f.rebin(1024, 1024) self.assertEqual(abs(numpy.array([[1547, 1439], [1536, 1494]]) - f.data).max(), 0, "data are the same after rebin")
def imread(self, filepath, plugin=None): return fabio.edfimage(filepath).data