示例#1
0
    def test_hdf5_read_from_non_chunked(self):
        import nifty.hdf5 as nhdf5
        fpath = os.path.join(self.tempFolder, '_nifty_test_array_.h5')

        shape = (101, 102, 103)
        data = numpy.ones(shape=shape, dtype='uint64')
        with h5py.File(fpath, 'a') as f:
            f.create_dataset("data", shape, dtype='uint64', data=data)

        hidT = nhdf5.openFile(fpath)
        array = nhdf5.Hdf5ArrayUInt64(hidT, "data")

        ashape = array.shape
        self.assertEqual(array.ndim, 3)
        self.assertEqual(len(ashape), 3)
        self.assertEqual(shape, tuple(ashape))

        self.assertFalse(array.isChunked)
        chunkShape = array.chunkShape
        self.assertEqual(len(chunkShape), 3)
        self.assertEqual(tuple(chunkShape), shape)

        subarray = array[0:10, 0:10, 0:10]
        expected = data[0:10, 0:10, 0:10]
        self.assertEqual(subarray.shape, expected.shape)
        self.assertTrue(numpy.allclose(subarray, expected))
示例#2
0
    def test_create_zipped_array(self):
        import nifty.hdf5 as nhdf5
        fpath = os.path.join(self.tempFolder, '_nifty_test_array_.h5')

        shape = [101,102,103]
        chunks = [11,12,13]
        hidT = nhdf5.createFile(fpath)
        array = nhdf5.Hdf5ArrayUInt64(
            groupHandle=hidT,
            datasetName="data",
            shape=shape,
            chunkShape=chunks,
            compression=9
        )

        ashape = array.shape
        self.assertEqual(array.ndim, 3)
        self.assertEqual(shape, ashape)

        chunkShape = array.chunkShape
        self.assertEqual(chunkShape, chunks)

        ends = [10,11,12]

        toWrite = numpy.arange(ends[0]*ends[1]*ends[2]).reshape(ends)
        array[0:ends[0], 0:ends[1], 0:ends[2]] = toWrite
        subarray = array[0:ends[0], 0:ends[1], 0:ends[2]]

        self.assertTrue(numpy.array_equal(toWrite, subarray))