Skip to content

Commit 4d3ff12

Browse files
authored
Use exposed type (#148)
1 parent 436d074 commit 4d3ff12

File tree

12 files changed

+75
-65
lines changed

12 files changed

+75
-65
lines changed

tests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import tiledb
88
from tiledb.bioimg import ATTR_NAME
9-
from tiledb.libtiledb import WebpInputFormat
9+
from tiledb.filter import WebpFilter
1010
from tiledb.bioimg.helpers import merge_ned_ranges
1111
import xml.etree.ElementTree as ET
1212

@@ -24,11 +24,11 @@ def get_schema(x_size, y_size, c_size=3, compressor=tiledb.ZstdFilter(level=0)):
2424
if isinstance(compressor, tiledb.WebpFilter):
2525
x_size *= c_size
2626
x_tile *= c_size
27-
if compressor.input_format == WebpInputFormat.WEBP_NONE:
27+
if compressor.input_format == WebpFilter.WebpInputFormat.WEBP_NONE:
2828
if c_size == 3:
29-
input_format = WebpInputFormat.WEBP_RGB
29+
input_format = WebpFilter.WebpInputFormat.WEBP_RGB
3030
elif c_size == 4:
31-
input_format = WebpInputFormat.WEBP_RGBA
31+
input_format = WebpFilter.WebpInputFormat.WEBP_RGBA
3232
else:
3333
assert False, f"No WebpInputFormat with pixel_depth={c_size}"
3434
compressor = tiledb.WebpFilter(

tests/integration/converters/test_ome_tiff.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from tiledb.bioimg.converters.ome_tiff import OMETiffConverter
1313
from tiledb.bioimg.helpers import open_bioimg
1414
from tiledb.bioimg.openslide import TileDBOpenSlide
15-
from tiledb.libtiledb import WebpInputFormat
15+
from tiledb.filter import WebpFilter
1616

1717

1818
def test_ome_tiff_converter(tmp_path):
@@ -101,9 +101,9 @@ def test_ome_tiff_converter_group_metadata(tmp_path, filename):
101101
"compressor",
102102
[
103103
tiledb.ZstdFilter(level=0),
104-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False),
105-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True),
106-
tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True),
104+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False),
105+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True),
106+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True),
107107
],
108108
)
109109
def test_ome_tiff_converter_exclude_original_metadata(
@@ -138,9 +138,9 @@ def test_ome_tiff_converter_exclude_original_metadata(
138138
"compressor",
139139
[
140140
tiledb.ZstdFilter(level=0),
141-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False),
142-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True),
143-
tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True),
141+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False),
142+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True),
143+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True),
144144
],
145145
)
146146
def test_ome_tiff_converter_roundtrip(
@@ -235,8 +235,8 @@ def compare_tiff(t1: tifffile.TiffFile, t2: tifffile.TiffFile, lossless: bool =
235235
compressors = [
236236
None,
237237
tiledb.ZstdFilter(level=0),
238-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False),
239-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True),
238+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False),
239+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True),
240240
]
241241

242242

tests/integration/converters/test_ome_tiff_experimental.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tiledb.bioimg.converters.ome_tiff import OMETiffConverter
88
from tiledb.bioimg.helpers import open_bioimg
99
from tiledb.bioimg.openslide import TileDBOpenSlide
10-
from tiledb.libtiledb import WebpInputFormat
10+
from tiledb.filter import WebpFilter
1111

1212

1313
# We need to expand on the test files. Most of the test files we have currently are not memory
@@ -169,6 +169,6 @@ def compare_tiff(t1: tifffile.TiffFile, t2: tifffile.TiffFile, lossless: bool =
169169
compressors = [
170170
None,
171171
tiledb.ZstdFilter(level=0),
172-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False),
173-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True),
172+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False),
173+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True),
174174
]

tests/integration/converters/test_ome_zarr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from tiledb.bioimg.converters.ome_zarr import OMEZarrConverter
1212
from tiledb.bioimg.helpers import iter_color, open_bioimg
1313
from tiledb.bioimg.openslide import TileDBOpenSlide
14-
from tiledb.libtiledb import WebpInputFormat
14+
from tiledb.filter import WebpFilter
1515

1616
schemas = (get_schema(2220, 2967), get_schema(387, 463), get_schema(1280, 431))
1717

