Skip to content

Commit

Permalink
Extract method to create simple fixure
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Apr 15, 2021
1 parent bb3f103 commit 2dbf416
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions fixtures/generate_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
import os

import zarr # 2.7
import zarr
from zarr.creation import create # 2.7
from zarr.util import json_dumps, json_loads

FIXTURES_FOLDER = "./"


def generate_fixtures():

empty_path = os.path.join(FIXTURES_FOLDER, "empty.zarr")
zarr.open(
empty_path,
def create_simple_array(store, dtype, compression=None, write_chunks=False):
arr = zarr.open(
store=store,
shape=(8, 8),
chunks=(2, None),
dtype="<i4",
dtype=dtype,
fill_value=0,
mode="w",
compressor=None,
compression=compression,
)
if write_chunks:
arr[0, 0] = 1
arr[0, 1] = 2
arr[7, 7] = 3


def generate_fixtures():

# Empty fixture
create_simple_array(os.path.join(FIXTURES_FOLDER, "empty.zarr"), dtype="<i4")

# little endian
for codec in (None, "gzip", "zlib"):
simple_path = os.path.join(
path = os.path.join(
FIXTURES_FOLDER, "simple{}_LE.zarr".format(f"_{codec}" if codec else "")
)
simple_zarr_array = zarr.open(
simple_path,
shape=(8, 8),
chunks=(2, None),
create_simple_array(
store=path,
dtype="<i4",
fill_value=0,
mode="w",
compression=codec,
write_chunks=True,
)
simple_zarr_array[0, 0] = 1
simple_zarr_array[0, 1] = 2
simple_zarr_array[7, 7] = 3

# big endian
for codec in (None, "gzip", "zlib"):
simple_path = os.path.join(
path = os.path.join(
FIXTURES_FOLDER, "simple{}_BE.zarr".format(f"_{codec}" if codec else "")
)
simple_zarr_array = zarr.open(
simple_path,
shape=(8, 8),
chunks=(2, None),
create_simple_array(
store=path,
dtype=">i4",
fill_value=0,
mode="w",
compression=codec,
write_chunks=True,
)
simple_zarr_array[0, 0] = 1
simple_zarr_array[0, 1] = 2
simple_zarr_array[7, 7] = 3

# nested
# TODO: Use latest zarr-python once https://github.com/zarr-developers/zarr-python/pull/716 is merged
Expand All @@ -62,19 +59,7 @@ def generate_fixtures():
key_separator="/",
auto_mkdir=True,
)

nested = zarr.open(
store,
shape=(8, 8),
chunks=(2, None),
dtype=">i4",
fill_value=0,
mode="w",
)
nested[0, 0] = 1
nested[0, 1] = 2
nested[7, 7] = 3

create_simple_array(store=store, dtype=">i4", compression='blosc', write_chunks=True)
# Manually add dimension separator to array meta
meta = json_loads(store[".zarray"])
meta["dimension_separator"] = "/"
Expand Down
Binary file modified fixtures/simple_gzip_BE.zarr/0.0
Binary file not shown.
Binary file modified fixtures/simple_gzip_BE.zarr/3.0
Binary file not shown.
Binary file modified fixtures/simple_gzip_LE.zarr/0.0
Binary file not shown.
Binary file modified fixtures/simple_gzip_LE.zarr/3.0
Binary file not shown.

0 comments on commit 2dbf416

Please sign in to comment.