Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion aicsimageio/readers/bioformats_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ def _is_supported_image(fs: AbstractFileSystem, path: str, **kwargs: Any) -> boo
except Exception:
return False

def __init__(self, image: types.PathLike):
def __init__(
self,
image: types.PathLike,
**kwargs: Any,
):
self._fs, self._path = io_utils.pathlike_to_fs(image, enforce_exists=True)
# Catch non-local file system
if not isinstance(self._fs, LocalFileSystem):
Expand Down
1 change: 1 addition & 0 deletions aicsimageio/readers/czi_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(
image: types.PathLike,
chunk_dims: Union[str, List[str]] = DEFAULT_CHUNK_DIMS,
chunk_by_dims: Optional[Union[str, List[str]]] = None,
**kwargs: Any,
):
# Expand details of provided image
self._fs, self._path = io_utils.pathlike_to_fs(image, enforce_exists=True)
Expand Down
1 change: 1 addition & 0 deletions aicsimageio/readers/lif_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
self,
image: types.PathLike,
chunk_dims: Union[str, List[str]] = DEFAULT_CHUNK_DIMS,
**kwargs: Any,
):
# Expand details of provided image
self._fs, self._path = io_utils.pathlike_to_fs(image, enforce_exists=True)
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/benchmark_image_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _ImageContainerTimeSuite:
DimensionNames.Samples,
]

def time_init(self, img_path, chunk_dims=None):
def time_init(self, img_path, chunk_dims=None, reader=None):
"""
Benchmark how long it takes to validate a file and finish general setup.
"""
Expand All @@ -70,7 +70,7 @@ def time_init(self, img_path, chunk_dims=None):

self.ImageContainer(img_path, chunk_dims=chunk_dims)

def time_delayed_array_construct(self, img_path, chunk_dims=None):
def time_delayed_array_construct(self, img_path, chunk_dims=None, reader=None):
"""
Benchmark how long it takes to construct the delayed dask array for a file.
"""
Expand All @@ -79,7 +79,7 @@ def time_delayed_array_construct(self, img_path, chunk_dims=None):

self.ImageContainer(img_path, chunk_dims=chunk_dims).dask_data

def time_random_single_chunk_read(self, img_path, chunk_dims=None):
def time_random_single_chunk_read(self, img_path, chunk_dims=None, reader=None):
"""
Benchmark how long it takes to read a single chunk out of a file.

Expand All @@ -100,7 +100,7 @@ def time_random_single_chunk_read(self, img_path, chunk_dims=None):
)
r.get_image_dask_data(valid_dims_to_return, **random_index_selections).compute()

def time_random_many_chunk_read(self, img_path, chunk_dims=None):
def time_random_many_chunk_read(self, img_path, chunk_dims=None, reader=None):
"""
Open a file, get many chunks out of the file at once.

Expand Down
49 changes: 49 additions & 0 deletions benchmarks/benchmark_native.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
from pathlib import Path

from aicsimageio.readers.ome_tiff_reader import OmeTiffReader
from aicsimageio.readers.bioformats_reader import BioformatsReader

from .benchmark_image_containers import _ImageContainerTimeSuite

###############################################################################

# We only benchmark against local files as remote files are covered by unit tests
# and are generally slower than local but scale at a similar rate.
LOCAL_RESOURCES_DIR = (
Path(__file__).parent.parent / "aicsimageio" / "tests" / "resources"
)

###############################################################################


class NativePythonCompareSuite(_ImageContainerTimeSuite):
# This suite compares the time it takes to do common operations for file formats
# covered by multiple readers
# (specifically, a native Python reader and the BioformatsReader).
# Where our native implementation is faster or slower than the Bioformats jpype
# implementation.
params = (
[
str(LOCAL_RESOURCES_DIR / "pre-variance-cfe.ome.tiff"),
str(LOCAL_RESOURCES_DIR / "variance-cfe.ome.tiff"),
],
# We don't go above chunking by three dims because it would be rare
# to do so... if you can read four-plus dims in a single chunk why can't you
# just read in the whole image at once.
# We also use CYX here to show that chunking with the _wrong_ dimensions can
# result in longer processing times.
[
"YX",
"ZYX",
"CYX",
],
[OmeTiffReader, BioformatsReader],
)

def setup(self, img_path, chunk_dims, reader):
random.seed(42)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌌

self.ImageContainer = reader