diff --git a/tiledb/bioimg/converters/base.py b/tiledb/bioimg/converters/base.py index 4eabad7..09deb9f 100644 --- a/tiledb/bioimg/converters/base.py +++ b/tiledb/bioimg/converters/base.py @@ -58,7 +58,15 @@ class ImageReader(ABC): @abstractmethod - def __init__(self, input_path: str, logger: logging.Logger, **kwargs: Any): + def __init__( + self, + input_path: str, + *, + logger: Optional[logging.Logger], + config: Optional[tiledb.Config] = None, + ctx: Optional[tiledb.Ctx] = None, + **kwargs: Any, + ): """Initialize this ImageReader""" def __enter__(self) -> ImageReader: @@ -359,7 +367,7 @@ def to_tiledb( reader = source elif cls._ImageReaderType is not None: reader = cls._ImageReaderType( - source, logger, **reader_kwargs if reader_kwargs else {} + source, logger=logger, **reader_kwargs if reader_kwargs else {} ) else: raise NotImplementedError(f"{cls} does not support importing") diff --git a/tiledb/bioimg/converters/ome_tiff.py b/tiledb/bioimg/converters/ome_tiff.py index d1b5443..ffdca2f 100644 --- a/tiledb/bioimg/converters/ome_tiff.py +++ b/tiledb/bioimg/converters/ome_tiff.py @@ -9,6 +9,7 @@ from tiledb import VFS, Config, Ctx from tiledb.cc import WebpInputFormat +from tiledb.highlevel import _get_ctx from .. import ATTR_NAME, EXPORT_TILE_SIZE, WHITE_RGBA from ..helpers import get_decimal_from_rgba, get_logger_wrapper, get_rgba, iter_color @@ -21,6 +22,7 @@ class OMETiffReader(ImageReader): def __init__( self, input_path: str, + *, logger: Optional[logging.Logger] = None, config: Optional[Config] = None, ctx: Optional[Ctx] = None, @@ -37,7 +39,9 @@ def __init__( # Use VFS for all paths local or remote for reading the input image self._input_path = input_path - self._vfs = VFS(config=config, ctx=ctx) + self._ctx = _get_ctx(ctx, config) + self._cfg = self._ctx.config() + self._vfs = VFS(config=self._cfg, ctx=self._ctx) self._vfs_fh = self._vfs.open(input_path, mode="rb") self._tiff = tifffile.TiffFile(self._vfs_fh) # XXX ignore all but the first series diff --git a/tiledb/bioimg/converters/ome_zarr.py b/tiledb/bioimg/converters/ome_zarr.py index d7322bd..d106332 100644 --- a/tiledb/bioimg/converters/ome_zarr.py +++ b/tiledb/bioimg/converters/ome_zarr.py @@ -25,6 +25,7 @@ class OMEZarrReader(ImageReader): def __init__( self, input_path: str, + *, logger: Optional[logging.Logger] = None, config: Optional[Config] = None, ctx: Optional[Ctx] = None, diff --git a/tiledb/bioimg/converters/openslide.py b/tiledb/bioimg/converters/openslide.py index 3df2600..b86eae5 100644 --- a/tiledb/bioimg/converters/openslide.py +++ b/tiledb/bioimg/converters/openslide.py @@ -27,6 +27,7 @@ class OpenSlideReader(ImageReader): def __init__( self, input_path: str, + *, logger: Optional[logging.Logger] = None, config: Optional[Config] = None, ctx: Optional[Ctx] = None, @@ -40,11 +41,12 @@ def __init__( self._ctx = _get_ctx(ctx, config) self._cfg = self._ctx.config() self._logger = get_logger_wrapper(False) if not logger else logger - resolved_path = input_path if is_remote_protocol(input_path): resolved_path = cache_filepath( input_path, config, ctx, self._logger, scratch_space ) + else: + resolved_path = input_path self._osd = osd.OpenSlide(resolved_path) def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: