Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using zarr-dev to potentially catch regressions. #15

Merged
merged 12 commits into from
Feb 5, 2021
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
channels: conda-forge,ome
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

- name: Run tests
shell: bash -l {0}
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/zarr-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Build with Zarr dev

on: [push, pull_request]

jobs:
test:
name: ${{ matrix.platform }} ${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}

strategy:
fail-fast: true
matrix:
platform: [ubuntu-latest]
python-version: [3.7]

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
channels: conda-forge,ome
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
Carreau marked this conversation as resolved.
Show resolved Hide resolved
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

- name: Install zarr dev
shell: bash -l {0}
run: |
python -m pip install git+https://github.com/zarr-developers/zarr-python.git@master

- name: Run tests
shell: bash -l {0}
run: make
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- openjdk
- maven
- make
- z5py
- z5py >= 2.0.8
- python == 3.7.9
- scikit-image
- pytest
Expand Down
16 changes: 10 additions & 6 deletions generate_data/generate_z5py.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@
CHUNKS = (100, 100, 1)

# options for the different compressors
COMPRESSION_OPTIONS = {'blosc': {'filter_id': 'lz4'}}
COMPRESSION_OPTIONS = {"blosc": {"codec": "lz4"}}


# TODO support more compressors:
# - more compressors in numcodecs
# - more blosc codecs
def generate_zarr_format(compressors=['gzip', 'blosc', 'zlib', 'raw']):
path = '../data/z5py.zr'
path = 'data/z5py.zr'
im = astronaut()

f = z5py.File(path)
f = z5py.File(path, mode='w')
for compressor in compressors:
copts = COMPRESSION_OPTIONS.get(compressor, {})
name = compressor if compressor != 'blosc' else '%s/%s' % (compressor, copts.get('filter_id'))
name = (
compressor
if compressor != "blosc"
else "%s/%s" % (compressor, copts.get("codec"))
)
f.create_dataset(name, data=im, compression=compressor, chunks=CHUNKS, **copts)


def generate_n5_format(compressors=['gzip', 'raw']):
path = '../data/z5py.n5'
path = 'data/z5py.n5'
im = astronaut()

f = z5py.File(path)
f = z5py.File(path, mode='w')
for compressor in compressors:
name = compressor
f.create_dataset(name, data=im, chunks=CHUNKS, compression=compressor)
Expand Down
27 changes: 14 additions & 13 deletions generate_data/generate_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@

# choose chunks s.t. we do have overhanging edge-chunks
CHUNKS = (100, 100, 1)
STR_TO_COMPRESSOR = {'gzip': numcodecs.GZip,
'blosc': numcodecs.Blosc,
'zlib': numcodecs.Zlib}
COMPRESSION_OPTIONS = {'blosc': {'filter_id': 'lz4'}}
STR_TO_COMPRESSOR = {
"gzip": numcodecs.GZip,
"blosc": numcodecs.Blosc,
"zlib": numcodecs.Zlib,
}
COMPRESSION_OPTIONS = {"blosc": {"cname": "lz4"}}


# TODO use more compressors from numcodecs and more blosc filter_ids
def generate_zarr_format(compressors=['gzip', 'blosc', 'zlib', None]):
path = '../data/zarr.zr'
path = 'data/zarr.zr'
im = astronaut()

f = zarr.open(path)
f = zarr.open(path, mode='w')
for compressor in compressors:
copts = COMPRESSION_OPTIONS.get(compressor, {})
if compressor is None:
name = 'taw'
elif compressor == 'blosc':
name = '%s/%s' % (compressor, copts.get('filter_id'))
name = "raw"
elif compressor == "blosc":
name = "%s/%s" % (compressor, copts.get("cname"))
else:
name = compressor
compressor_impl = STR_TO_COMPRESSOR[compressor](**copts) if compressor is not None else None
f.create_dataset(name, data=im, chunks=CHUNKS,
compressor=compressor_impl)


# this needs PR https://github.com/zarr-developers/zarr/pull/309
def generate_n5_format(compressors=['gzip', None]):
path = '../data/zarr.n5'
path = 'data/zarr.n5'
im = astronaut()

f = zarr.open(path)
f = zarr.open(path, mode='w')
for compressor in compressors:
name = compressor if compressor is not None else 'raw'
compressor_impl = STR_TO_COMPRESSOR[compressor] if compressor is not None else None
compressor_impl = STR_TO_COMPRESSOR[compressor]() if compressor is not None else None
f.create_dataset(name, data=im, chunks=CHUNKS,
compressor=compressor_impl)

Expand Down
4 changes: 4 additions & 0 deletions test/test_read_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

def read_with_zarr(fpath, ds_name):
import zarr
if ds_name == "blosc":
ds_name = "blosc/lz4"
return zarr.open(os.fspath(fpath))[ds_name][:]


Expand All @@ -50,6 +52,8 @@ def read_with_pyn5(fpath, ds_name):

def read_with_z5py(fpath, ds_name):
import z5py
if ds_name == "blosc":
ds_name = "blosc/lz4"
return z5py.File(fpath)[ds_name][:]


Expand Down