From b9737eb0adc80409549d65e8648446a3098bc879 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 2 Apr 2024 12:42:35 -0700 Subject: [PATCH] fix bug reading dragonfly acquisitions --- iohub/mmstack.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iohub/mmstack.py b/iohub/mmstack.py index 83c7800e..80b4d3e4 100644 --- a/iohub/mmstack.py +++ b/iohub/mmstack.py @@ -12,6 +12,7 @@ from numpy.typing import ArrayLike from tifffile import TiffFile from xarray import DataArray +from natsort import natsorted from iohub.mm_fov import MicroManagerFOV, MicroManagerFOVMapping @@ -126,6 +127,7 @@ def _parse_data(self): self._store = series.aszarr() _logger.debug(f"Opened {self._store}.") data = da.from_zarr(zarr.open(self._store)) + data = data[:self.positions] # not all positions may have been acquires self.dtype = data.dtype img = DataArray(data, dims=raw_dims, name=self.dirname) xarr = img.expand_dims( @@ -150,7 +152,7 @@ def xdata(self): return self._xdata def __len__(self) -> int: - return self.positions + return len(self.xdata.keys()) def __getitem__(self, key: str | int) -> MMOmeTiffFOV: key = _normalize_mm_pos_key(key) @@ -218,15 +220,14 @@ def _set_mm_meta(self, mm_meta: dict) -> None: mm_version == "2.0.1 20220920" and self._mm_meta["Summary"]["Prefix"] == "raw_data" ): - file_names = set( - [(key[0], val[0]) for key, val in self.coord_map.items()] - ) + files = natsorted(self.root.glob("*.ome.tif")) + self.positions = len(files) # not all positions are saved if self._mm_meta["Summary"]["Positions"] > 1: self._stage_positions = [None] * self.positions - for p_idx, file_name in file_names: - site_idx = int(file_name.split("_")[-1].split("-")[0]) + for p_idx, file_name in enumerate(files): + site_idx = int(str(file_name).split("_")[-1].split("-")[0]) pos = self._simplify_stage_position( self._mm_meta["Summary"]["StagePositions"][site_idx] )