Skip to content

Commit

Permalink
feat(ome): ✨ added support for TImeIncrement and TimeIncrementUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
filippocastelli committed Aug 23, 2024
1 parent f79aa3b commit 958e46b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyometiff/omereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self,
self.fpath = Path(fpath)
self.imageseries = imageseries

def read(self) -> (np.ndarray, dict, str):
def read(self) -> tuple[np.ndarray, dict, str]:
self.array, self.omexml_string = self._open_tiff(self.fpath)
self.metadata = self.parse_metadata(self.omexml_string)
return self.array, self.metadata, self.omexml_string
Expand Down Expand Up @@ -72,6 +72,10 @@ def parse_metadata(self, omexml_string):
metadata["PhysicalSizeY"] = self.ox.image(self.imageseries).Pixels.PhysicalSizeY
metadata["PhysicalSizeZ"] = self.ox.image(self.imageseries).Pixels.PhysicalSizeZ

# time increment
metadata["TimeIncrement"] = self.ox.image(self.imageseries).Pixels.TimeIncrement
metadata["TimeIncrementUnit"] = self.ox.image(self.imageseries).Pixels.TimeIncrementUnit

# physical size unit
metadata["PhysicalSizeXUnit"] = self.ox.image(
self.imageseries
Expand Down
9 changes: 9 additions & 0 deletions pyometiff/omewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def _dim_or_1(dim):
pixels.set_SizeZ(_dim_or_1("Z"))
pixels.set_SizeY(_dim_or_1("Y"))
pixels.set_SizeX(_dim_or_1("X"))

# time increment
time_increment = pop_expected_keys.get("TimeIncrement", None)
time_increment_unit = pop_expected_keys.get("TimeIncrementUnit", None)

if time_increment is not None:
pixels.set_TimeIncrement(time_increment)
if time_increment_unit is not None:
pixels.set_TimeIncrementUnit(time_increment_unit)

# this is reversed of what dimensionality of the ometiff file is saved as
pixels.set_DimensionOrder(self._dimension_order[::-1])
Expand Down
18 changes: 18 additions & 0 deletions pyometiff/omexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,24 @@ def set_SizeC(self, value: int) -> None:

SizeC = property(get_SizeC, set_SizeC)

def get_TimeIncrement(self) -> float:
"""The time increment between T planes"""
return get_float_attr(self.node, "TimeIncrement")

def set_TimeIncrement(self, value: float) -> None:
self.node.set("TimeIncrement", str(value))

TimeIncrement = property(get_TimeIncrement, set_TimeIncrement)

def get_TimeIncrementUnit(self) -> str:
"""The unit of the time increment"""
return self.node.get("TimeIncrementUnit")

def set_TimeIncrementUnit(self, value: str) -> None:
self.node.set("TimeIncrementUnit", value)

TimeIncrementUnit = property(get_TimeIncrementUnit, set_TimeIncrementUnit)

def get_channel_count(self) -> int:
"""The number of channels in the image
Expand Down

0 comments on commit 958e46b

Please sign in to comment.