Example #1
0
    def test_writer(self):

        shape = 100, 128
        n = 10
        m = 3  # number of frames in memory
        data = numpy.random.random(
            (m, shape[0], shape[1])).astype(numpy.float32)
        nmbytes = data.nbytes / 1e6 * n / m
        t0 = time.perf_counter()
        writer = io.FabioWriter(extension=".edf")
        logger.info(writer.__repr__())
        writer.init({
            "nbpt_azim": shape[0],
            "nbpt_rad": shape[1],
            "prefix": "toto",
            "index_format": "_%04d",
            "start_index": 1,
            "directory": self.tmpdir
        })
        logger.info(writer.__repr__())

        for i in range(n):
            writer.write(data[i % m])
        writer.close()
        t = time.perf_counter() - t0
        logger.info(
            "Writing of Fabio of %ix%s (%.3fMB) took %.3f (%.3fMByte/s)", n,
            shape, nmbytes, t, nmbytes / t)
        self.assertEqual(len(os.listdir(self.tmpdir)), n)
Example #2
0
    def test_writer(self):
        # self.skipTest("Untested")

        h5file = os.path.join(self.tmpdir)
        shape = 1024, 1024
        n = 100
        m = 10  # number of frames in memory
        data = numpy.random.random(
            (m, shape[0], shape[1])).astype(numpy.float32)
        nmbytes = data.nbytes / 1e6 * n / m
        t0 = time.time()
        writer = io.FabioWriter(filename=h5file)
        writer.init({
            "nbpt_azim": shape[0],
            "nbpt_rad": shape[1],
            "prefix": "test"
        })
        for i in range(n):
            writer.write(data[i % m], i)
        writer.close()
        t = time.time() - t0
        logger.info(
            "Writing of HDF5 of %ix%s (%.3fMB) took %.3f (%.3fMByte/s)", n,
            shape, nmbytes, t, nmbytes / t)
        statinfo = os.stat(h5file)
        self.assertTrue(
            statinfo.st_size / 1e6 > nmbytes,
            "file size (%s) is larger than dataset" % statinfo.st_size)