Skip to content

Commit

Permalink
Merge branch 'main' into admin/drop-python3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanLeRoy authored Oct 30, 2023
2 parents 097f395 + 399c358 commit 8da393c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AICSImageIO

[![Build Status](https://github.com/AllenCellModeling/aicsimageio/workflows/Build%20Main/badge.svg)](https://github.com/AllenCellModeling/aicsimageio/actions)
[![Build Status](https://github.com/AllenCellModeling/aicsimageio/actions/workflows/build-main.yml/badge.svg)](https://github.com/AllenCellModeling/aicsimageio/actions)
[![Documentation](https://github.com/AllenCellModeling/aicsimageio/workflows/Documentation/badge.svg)](https://AllenCellModeling.github.io/aicsimageio/)
[![Code Coverage](https://codecov.io/gh/AllenCellModeling/aicsimageio/branch/main/graph/badge.svg)](https://app.codecov.io/gh/AllenCellModeling/aicsimageio/branch/main)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4906608.svg)](https://doi.org/10.5281/zenodo.4906608)
Expand Down
2 changes: 1 addition & 1 deletion aicsimageio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__email__ = "[email protected], [email protected], [email protected]"
# Do not edit this string manually, always use bumpversion
# Details in CONTRIBUTING.md
__version__ = "4.12.1"
__version__ = "4.13.0"


def get_module_version() -> str:
Expand Down
8 changes: 8 additions & 0 deletions aicsimageio/readers/nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def _xarr_reformat(self, delayed: bool) -> xr.DataArray:
xarr.attrs[constants.METADATA_UNPROCESSED][
"frame"
] = rdr.frame_metadata(self.current_scene_index)

# include OME metadata as attrs of returned xarray.DataArray if possible
# (not possible with `nd2` version < 0.7.0; see PR #521)
try:
xarr.attrs[constants.METADATA_PROCESSED] = self.ome_metadata
except NotImplementedError:
pass

return xarr.isel({nd2.AXIS.POSITION: 0}, missing_dims="ignore")

@property
Expand Down
8 changes: 4 additions & 4 deletions aicsimageio/readers/ome_tiff_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from fsspec.implementations.local import LocalFileSystem
from fsspec.spec import AbstractFileSystem
from ome_types import OME, from_xml
from pydantic.error_wrappers import ValidationError
from pydantic import ValidationError
from tifffile.tifffile import TiffFile, TiffFileError, TiffTags
from xmlschema import XMLSchemaValidationError
from xmlschema.exceptions import XMLSchemaValueError
Expand Down Expand Up @@ -185,7 +185,7 @@ def __init__(

# Get ome-types object and warn of other behaviors
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# Get and store OME
self._ome = self._get_ome(
tiff.pages[0].description, self.clean_metadata
Expand Down Expand Up @@ -308,7 +308,7 @@ def _read_delayed(self) -> xr.DataArray:
The file could not be read or is not supported.
"""
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# Get unprocessed metadata from tags
tiff_tags = self._get_tiff_tags(tiff)

Expand Down Expand Up @@ -353,7 +353,7 @@ def _read_immediate(self) -> xr.DataArray:
The file could not be read or is not supported.
"""
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# Get unprocessed metadata from tags
tiff_tags = self._get_tiff_tags(tiff)

Expand Down
16 changes: 5 additions & 11 deletions aicsimageio/readers/tiff_glob_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _is_supported_image(
) -> bool:
try:
with fs.open(path) as open_resource:
with TiffFile(open_resource, is_mmstack=False):
with TiffFile(open_resource):
return True

except (TiffFileError, TypeError):
Expand Down Expand Up @@ -256,7 +256,7 @@ def indexer(x: str) -> pd.Series:

if single_file_shape is None:
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
self._single_file_shape = tiff.series[0].shape

else:
Expand Down Expand Up @@ -299,9 +299,7 @@ def _read_delayed(self) -> xr.DataArray:
scene_files = scene_files.drop(self.scene_glob_character, axis=1)
scene_nunique = scene_files.nunique()

tiff_tags = self._get_tiff_tags(
TiffFile(scene_files.filename.iloc[0], is_mmstack=False)
)
tiff_tags = self._get_tiff_tags(TiffFile(scene_files.filename.iloc[0]))

group_dims = [
x for x in scene_files.columns if x not in ["filename", *self.chunk_dims]
Expand Down Expand Up @@ -366,9 +364,7 @@ def _read_delayed(self) -> xr.DataArray:
dims = list(expanded_blocks_sizes.keys())

else: # assemble array in a single chunk
zarr_im = imread(
scene_files.filename.tolist(), aszarr=True, level=0, is_mmstack=False
)
zarr_im = imread(scene_files.filename.tolist(), aszarr=True, level=0)
darr = da.from_zarr(zarr_im).rechunk(-1)
darr = darr.reshape(reshape_sizes)
darr = darr.transpose(axes_order)
Expand Down Expand Up @@ -407,9 +403,7 @@ def _read_immediate(self) -> xr.DataArray:
scene_files = scene_files.drop(self.scene_glob_character, axis=1)
scene_nunique = scene_files.nunique()

tiff_tags = self._get_tiff_tags(
TiffFile(scene_files.filename.iloc[0], is_mmstack=False)
)
tiff_tags = self._get_tiff_tags(TiffFile(scene_files.filename.iloc[0]))

chunk_sizes = self._get_chunk_sizes(scene_nunique)

Expand Down
9 changes: 4 additions & 5 deletions aicsimageio/readers/tiff_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(
def scenes(self) -> Tuple[str, ...]:
if self._scenes is None:
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# This is non-metadata tiff, just use available series indices
self._scenes = tuple(
metadata_utils.generate_ome_image_id(i)
Expand Down Expand Up @@ -186,7 +186,6 @@ def _get_image_data(
series=scene,
level=0,
chunkmode="page",
is_mmstack=False,
) as store:
arr = da.from_zarr(store)
arr = arr.transpose(transpose_indices)
Expand Down Expand Up @@ -456,7 +455,7 @@ def _read_delayed(self) -> xr.DataArray:
The file could not be read or is not supported.
"""
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# Get dims from provided or guess
dims = self._get_dims_for_scene(tiff)

Expand Down Expand Up @@ -509,7 +508,7 @@ def _read_immediate(self) -> xr.DataArray:
The file could not be read or is not supported.
"""
with self._fs.open(self._path) as open_resource:
with TiffFile(open_resource, is_mmstack=False) as tiff:
with TiffFile(open_resource) as tiff:
# Get dims from provided or guess
dims = self._get_dims_for_scene(tiff)

Expand Down Expand Up @@ -577,7 +576,7 @@ def _get_pixel_size(
) -> Tuple[Optional[float], Optional[float], Optional[float]]:
"""Return the pixel size in microns (z,y,x) for the given series in a tiff path."""

with TiffFile(path_or_file, is_mmstack=False) as tiff:
with TiffFile(path_or_file) as tiff:
tags = tiff.series[series_index].pages[0].tags

if tiff.is_imagej:
Expand Down
19 changes: 16 additions & 3 deletions aicsimageio/tests/readers/extra_readers/test_nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"expected_dtype, "
"expected_dims_order, "
"expected_channel_names, "
"expected_physical_pixel_sizes",
"expected_physical_pixel_sizes, "
"expected_metadata_type",
[
pytest.param(
"example.txt",
Expand All @@ -42,6 +43,7 @@
None,
None,
None,
None,
marks=pytest.mark.xfail(raises=exceptions.UnsupportedFileFormatError),
),
pytest.param(
Expand All @@ -53,6 +55,7 @@
"TCYX",
["20phase", "20xDiO"],
(1, 50, 50),
dict,
),
(
"ND2_jonas_header_test2.nd2",
Expand All @@ -63,6 +66,7 @@
"CTZYX",
["Jonas_DIC"],
(0.5, 0.12863494437945, 0.12863494437945),
OME,
),
(
"ND2_maxime_BF007.nd2",
Expand All @@ -73,6 +77,7 @@
"CYX",
["405/488/561/633nm"],
(1.0, 0.158389678930686, 0.158389678930686),
OME,
),
(
"ND2_dims_p4z5t3c2y32x32.nd2",
Expand All @@ -83,6 +88,7 @@
"TZCYX",
["Widefield Green", "Widefield Red"],
(1.0, 0.652452890023035, 0.652452890023035),
OME,
),
(
"ND2_dims_c2y32x32.nd2",
Expand All @@ -93,6 +99,7 @@
"CYX",
["Widefield Green", "Widefield Red"],
(1.0, 0.652452890023035, 0.652452890023035),
OME,
),
(
"ND2_dims_p1z5t3c2y32x32.nd2",
Expand All @@ -103,6 +110,7 @@
"TZCYX",
["Widefield Green", "Widefield Red"],
(1.0, 0.652452890023035, 0.652452890023035),
OME,
),
(
"ND2_dims_p2z5t3-2c4y32x32.nd2",
Expand All @@ -113,6 +121,7 @@
"TZCYX",
["Widefield Green", "Widefield Red", "Widefield Far-Red", "Brightfield"],
(1.0, 0.652452890023035, 0.652452890023035),
OME,
),
(
"ND2_dims_t3c2y32x32.nd2",
Expand All @@ -123,6 +132,7 @@
"TCYX",
["Widefield Green", "Widefield Red"],
(1.0, 0.652452890023035, 0.652452890023035),
OME,
),
(
"ND2_dims_rgb_t3p2c2z3x64y64.nd2",
Expand All @@ -133,6 +143,7 @@
"TZCYXS",
["Brightfield", "Brightfield"],
(0.01, 0.34285714285714286, 0.34285714285714286),
OME,
),
(
"ND2_dims_rgb.nd2",
Expand All @@ -143,6 +154,7 @@
"CYXS",
["Brightfield"],
(1.0, 0.34285714285714286, 0.34285714285714286),
OME,
),
],
)
Expand All @@ -156,6 +168,7 @@ def test_nd2_reader(
expected_dims_order: str,
expected_channel_names: List[str],
expected_physical_pixel_sizes: Tuple[float, float, float],
expected_metadata_type: Union[type, Tuple[Union[type, Tuple[Any, ...]], ...]],
) -> None:
# Construct full filepath
uri = get_resource_full_path(filename, host)
Expand All @@ -172,7 +185,7 @@ def test_nd2_reader(
expected_dims_order=expected_dims_order,
expected_channel_names=expected_channel_names,
expected_physical_pixel_sizes=expected_physical_pixel_sizes,
expected_metadata_type=dict,
expected_metadata_type=expected_metadata_type,
)


Expand All @@ -196,7 +209,7 @@ def test_nd2_reader(
dimensions.DEFAULT_DIMENSION_ORDER,
["Jonas_DIC"],
(0.5, 0.12863494437945, 0.12863494437945),
dict,
OME,
),
],
)
Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ default_context:
project_slug: "aicsimageio"
project_short_description: "Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python"
pypi_username: "aicspypi"
version: "4.12.1"
version: "4.13.0"
open_source_license: "BSD license"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.12.1
current_version = 4.13.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize = {major}.{minor}.{patch}
commit = True
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(self):
],
"nd2": ["nd2[legacy]>=0.6.0"],
"dv": ["mrc>=0.2.0"],
"bfio": ["bfio>=2.3.0", "tifffile<2022.4.22"],
"bfio": ["bfio==2.3.0", "tifffile<2022.4.22"],
# "czi": [ # excluded for licensing reasons
# "fsspec>=2022.8.0",
# "aicspylibczi>=3.1.1",
Expand Down Expand Up @@ -110,10 +110,10 @@ def run(self):
"PyYAML>=6.0",
"wrapt>=1.12",
"resource-backed-dask-array>=0.1.0",
"tifffile>=2021.8.30",
"tifffile>=2021.8.30,<2023.3.15",
"xarray>=0.16.1",
"xmlschema", # no pin because it's pulled in from OME types
"zarr>=2.6,<3",
"zarr>=2.6,<2.16.0",
]

extra_requirements = {
Expand Down Expand Up @@ -170,6 +170,6 @@ def run(self):
url="https://github.com/AllenCellModeling/aicsimageio",
# Do not edit this string manually, always use bumpversion
# Details in CONTRIBUTING.md
version="4.12.1",
version="4.13.0",
zip_safe=False,
)

0 comments on commit 8da393c

Please sign in to comment.