Beispiel #1
0
 def testRebin(self):
     """Test the rebin method"""
     big = numpy.arange(64).reshape((8, 8))
     res = numpy.array([[13, 17], [45, 49]])
     fabimg = fabioimage(data=big, header={})
     fabimg.rebin(4, 4)
     self.assertEqual(abs(res - fabimg.data).max(), 0, "data are the same after rebin")
Beispiel #2
0
 def setUp(self):
     """make the image"""
     dat = numpy.ones((1024, 1024), numpy.uint16)
     dat = (dat * 50000).astype(numpy.uint16)
     assert dat.dtype.char == numpy.ones((1), numpy.uint16).dtype.char
     hed = {"Title": "50000 everywhere"}
     self.obj = fabioimage(dat, hed)
Beispiel #3
0
 def setUp(self):
     """make the image"""
     dat = numpy.ones((1024, 1024), numpy.uint16)
     dat = (dat * 50000).astype(numpy.uint16)
     assert dat.dtype.char == numpy.ones((1), numpy.uint16).dtype.char
     hed = {"Title": "50000 everywhere"}
     self.obj = fabioimage(dat, hed)
Beispiel #4
0
    def testpil(self):

        for typ in self.okformats:
            name = NAMES[typ]
            for shape in [(10, 20), (431, 1325)]:
                testdata = self.mkdata(shape, typ)
                img = fabioimage(testdata, {"title":"Random data"})
                pim = img.toPIL16()
                for i in [ 0, 5, 6, shape[1] - 1 ]:
                    for j in [0, 5, 7, shape[0] - 1 ]:
                        errstr = name + " %d %d %f %f t=%s" % (
                            i, j, testdata[j, i], pim.getpixel((i, j)), typ)

                        er1 = img.data[j, i] - pim.getpixel((i, j))
                        er2 = img.data[j, i] + pim.getpixel((i, j))

                        # difference as % error in case of rounding
                        if er2 != 0.:
                            err = er1 / er2
                        else:
                            err = er1

                        self.assertAlmostEquals(err,
                                                 0,
                                                 6,
                                                 errstr)
Beispiel #5
0
 def testRebin(self):
     """Test the rebin method"""
     big = numpy.arange(64).reshape((8, 8))
     res = numpy.array([[13, 17], [45, 49]])
     fabimg = fabioimage(data=big, header={})
     fabimg.rebin(4, 4)
     self.assertEqual(
         abs(res - fabimg.data).max(), 0, "data are the same after rebin")
Beispiel #6
0
 def setUp(self):
     """ create test files"""
     if not os.path.isfile(self.testfile):
         open(self.testfile, "wb").write("{ hello }")
     if not os.path.isfile(self.testfile + ".gz"):
         gzip.open(self.testfile + ".gz", "wb").write("{ hello }")
     if not os.path.isfile(self.testfile + ".bz2"):
         bz2.BZ2File(self.testfile + ".bz2", "wb").write("{ hello }")
     self.obj = fabioimage()
Beispiel #7
0
 def setUp(self):
     """ create test files"""
     if not os.path.isfile(self.testfile):
         open(self.testfile, "wb").write(b"{ hello }")
     if not os.path.isfile(self.testfile + ".gz"):
         gzip.open(self.testfile + ".gz", "wb").write(b"{ hello }")
     if not os.path.isfile(self.testfile + ".bz2"):
         bz2.BZ2File(self.testfile + ".bz2", "wb").write(b"{ hello }")
     self.obj = fabioimage()
Beispiel #8
0
 def setUp(self):
     """make test data"""
     dat2 = numpy.zeros((1024, 1024), numpy.uint16)
     hed = {"Title": "zeros and 100"}
     self.cord = [256, 256, 790, 768]
     self.obj = fabioimage(dat2, hed)
     self.slic = slic = self.obj.make_slice(self.cord)
     # Note - d2 is modified *after* fabioimage is made
     dat2[slic] = dat2[slic] + 100
     assert self.obj.maxval is None
     assert self.obj.minval is None
     self.npix = (slic[0].stop - slic[0].start) * (slic[1].stop - slic[1].start)
Beispiel #9
0
 def setUp(self):
     """make test data"""
     dat2 = numpy.zeros((1024, 1024), numpy.uint16)
     hed = {"Title": "zeros and 100"}
     self.cord = [256, 256, 790, 768]
     self.obj = fabioimage(dat2, hed)
     self.slic = slic = self.obj.make_slice(self.cord)
     # Note - d2 is modified *after* fabioimage is made
     dat2[slic] = dat2[slic] + 100
     assert self.obj.maxval is None
     assert self.obj.minval is None
     self.npix = (slic[0].stop - slic[0].start) * \
         (slic[1].stop - slic[1].start)
Beispiel #10
0
    def testpil(self):

        for typ in self.okformats:
            name = NAMES[typ]
            for shape in [(10, 20), (431, 1325)]:
                testdata = self.mkdata(shape, typ)
                img = fabioimage(testdata, {"title": "Random data"})
                pim = img.toPIL16()
                for i in [0, 5, 6, shape[1] - 1]:
                    for j in [0, 5, 7, shape[0] - 1]:
                        errstr = name + " %d %d %f %f t=%s" % (
                            i, j, testdata[j, i], pim.getpixel((i, j)), typ)

                        er1 = img.data[j, i] - pim.getpixel((i, j))
                        er2 = img.data[j, i] + pim.getpixel((i, j))

                        # difference as % error in case of rounding
                        if er2 != 0.:
                            err = er1 / er2
                        else:
                            err = er1

                        self.assertAlmostEquals(err, 0, 6, errstr)
Beispiel #11
0
 def frm(i):
     header['Omega'] = omega[i]
     f = fabioimage(data[i], header)
     f.filename = filename
     f.currentframe = i
     return f