nd2
nd2 copied to clipboard
Export position names to OME metadata
- nd2 version: 0.10.1
- Python version: 3.12.2
- Operating System: macOS
Description
For a nd2 recording of a multi-D acquisition with multiple positions, the position names are not exported in the OME metadata.
What I Did
A patch fixing the issue could be along the lines of
diff --git i/src/nd2/_ome.py w/src/nd2/_ome.py
index c0897e8..a02b35e 100644
--- i/src/nd2/_ome.py
+++ w/src/nd2/_ome.py
@@ -111,6 +111,15 @@ def nd2_ome_metadata(
channel.excitation_wavelength_unit = UnitsLength.NANOMETER
channels.append(channel)
+ xypl: XYPosLoop | None
+ xypl, = [loop for loop in f.experiment if loop.type == "XYPosLoop"] or [None]
+ names = ( # use point names if they exist, with a fallback
+ [point.name for point in xypl.parameters.points]
+ if xypl else
+ [f"{Path(f.path).stem} Series {p}" for p in range(n_positions)]
+ if n_positions > 1 else
+ [Path(f.path).stem]
+ )
for p in range(n_positions):
planes: list[m.Plane] = []
tiff_blocks: list[m.TiffData] = []
@@ -182,7 +191,7 @@ def nd2_ome_metadata(
instrument_ref=m.InstrumentRef(id=instrument.id),
# objective_settings=...
id=f"Image:{p}",
- name=Path(f.path).stem + (f" (Series {p})" if n_positions > 1 else ""),
+ name=names[p],
pixels=pixels,
acquisition_date=acquisition_date,
)
The "old" name you previously provided matches bioformats' behavior (I think), but I'd say the information it provides is redundant (unlike the position name, which can be semantically relevant). It's up to you whether you want to set image.name to the raw point name, or something like Stage1 "the_name" (matching bioformats's behavior for MetaMorph ND files) or something else that includes e.g. the path stem.