Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
annshress committed Sep 1, 2023
1 parent ae81ec8 commit 8e65cc8
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ flake8
black
wheel
packaging
-rrequirements.txt
-r requirements.txt
Empty file added test/__init__.py
Empty file.
34 changes: 24 additions & 10 deletions test/test_HedwigZarrImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,38 @@ def temp_zarr_path(request, tmp_path_factory, data_path):


@pytest.mark.parametrize(
"zarr_name",
["2013-1220-dA30_5-BSC-1_22_full_rec.zarr", "OM_P1_S1_ScanOnly_1k.zarr", "OM_P1_S1_ScanOnly_1k_tiff.zarr"],
"zarr_name, image_ext, array_shape, dims, shader_type, ngff_dims, shader_params",
[
(
"2013-1220-dA30_5-BSC-1_22_full_rec.zarr",
"mrc",
(1, 1, 512, 87, 512),
"XYZ",
"Grayscale",
"TCZYX",
{"window": [263, 413], "range": [-2664, 1677]},
),
("OM_P1_S1_ScanOnly_1k.zarr", "png", (1, 3, 1, 1024, 521), "XYC", "RGB", "TCZYX", {}),
("OM_P1_S1_ScanOnly_1k_tiff.zarr", "tiff", (1, 3, 1, 1024, 521), "XYC", "RGB", "TCZYX", {}),
],
)
def test_HedwigZarrImage_info(data_path, zarr_name):
def test_HedwigZarrImage_info(
data_path, zarr_name, image_ext, array_shape, dims, shader_type, ngff_dims, shader_params
):
zi = HedwigZarrImages(data_path / zarr_name)
keys = list(zi.get_series_keys())
print(f"zarr groups: {keys}")

print(zi.ome_xml_path)

for k, z_img in zi.series():
print(f'image name: "{k}"')
print(f"\tarray shape: {z_img.shape}")
print(f"\tzarr path: {z_img.path}")
print(f"\tdims: {z_img.dims}")
print(f"\tshader type: {z_img.shader_type}")
print(f"\tNGFF dims: {z_img._ome_ngff_multiscale_dims()}")
print(f"\tshader params: {json.dumps(z_img.neuroglancer_shader_parameters())}")
assert image_ext in k
assert array_shape == z_img.shape
print(f"{z_img.path=}")
assert dims == z_img.dims
assert shader_type == z_img.shader_type
assert ngff_dims == z_img._ome_ngff_multiscale_dims()
assert shader_params == z_img.neuroglancer_shader_parameters()


@pytest.mark.parametrize(
Expand Down
31 changes: 29 additions & 2 deletions test/test_zarr_rechunk.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
from click.testing import CliRunner
import pytools.zarr_rechunk
import shutil
from pathlib import Path
import pytest
import pytools.zarr_rechunk
from pytools.HedwigZarrImages import HedwigZarrImages

args = ["--help", "--version"]


@pytest.mark.parametrize("cli_args", args)
def test_mrc2nifti_main_help(cli_args):
def test_zarr_rechunk_main_help(cli_args):
runner = CliRunner()
result = runner.invoke(pytools.zarr_rechunk.main, cli_args.split())
assert not result.exception


@pytest.mark.parametrize("chunk_size", [512, 64])
def test_zarr_rechunk_main(image_ome_ngff, chunk_size):
runner = CliRunner()
with runner.isolated_filesystem():
local_path = image_ome_ngff.name
shutil.copytree(image_ome_ngff, local_path)

result = runner.invoke(pytools.zarr_rechunk.main, args=[str(local_path), "--chunk-size", chunk_size])
assert not result.exception

zi = HedwigZarrImages(Path(local_path).absolute(), read_only=False)
for k, hzi in zi.series():
for level in range(len(hzi._ome_ngff_multiscales()["datasets"])):
arr = hzi._ome_ngff_multiscale_get_array(level)
# check for expected chunking
for s, c, d in zip(arr.shape, arr.chunks, hzi._ome_ngff_multiscale_dims()):
if d == "T":
assert s == 1
elif d == "C" or s < target_chunk:
assert s == c
else:
assert c == target_chunk

0 comments on commit 8e65cc8

Please sign in to comment.