Skip to content

Commit

Permalink
Add tests for get_metadata_for_zarr
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Mar 14, 2024
1 parent 8949375 commit 41c43b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
9 changes: 6 additions & 3 deletions brainglobe_stitch/image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,10 @@ def fuse(
self._fuse_to_bdv_h5(output_path, fused_image_shape)

def _fuse_to_zarr(
self, output_path: Path, fused_image_shape: Tuple[int, ...]
self,
output_path: Path,
fused_image_shape: Tuple[int, ...],
pyramid_depth: int = 6,
) -> None:
"""
Fuse the tiles in the ImageMosaic into a single image and save it as a
Expand All @@ -613,7 +616,7 @@ def _fuse_to_zarr(
chunk_shape: Tuple[int, ...] = (256, 256, 256)

transformation_metadata, axes_metadata = self.get_metadata_for_zarr(
pyramid_depth=6
pyramid_depth=pyramid_depth
)

if self.num_channels > 1:
Expand Down Expand Up @@ -846,7 +849,7 @@ def _fuse_to_bdv_h5(
output_file.close()

def get_metadata_for_zarr(
self, pyramid_depth: int = 5
self, pyramid_depth: int = 6
) -> Tuple[List[List[Dict]], List[Dict]]:
"""
Prepare the metadata for a zarr file.
Expand Down
46 changes: 41 additions & 5 deletions tests/test_unit/test_image_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,49 @@ def test_fuse(
mock_interpolate_overlaps.assert_not_called()


def test_fuse_to_zarr():
pass
@pytest.mark.parametrize(
"pyramid_depth, num_channels",
[(1, 1), (1, 2), (1, 5), (2, 1), (2, 2), (2, 5), (3, 1), (3, 2), (3, 5)],
)
def test_get_metadata_for_zarr(image_mosaic, pyramid_depth, num_channels):
temp_num_channels = image_mosaic.num_channels
image_mosaic.num_channels = num_channels

metadata, axes = image_mosaic.get_metadata_for_zarr(pyramid_depth)

def test_fuse_to_bdv_h5():
pass
if num_channels > 1:
assert len(axes) == 4
assert axes[0]["name"] == "c"
assert axes[0]["type"] == "channel"
axes.pop(0)
else:
assert len(axes) == 3

expected_axes_names = ["z", "y", "x"]

for idx, axes in enumerate(axes):
assert axes["name"] == expected_axes_names[idx]
assert axes["type"] == "space"
assert axes["unit"] == "micrometer"

def test_get_metadata_for_zarr():
for idx, transformation in enumerate(metadata):
assert transformation[0]["type"] == "scale"
expected_scale = [
image_mosaic.z_resolution,
image_mosaic.x_y_resolution * 2**idx,
image_mosaic.x_y_resolution * 2**idx,
]
if num_channels > 1:
expected_scale.insert(0, 1)

assert transformation[0]["scale"] == expected_scale

image_mosaic.num_channels = temp_num_channels


def test_fuse_to_zarr(image_mosaic):
image_mosaic.xml_path.parent / "fused.zarr"


def test_fuse_to_bdv_h5():
pass

0 comments on commit 41c43b8

Please sign in to comment.