@@ -98,9 +98,9 @@ def test_ome_zarr_converter(tmp_path, series_idx, preserve_axes):
9898
"compressor",
9999
[
100100
tiledb.ZstdFilter(level=0),
101-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False),
102-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True),
103-
tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True),
101+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False),
102+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True),
103+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True),
104104
],
105105
)
106106
def test_ome_zarr_converter_rountrip(

tests/integration/converters/test_openslide.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tiledb.bioimg.converters.openslide import OpenSlideConverter
1111
from tiledb.bioimg.helpers import open_bioimg
1212
from tiledb.bioimg.openslide import TileDBOpenSlide
13-
from tiledb.libtiledb import WebpInputFormat
13+
from tiledb.filter import WebpFilter
1414

1515

1616
@pytest.mark.parametrize("preserve_axes", [False, True])
@@ -19,9 +19,9 @@
1919
"compressor",
2020
[
2121
tiledb.ZstdFilter(level=0),
22-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGBA, lossless=False),
23-
tiledb.WebpFilter(WebpInputFormat.WEBP_RGBA, lossless=True),
24-
tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True),
22+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGBA, lossless=False),
23+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGBA, lossless=True),
24+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True),
2525
],
2626
)
2727
def test_openslide_converter(tmp_path, preserve_axes, chunked, max_workers, compressor):

tests/integration/converters/test_png.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tiledb.bioimg.converters.png import PNGConverter
1111
from tiledb.bioimg.helpers import open_bioimg
1212
from tiledb.bioimg.openslide import TileDBOpenSlide
13-
from tiledb.libtiledb import WebpInputFormat
13+
from tiledb.filter import WebpFilter
1414

1515

