|
| 1 | +import json |
| 2 | + |
1 | 3 | import nibabel as nib
|
2 | 4 | import numpy as np
|
3 | 5 | import pytest
|
4 | 6 |
|
5 | 7 | import tiledb
|
6 | 8 | from tests import get_path
|
| 9 | +from tiledb.bioimg.converters import DATASET_TYPE, FMT_VERSION |
7 | 10 | from tiledb.bioimg.converters.nifti import NiftiConverter
|
| 11 | +from tiledb.bioimg.openslide import TileDBOpenSlide |
| 12 | +from tiledb.cc import WebpInputFormat |
8 | 13 |
|
9 | 14 |
|
10 | 15 | def compare_nifti_images(file1, file2, scaled_test):
|
@@ -43,7 +48,9 @@ def compare_nifti_images(file1, file2, scaled_test):
|
43 | 48 | @pytest.mark.parametrize(
|
44 | 49 | "compressor, lossless",
|
45 | 50 | [
|
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), |
47 | 54 | # WEBP is not supported for Grayscale images
|
48 | 55 | ],
|
49 | 56 | )
|
@@ -71,3 +78,40 @@ def test_nifti_converter_roundtrip(
|
71 | 78 | output_path,
|
72 | 79 | scaled_test=False if filename == "nifti/visiblehuman.nii" else True,
|
73 | 80 | )
|
| 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