Skip to content

Commit

Permalink
store frame metadata when reading a specific scene (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-gould authored Apr 26, 2023
1 parent bed6166 commit d4ae290
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aicsimageio/readers/nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def _xarr_reformat(self, delayed: bool) -> xr.DataArray:
delayed=delayed, squeeze=False, position=self.current_scene_index
)
xarr.attrs[constants.METADATA_UNPROCESSED] = xarr.attrs.pop("metadata")
if self.current_scene_index is not None:
xarr.attrs[constants.METADATA_UNPROCESSED][
"frame"
] = rdr.frame_metadata(self.current_scene_index)
return xarr.isel({nd2.AXIS.POSITION: 0})

@property
Expand Down
10 changes: 10 additions & 0 deletions aicsimageio/tests/readers/extra_readers/test_nd2_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,13 @@ def test_aicsimage(
expected_physical_pixel_sizes=expected_physical_pixel_sizes,
expected_metadata_type=expected_metadata_type,
)


def test_frame_metadata() -> None:
filename = "ND2_dims_rgb_t3p2c2z3x64y64.nd2"
uri = get_resource_full_path(filename, LOCAL)
rdr = ND2Reader(uri)
rdr.set_scene(0)
assert isinstance(
rdr.xarray_data.attrs["unprocessed"]["frame"], nd2.structures.FrameMetadata
)

0 comments on commit d4ae290

Please sign in to comment.