Skip to content

Commit

Permalink
Feature/ome_metadata-for-nd2 (#521)
Browse files Browse the repository at this point in the history
* feat: add ome_meta from nd2

* add test

* black

* remove import
  • Loading branch information
tlambert03 authored Aug 14, 2023
1 parent a6d7928 commit 2e88f68
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aicsimageio/readers/nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
if TYPE_CHECKING:
import xarray as xr
from fsspec.spec import AbstractFileSystem
from ome_types import OME


try:
Expand Down Expand Up @@ -102,3 +103,24 @@ def physical_pixel_sizes(self) -> types.PhysicalPixelSizes:
"""
with nd2.ND2File(self._path) as rdr:
return types.PhysicalPixelSizes(*rdr.voxel_size()[::-1])

@property
def ome_metadata(self) -> OME:
"""Return OME metadata.
Returns
-------
metadata: OME
The original metadata transformed into the OME specfication.
This likely isn't a complete transformation but is guarenteed to
be a valid transformation.
Raises
------
NotImplementedError
No metadata transformer available.
"""
if hasattr(nd2.ND2File, "ome_metadata"):
with nd2.ND2File(self._path) as rdr:
return rdr.ome_metadata()
raise NotImplementedError()
20 changes: 20 additions & 0 deletions aicsimageio/tests/readers/extra_readers/test_nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pytest
from ome_types import OME

from aicsimageio import AICSImage, dimensions, exceptions
from aicsimageio.readers.nd2_reader import ND2Reader
Expand Down Expand Up @@ -229,6 +230,25 @@ def test_aicsimage(
)


@pytest.mark.parametrize(
"filename",
[
"ND2_jonas_header_test2.nd2",
"ND2_maxime_BF007.nd2",
"ND2_dims_p4z5t3c2y32x32.nd2",
],
)
def test_ome_metadata(filename: str) -> None:
# Get full filepath
uri = get_resource_full_path(filename, LOCAL)

# Init image
img = AICSImage(uri)

# Test the transform
assert isinstance(img.ome_metadata, OME)


def test_frame_metadata() -> None:
filename = "ND2_dims_rgb_t3p2c2z3x64y64.nd2"
uri = get_resource_full_path(filename, LOCAL)
Expand Down

0 comments on commit 2e88f68

Please sign in to comment.