Skip to content

Commit a3f0b2c

Browse files
committed
Adding extra tests
1 parent b7d54af commit a3f0b2c

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

tests/integration/converters/test_nifti.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import json
2+
13
import nibabel as nib
24
import numpy as np
35
import pytest
46

57
import tiledb
68
from tests import get_path
9+
from tiledb.bioimg.converters import DATASET_TYPE, FMT_VERSION
710
from tiledb.bioimg.converters.nifti import NiftiConverter
11+
from tiledb.bioimg.openslide import TileDBOpenSlide
12+
from tiledb.cc import WebpInputFormat
813

914

1015
def compare_nifti_images(file1, file2, scaled_test):
@@ -43,7 +48,9 @@ def compare_nifti_images(file1, file2, scaled_test):
4348
@pytest.mark.parametrize(
4449
"compressor, lossless",
4550
[
46-
(tiledb.ZstdFilter(level=0), False),
51+
(tiledb.ZstdFilter(level=0), True),
52+
# (tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True), True),
53+
(tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True), True),
4754
# WEBP is not supported for Grayscale images
4855
],
4956
)
@@ -71,3 +78,40 @@ def test_nifti_converter_roundtrip(
7178
output_path,
7279
scaled_test=False if filename == "nifti/visiblehuman.nii" else True,
7380
)
81+
82+
83+
@pytest.mark.parametrize(
84+
"filename, axes, canonical",
85+
[
86+
("nifti/example4d.nii", "XYZT", "TZYX"),
87+
("nifti/functional.nii", "XYZT", "TZYX"),
88+
("nifti/standard.nii", "XYZ", "ZYX"),
89+
("nifti/visiblehuman.nii", "XYZTC", "CZYX"),
90+
("nifti/anatomical.nii", "XYZ", "ZYX"),
91+
],
92+
)
93+
def test_nifti_converter_group_metadata(tmp_path, filename, axes, canonical):
94+
input_path = get_path(filename)
95+
tiledb_path = str(tmp_path / "to_tiledb")
96+
NiftiConverter.to_tiledb(input_path, tiledb_path, preserve_axes=False)
97+
98+
with TileDBOpenSlide(tiledb_path) as t:
99+
group_properties = t.properties
100+
assert group_properties["dataset_type"] == DATASET_TYPE
101+
assert group_properties["fmt_version"] == FMT_VERSION
102+
assert isinstance(group_properties["pkg_version"], str)
103+
assert group_properties["axes"] == axes
104+
105+
levels_group_meta = json.loads(group_properties["levels"])
106+
assert t.level_count == len(levels_group_meta)
107+
for level, level_meta in enumerate(levels_group_meta):
108+
assert level_meta["level"] == level
109+
assert level_meta["name"] == f"l_{level}.tdb"
110+
111+
level_axes = level_meta["axes"]
112+
shape = level_meta["shape"]
113+
level_width, level_height = t.level_dimensions[level]
114+
assert level_axes == canonical
115+
assert len(shape) == len(level_axes)
116+
assert shape[level_axes.index("X")] == level_width
117+
assert shape[level_axes.index("Y")] == level_height

0 commit comments

Comments
 (0)