- read metadata from first file in ome tiff sequence

This commit is contained in:
Wim Pomp
2025-03-19 16:06:07 +01:00
parent 0ac22aff87
commit b7dadb645e
2 changed files with 49 additions and 41 deletions

View File

@@ -1,3 +1,5 @@
import re
import warnings
from abc import ABC from abc import ABC
from functools import cached_property from functools import cached_property
from itertools import product from itertools import product
@@ -6,8 +8,8 @@ from pathlib import Path
import numpy as np import numpy as np
import tifffile import tifffile
import yaml import yaml
import warnings from lfdfiles import TiffFile
from ome_types import model, from_xml from ome_types import from_xml, model
from .. import AbstractReader, try_default from .. import AbstractReader, try_default
@@ -31,10 +33,16 @@ class Reader(AbstractReader, ABC):
def get_ome(self): def get_ome(self):
if self.reader.is_ome: 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()
file0 = TiffFile(self.path.with_stem(a + re.sub(r'\d', '0', b)))
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter('ignore', category=UserWarning) warnings.simplefilter('ignore', category=UserWarning)
return from_xml(self.reader.ome_metadata) ome = from_xml(file0.ome_metadata)
else: ome.images = [image for image in ome.images if self.path.stem[:len(image.name)] == image.name]
return ome
page = self.reader.pages[0] page = self.reader.pages[0]
size_y = page.imagelength size_y = page.imagelength
size_x = page.imagewidth size_x = page.imagewidth

View File

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