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
8
12
9
13
10
14
def compare_nifti_images (file1 , file2 , scaled_test ):
@@ -43,8 +47,8 @@ def compare_nifti_images(file1, file2, scaled_test):
43
47
@pytest .mark .parametrize (
44
48
"compressor, lossless" ,
45
49
[
46
- (tiledb .ZstdFilter (level = 0 ), False ),
47
- # WEBP is not supported for Grayscale images
50
+ (tiledb .ZstdFilter (level = 0 ), True ),
51
+ # WEBP is not supported for these images
48
52
],
49
53
)
50
54
def test_nifti_converter_roundtrip (
@@ -71,3 +75,40 @@ def test_nifti_converter_roundtrip(
71
75
output_path ,
72
76
scaled_test = False if filename == "nifti/visiblehuman.nii" else True ,
73
77
)
78
+
79
+
80
+ @pytest .mark .parametrize (
81
+ "filename, axes, canonical" ,
82
+ [
83
+ ("nifti/example4d.nii" , "XYZT" , "TZYX" ),
84
+ ("nifti/functional.nii" , "XYZT" , "TZYX" ),
85
+ ("nifti/standard.nii" , "XYZ" , "ZYX" ),
86
+ ("nifti/visiblehuman.nii" , "XYZTC" , "CZYX" ),
87
+ ("nifti/anatomical.nii" , "XYZ" , "ZYX" ),
88
+ ],
89
+ )
90
+ def test_nifti_converter_group_metadata (tmp_path , filename , axes , canonical ):
91
+ input_path = get_path (filename )
92
+ tiledb_path = str (tmp_path / "to_tiledb" )
93
+ NiftiConverter .to_tiledb (input_path , tiledb_path , preserve_axes = False )
94
+
95
+ with TileDBOpenSlide (tiledb_path ) as t :
96
+ group_properties = t .properties
97
+ assert group_properties ["dataset_type" ] == DATASET_TYPE
98
+ assert group_properties ["fmt_version" ] == FMT_VERSION
99
+ assert isinstance (group_properties ["pkg_version" ], str )
100
+ assert group_properties ["axes" ] == axes
101
+
102
+ levels_group_meta = json .loads (group_properties ["levels" ])
103
+ assert t .level_count == len (levels_group_meta )
104
+ for level , level_meta in enumerate (levels_group_meta ):
105
+ assert level_meta ["level" ] == level
106
+ assert level_meta ["name" ] == f"l_{ level } .tdb"
107
+
108
+ level_axes = level_meta ["axes" ]
109
+ shape = level_meta ["shape" ]
110
+ level_width , level_height = t .level_dimensions [level ]
111
+ assert level_axes == canonical
112
+ assert len (shape ) == len (level_axes )
113
+ assert shape [level_axes .index ("X" )] == level_width
114
+ assert shape [level_axes .index ("Y" )] == level_height
0 commit comments