From 4563908254d4683197a72ba0a293382997825a75 Mon Sep 17 00:00:00 2001 From: "w.pomp" Date: Tue, 3 Mar 2026 15:56:27 +0100 Subject: [PATCH] - make paths absolute if possible - seqfind: read some metadata from display_and_comments.txt if needed and present --- ndbioimage/__init__.py | 6 ++++-- ndbioimage/readers/seqread.py | 20 +++++++++++++++----- pyproject.toml | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ndbioimage/__init__.py b/ndbioimage/__init__.py index 9a5a27f..c0f31de 100755 --- a/ndbioimage/__init__.py +++ b/ndbioimage/__init__.py @@ -1306,9 +1306,11 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC): @staticmethod def split_path_series(path: Path | str) -> tuple[Path, int]: if isinstance(path, str): - path = Path(path) + path = Path(path).absolute() if isinstance(path, Path) and path.name.startswith("Pos") and path.name.lstrip("Pos").isdigit(): - return path.parent, int(path.name.lstrip("Pos")) + return path.absolute().parent, int(path.name.lstrip("Pos")) + if isinstance(path, Path): + return path.absolute(), 0 return path, 0 def view(self, *args: Any, **kwargs: Any) -> View: diff --git a/ndbioimage/readers/seqread.py b/ndbioimage/readers/seqread.py index ee72d8f..5fd83ed 100644 --- a/ndbioimage/readers/seqread.py +++ b/ndbioimage/readers/seqread.py @@ -1,4 +1,5 @@ import re +import warnings from abc import ABC from datetime import datetime from itertools import product @@ -59,9 +60,10 @@ class Reader(AbstractReader, ABC): ome = model.OME() with tifffile.TiffFile(self.filedict[0, 0, 0]) as tif: metadata = {key: yaml.safe_load(value) for key, value in tif.pages[0].tags[50839].value.items()} - ome.experimenters.append( - model.Experimenter(id="Experimenter:0", user_name=metadata["Info"]["Summary"]["UserName"]) - ) + if "Summary" in metadata["Info"] and "UserName" in metadata["Info"]["Summary"]: + ome.experimenters.append( + model.Experimenter(id="Experimenter:0", user_name=metadata["Info"]["Summary"]["UserName"]) + ) objective_str = metadata["Info"]["ZeissObjectiveTurret-Label"] ome.instruments.append(model.Instrument()) ome.instruments[0].objectives.append( @@ -112,7 +114,7 @@ class Reader(AbstractReader, ABC): type=pixel_type, physical_size_x=pxsize, physical_size_y=pxsize, - physical_size_z=metadata["Info"]["Summary"]["z-step_um"], + physical_size_z=metadata["Info"]["Summary"]["z-step_um"] if "Summary" in metadata["Info"] else None, ), objective_settings=model.ObjectiveSettings(id="Objective:0"), ) @@ -164,7 +166,15 @@ class Reader(AbstractReader, ABC): metadata = {key: yaml.safe_load(value) for key, value in tif.pages[0].tags[50839].value.items()} # compare channel names from metadata with filenames - cnamelist = metadata["Info"]["Summary"]["ChNames"] + if "Summary" in metadata["Info"] and "ChNames" in metadata["Info"]["Summary"]: + cnamelist = metadata["Info"]["Summary"]["ChNames"] + elif (self.path.parent / "display_and_comments.txt").exists(): + warnings.warn(f"{self.path} is missing some metadata") + with open(self.path.parent / "display_and_comments.txt") as f: + cnamelist = [channel["Name"] for channel in yaml.safe_load(f)["Channels"]] + else: + raise ValueError("could not find metadata describing the order of the channels") + cnamelist = [c for c in cnamelist if any([c in f.name for f in filelist])] pattern_c = re.compile(r"img_\d{3,}_(.*)_\d{3,}$", re.IGNORECASE) diff --git a/pyproject.toml b/pyproject.toml index add0b61..c8bfc7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ndbioimage" -version = "2026.1.2" +version = "2026.3.0" description = "Bio image reading, metadata and some affine registration." authors = [ { name = "W. Pomp", email = "w.pomp@nki.nl" }