- fix reading time interval when defined not in s in ome

- search all ome.tif for metadata in order
This commit is contained in:
Wim Pomp
2025-10-15 20:29:07 +02:00
parent 1b5febc35b
commit 7fe1d189e5
3 changed files with 23 additions and 12 deletions

View File

@@ -1401,8 +1401,12 @@ class AbstractReader(Imread, metaclass=ABCMeta):
else:
self.objective = None
try:
t0 = find(image.pixels.planes, the_c=0, the_t=0, the_z=0).delta_t
t1 = find(image.pixels.planes, the_c=0, the_t=self.shape["t"] - 1, the_z=0).delta_t
t0 = find(image.pixels.planes, the_c=0, the_t=0, the_z=0).delta_t_quantity.to(self.ureg.s).m
t1 = (
find(image.pixels.planes, the_c=0, the_t=self.shape["t"] - 1, the_z=0)
.delta_t_quantity.to(self.ureg.s)
.m
)
self.timeinterval = (t1 - t0) / (self.shape["t"] - 1) if self.shape["t"] > 1 and t1 > t0 else None
except AttributeError:
self.timeinterval = None

View File

@@ -34,15 +34,22 @@ class Reader(AbstractReader, ABC):
def get_ome(self):
if self.reader.is_ome:
match = re.match(r"^(.*)(pos.*)$", self.path.stem, flags=re.IGNORECASE)
if match is not None and len(match.groups()) == 2:
a, b = match.groups()
with tifffile.TiffFile(self.path.with_stem(a + re.sub(r"\d", "0", b))) as file0:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
ome = from_xml(file0.ome_metadata)
ome.images = [image for image in ome.images if self.path.stem[: len(image.name)] == image.name]
return ome
match = re.match(r"^(.*)(pos[\d_]+)(.*)$", self.path.name, flags=re.IGNORECASE)
if match is not None and len(match.groups()) == 3:
a, b, c = match.groups()
pat = re.compile(f"^{re.escape(a)}" + re.sub(r"\d+", r"\\d+", b) + f"{re.escape(c)}$")
for file in sorted(self.path.parent.iterdir(), key=lambda i: (len(i.name), i.name)):
if pat.match(file.name):
with tifffile.TiffFile(file) as tif:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=UserWarning)
ome = from_xml(tif.ome_metadata)
ome.images = [
image for image in ome.images if self.path.stem[: len(image.name)] == image.name
]
if ome.images:
return ome
warnings.warn("could not find the ome.tif file containing the metadata")
page = self.reader.pages[0]
size_y = page.imagelength

View File

@@ -1,6 +1,6 @@
[project]
name = "ndbioimage"
version = "2025.9.0"
version = "2025.10.0"
description = "Bio image reading, metadata and some affine registration."
authors = [
{ name = "W. Pomp", email = "w.pomp@nki.nl" }