1616
def create_synthetic_image(
@@ -125,8 +125,8 @@ def compare_png(p1: Image, p2: Image, lossless: bool = True):
125125
"compressor, lossless",
126126
[
127127
(tiledb.ZstdFilter(level=0), True),
128-
(tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=True), True),
129-
(tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True), True),
128+
(tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=True), True),
129+
(tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True), True),
130130
],
131131
)
132132
@pytest.mark.parametrize(
@@ -196,7 +196,7 @@ def test_png_converter_L_roundtrip(
196196
@pytest.mark.parametrize(
197197
"compressor, lossless",
198198
[
199-
(tiledb.WebpFilter(WebpInputFormat.WEBP_RGB, lossless=False), False),
199+
(tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGB, lossless=False), False),
200200
],
201201
)
202202
def test_png_converter_RGB_roundtrip_lossy(
@@ -235,8 +235,8 @@ def test_png_converter_RGB_roundtrip_lossy(
235235
"compressor, lossless",
236236
[
237237
(tiledb.ZstdFilter(level=0), True),
238-
(tiledb.WebpFilter(WebpInputFormat.WEBP_RGBA, lossless=True), True),
239-
(tiledb.WebpFilter(WebpInputFormat.WEBP_NONE, lossless=True), True),
238+
(tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGBA, lossless=True), True),
239+
(tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_NONE, lossless=True), True),
240240
],
241241
)
242242
def test_png_converter_RGBA_roundtrip(
@@ -266,7 +266,10 @@ def test_png_converter_RGBA_roundtrip(
266266
@pytest.mark.parametrize(
267267
"compressor, lossless",
268268
[
269-
(tiledb.WebpFilter(WebpInputFormat.WEBP_RGBA, lossless=False), False),
269+
(
270+
tiledb.WebpFilter(WebpFilter.WebpInputFormat.WEBP_RGBA, lossless=False),
271+
False,
272+
),
270273
],
271274
)
272275
def test_png_converter_RGBA_roundtrip_lossy(

tiledb/bioimg/converters/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
register_group = None
3838

3939
import tiledb
40-
from tiledb.libtiledb import WebpInputFormat
40+
from tiledb.filter import WebpFilter
4141

4242
from .. import ATTR_NAME
4343
from ..helpers import (
@@ -99,9 +99,9 @@ def channels(self) -> Sequence[str]:
9999
...
100100

101101
@property
102-
def webp_format(self) -> WebpInputFormat:
102+
def webp_format(self) -> WebpFilter.WebpInputFormat:
103103
"""WebpInputFormat of this multi-resolution image. Defaults to WEBP_NONE."""
104-
return WebpInputFormat.WEBP_NONE
104+
return WebpFilter.WebpInputFormat.WEBP_NONE
105105

106106
@property
107107
def level_count(self) -> int:
@@ -457,7 +457,8 @@ def to_tiledb(
457457
elif isinstance(compressor, tiledb.Filter):
458458
if (
459459
isinstance(compressor, tiledb.WebpFilter)
460-
and compressor.input_format == WebpInputFormat.WEBP_NONE
460+
and compressor.input_format
461+
== WebpFilter.WebpInputFormat.WEBP_NONE
461462
):
462463
compressor = tiledb.WebpFilter(
463464
input_format=reader.webp_format,

tiledb/bioimg/converters/ome_tiff.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
raise err
3131

3232
from tiledb import VFS, Config, Ctx
33+
from tiledb.filter import WebpFilter
3334
from tiledb.highlevel import _get_ctx
34-
from tiledb.libtiledb import WebpInputFormat
3535

3636
from .. import ATTR_NAME, EXPORT_TILE_SIZE, WHITE_RGBA
3737
from ..helpers import (
@@ -114,12 +114,12 @@ def axes(self) -> Axes:
114114
@property
115115
def channels(self) -> Sequence[str]:
116116
# channel names are fixed if this is an RGB image
117-
if self.webp_format is WebpInputFormat.WEBP_RGB:
118-
self._logger.debug(f"Webp format: {WebpInputFormat.WEBP_RGB}")
117+
if self.webp_format is WebpFilter.WebpInputFormat.WEBP_RGB:
118+
self._logger.debug(f"Webp format: {WebpFilter.WebpInputFormat.WEBP_RGB}")
119119
return "RED", "GREEN", "BLUE"
120120

121121
# otherwise try to infer them from the OME-XML metadata
122-
self._logger.debug(f"Webp format is not: {WebpInputFormat.WEBP_RGB}")
122+
self._logger.debug(f"Webp format is not: {WebpFilter.WebpInputFormat.WEBP_RGB}")
123123
try:
124124
channels = self._metadata["OME"]["Image"][0]["Pixels"]["Channel"]
125125
if not isinstance(channels, Sequence):
@@ -130,16 +130,16 @@ def channels(self) -> Sequence[str]:
130130
return tuple(c.get("Name") or f"Channel {i}" for i, c in enumerate(channels))
131131

132132
@property
133-
def webp_format(self) -> WebpInputFormat:
133+
def webp_format(self) -> WebpFilter.WebpInputFormat:
134134
self._logger.debug(f"Keyframe photometric: {self._series.keyframe.photometric}")
135135
if self._series.keyframe.photometric == tifffile.PHOTOMETRIC.RGB:
136-
return WebpInputFormat.WEBP_RGB
136+
return WebpFilter.WebpInputFormat.WEBP_RGB
137137
# XXX: it is possible that instead of a single RGB channel (samplesperpixel==3)
138138
# there are 3 MINISBLACK channels (samplesperpixel=1). In this case look for the
139139
# photometric interpretation in the original metadata
140140
if self._original_metadata("PhotometricInterpretation") == "RGB":
141-
return WebpInputFormat.WEBP_RGB
142-
return WebpInputFormat.WEBP_NONE
141+
return WebpFilter.WebpInputFormat.WEBP_RGB
142+
return WebpFilter.WebpInputFormat.WEBP_NONE
143143

144144
@property
145145
def level_count(self) -> int:

tiledb/bioimg/converters/ome_zarr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
raise err
3333

3434
from tiledb import Config, Ctx
35+
from tiledb.filter import WebpFilter
3536
from tiledb.highlevel import _get_ctx
36-
from tiledb.libtiledb import WebpInputFormat
3737

3838
from .. import WHITE_RGB
3939
from ..helpers import get_logger_wrapper, get_rgba, translate_config_to_s3fs
@@ -105,14 +105,14 @@ def channels(self) -> Sequence[str]:
105105
)
106106

107107
@property
108-
def webp_format(self) -> WebpInputFormat:
108+
def webp_format(self) -> WebpFilter.WebpInputFormat:
109109
channels = self._omero.image_data.get("channels", ()) if self._omero else ()
110110
colors = tuple(channel.get("color") for channel in channels)
111111
self._logger.debug(f"Webp format - channels: {channels}, colors:{colors}")
112112

113113
if colors == ("FF0000", "00FF00", "0000FF"):
114-
return WebpInputFormat.WEBP_RGB
115-
return WebpInputFormat.WEBP_NONE
114+
return WebpFilter.WebpInputFormat.WEBP_RGB
115+
return WebpFilter.WebpInputFormat.WEBP_NONE
116116

117117
@property
118118
def level_count(self) -> int:

tiledb/bioimg/converters/openslide.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from numpy._typing import NDArray
99

1010
from tiledb import Config, Ctx
11+
from tiledb.filter import WebpFilter
1112
from tiledb.highlevel import _get_ctx
12-
from tiledb.libtiledb import WebpInputFormat
1313

1414
from ..helpers import cache_filepath, get_logger_wrapper, is_remote_protocol, iter_color
1515
from . import DEFAULT_SCRATCH_SPACE
@@ -79,9 +79,9 @@ def channels(self) -> Sequence[str]:
7979
return "RED", "GREEN", "BLUE", "ALPHA"
8080

8181
@property
82-
def webp_format(self) -> WebpInputFormat:
83-
self._logger.debug(f"Webp Input Format: {WebpInputFormat.WEBP_RGBA}")
84-
return WebpInputFormat.WEBP_RGBA
82+
def webp_format(self) -> WebpFilter.WebpInputFormat:
83+
self._logger.debug(f"Webp Input Format: {WebpFilter.WebpInputFormat.WEBP_RGBA}")
84+
return WebpFilter.WebpInputFormat.WEBP_RGBA
8585

8686
@property
8787
def level_count(self) -> int:

0 commit comments

Comments
 (0)