Пример #1
0
    def testReadZarrExecution(self):
        test_array = np.random.RandomState(0).rand(20, 10)
        group_name = 'test_group'
        dataset_name = 'test_dataset'

        with self.assertRaises(TypeError):
            fromzarr(object())

        with tempfile.TemporaryDirectory() as d:
            path = os.path.join(d,
                                'test_read_{}.zarr'.format(int(time.time())))

            group = zarr.group(path)
            arr = group.array(group_name + '/' + dataset_name,
                              test_array,
                              chunks=(7, 4))

            r = fromzarr(arr)

            result = self.executor.execute_tensor(r, concat=True)[0]
            np.testing.assert_array_equal(result, test_array)
            self.assertGreater(len(get_tiled(r).chunks), 1)

            arr = zarr.open_array('{}/{}/{}'.format(path, group_name,
                                                    dataset_name))
            r = fromzarr(arr)

            result = self.executor.execute_tensor(r, concat=True)[0]
            np.testing.assert_array_equal(result, test_array)
            self.assertGreater(len(get_tiled(r).chunks), 1)

            r = fromzarr(path, group=group_name, dataset=dataset_name)

            result = self.executor.execute_tensor(r, concat=True)[0]
            np.testing.assert_array_equal(result, test_array)
            self.assertGreater(len(get_tiled(r).chunks), 1)

            r = fromzarr(path + '/' + group_name + '/' + dataset_name)

            result = self.executor.execute_tensor(r, concat=True)[0]
            np.testing.assert_array_equal(result, test_array)
            self.assertGreater(len(get_tiled(r).chunks), 1)
Пример #2
0
def test_read_zarr_execution(setup):
    session = setup

    test_array = np.random.RandomState(0).rand(20, 10)
    group_name = 'test_group'
    dataset_name = 'test_dataset'

    with pytest.raises(TypeError):
        fromzarr(object())

    with tempfile.TemporaryDirectory() as d:
        path = os.path.join(d, f'test_read_{int(time.time())}.zarr')

        group = zarr.group(path)
        arr = group.array(group_name + '/' + dataset_name, test_array, chunks=(7, 4))

        r = fromzarr(arr)

        result = r.execute().fetch()
        np.testing.assert_array_equal(result, test_array)
        assert len(session._session._tileable_to_fetch[r.data].chunks) > 1

        arr = zarr.open_array(f'{path}/{group_name}/{dataset_name}')
        r = fromzarr(arr)

        result = r.execute().fetch()
        np.testing.assert_array_equal(result, test_array)
        assert len(session._session._tileable_to_fetch[r.data].chunks) > 1

        r = fromzarr(path, group=group_name, dataset=dataset_name)

        result = r.execute().fetch()
        np.testing.assert_array_equal(result, test_array)
        assert len(session._session._tileable_to_fetch[r.data].chunks) > 1

        r = fromzarr(path + '/' + group_name + '/' + dataset_name)

        result = r.execute().fetch()
        np.testing.assert_array_equal(result, test_array)
        assert len(session._session._tileable_to_fetch[r.data].chunks) > 1