Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass reader to ImageConverter.to_tiledb() instead of creating custom ImageConverter subclasses #1

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions napari_tiledb_bioimg/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def napari_get_reader(path):
warnings.warn(f"Not a single path: {path}")
return None

if not os.path.isdir(path):
warnings.warn(f"Not a directory: {path}")
if tiledb.object_type(path) != "group":
warnings.warn(f"Not a tiledb group: {path}")
return None

try:
Expand Down
14 changes: 3 additions & 11 deletions napari_tiledb_bioimg/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ def level_metadata(self, level: int) -> Dict[str, Any]:
return {}


class NapariSingleScaleConverter(ImageConverter):
_ImageReaderType = NapariSingleScaleDataReader


class NapariMultiScaleConverter(ImageConverter):
_ImageReaderType = NapariMultiScaleDataReader


def napari_write_image_lossless(path, data, attributes):
return _napari_write_image(path, data, lossless=True)

Expand All @@ -128,8 +120,8 @@ def _napari_write_image(path, data, lossless):
kwargs = dict(compressor=tiledb.WebpFilter(lossless=lossless))
if isinstance(data, MultiScaleData):
kwargs.update(chunked=True, max_workers=os.cpu_count())
converter = NapariMultiScaleConverter
reader = NapariMultiScaleDataReader(data)
else:
converter = NapariSingleScaleConverter
converter.to_tiledb(data, path, **kwargs)
reader = NapariSingleScaleDataReader(data)
ImageConverter.to_tiledb(reader, path, **kwargs)
return [path]
2 changes: 1 addition & 1 deletion napari_tiledb_bioimg/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contributions:
readers:
- command: napari-tiledb-bioimg.get_reader
accepts_directories: true
filename_patterns: []
filename_patterns: ['*.tdb', '*.tiledb']
writers:
- command: napari-tiledb-bioimg.write_image_lossless
layer_types: ['image']
Expand Down
4 changes: 2 additions & 2 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def test_get_reader_not_dir_fail(tmp_path):
f.write_text("")
assert f.is_file()

with pytest.warns(UserWarning, match="Not a directory"):
with pytest.warns(UserWarning, match="Not a tiledb group"):
assert napari_get_reader(str(f)) is None


def test_get_reader_invalid_dir_fail(tmp_path):
"""Not receiving a proper TileDB group directory"""
with pytest.warns(UserWarning, match="Failed to open"):
with pytest.warns(UserWarning, match="Not a tiledb group"):
assert napari_get_reader(str(tmp_path)) is None


Expand Down
18 changes: 7 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For more information about tox, see https://tox.readthedocs.io/en/latest/
[tox]
envlist = py{38,39,310}-{linux,macos,windows}
isolated_build=true
isolated_build = true

[gh-actions]
python =
Expand All @@ -20,13 +20,9 @@ platform =
macos: darwin
linux: linux
windows: win32
passenv =
CI
GITHUB_ACTIONS
DISPLAY
XAUTHORITY
NUMPY_EXPERIMENTAL_ARRAY_FUNCTION
PYVISTA_OFF_SCREEN
extras =
testing
commands = pytest -v --color=yes --cov=napari_tiledb_bioimg --cov-report=xml
passenv = CI,GITHUB_ACTIONS,DISPLAY,XAUTHORITY,NUMPY_EXPERIMENTAL_ARRAY_FUNCTION,PYVISTA_OFF_SCREEN
extras = testing

commands =
{linux,macos}: pytest -v --color=yes --cov=napari_tiledb_bioimg --cov-report=xml
windows: pytest --basetemp={envtmpdir} -v --color=yes --cov=napari_tiledb_bioimg --cov-report=xml