예제 #1
0
    def testStoreZarrExecution(self):
        raw = np.random.RandomState(0).rand(10, 20)

        group_name = 'test_group'
        dataset_name = 'test_dataset'

        t = tensor(raw, chunk_size=6)

        with self.assertRaises(TypeError):
            tozarr(object(), t)

        with tempfile.TemporaryDirectory() as d:
            filename = os.path.join(
                d, 'test_store_{}.zarr'.format(int(time.time())))
            path = '{}/{}/{}'.format(filename, group_name, dataset_name)

            r = tozarr(filename,
                       t,
                       group=group_name,
                       dataset=dataset_name,
                       compressor=Zstd(level=3))
            self.executor.execute_tensor(r)

            arr = zarr.open(path)
            np.testing.assert_array_equal(arr, raw)
            self.assertEqual(arr.compressor, Zstd(level=3))

            r = tozarr(path, t + 2)
            self.executor.execute_tensor(r)

            arr = zarr.open(path)
            np.testing.assert_array_equal(arr, raw + 2)

            filters = [Delta(dtype='i4')]
            compressor = Blosc(cname='zstd', clevel=1, shuffle=Blosc.SHUFFLE)
            arr = zarr.open(path, compressor=compressor, filters=filters)

            r = tozarr(arr, t + 1)
            self.executor.execute_tensor(r)
            result = zarr.open_array(path)
            np.testing.assert_array_equal(result, raw + 1)
예제 #2
0
def test_store_zarr_execution(setup):
    raw = np.random.RandomState(0).rand(10, 20)

    group_name = 'test_group'
    dataset_name = 'test_dataset'

    t = tensor(raw, chunk_size=6)

    with pytest.raises(TypeError):
        tozarr(object(), t)

    with tempfile.TemporaryDirectory() as d:
        filename = os.path.join(d, f'test_store_{int(time.time())}.zarr')
        path = f'{filename}/{group_name}/{dataset_name}'

        r = tozarr(filename,
                   t,
                   group=group_name,
                   dataset=dataset_name,
                   compressor=Zstd(level=3))
        r.execute()

        arr = zarr.open(path)
        np.testing.assert_array_equal(arr, raw)
        assert arr.compressor == Zstd(level=3)

        r = tozarr(path, t + 2)
        r.execute()

        arr = zarr.open(path)
        np.testing.assert_array_equal(arr, raw + 2)

        filters = [Delta(dtype='i4')]
        compressor = Blosc(cname='zstd', clevel=1, shuffle=Blosc.SHUFFLE)
        arr = zarr.open(path, compressor=compressor, filters=filters)

        r = tozarr(arr, t + 1)
        r.execute()
        result = zarr.open_array(path)
        np.testing.assert_array_equal(result, raw + 1)