Skip to content

Commit

Permalink
OpenCell reader extension (#197)
Browse files Browse the repository at this point in the history
* stage positions parsing for opencell datasets

* formatting

* don't overwrite frames, slices, and channels in `_set_mm_meta`

* fix error getting stage position
  • Loading branch information
ieivanov authored Oct 25, 2023
1 parent e822aa8 commit ca593de
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
8 changes: 4 additions & 4 deletions iohub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ def _get_pos_names(self):
if self.p > 1:
self.pos_names = []
for p in range(self.p):
name = (
self.summary_metadata["StagePositions"][p].get("Label")
or p
)
try:
name = self.reader.stage_positions[p]["Label"]
except (IndexError, KeyError):
name = p
self.pos_names.append(name)
else:
self.pos_names = ["0"]
Expand Down
43 changes: 34 additions & 9 deletions iohub/multipagetiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def __init__(self, folder: str, extract_data: bool = False):
# Initialize MM attributes
self.channel_names = []

# Read MM data
self._set_mm_meta()

# Gather index map of file, page, byte offset
self._gather_index_maps()

# Read MM data
self._set_mm_meta()

# if extract data, create all of the virtual zarr stores up front
if extract_data:
for i in range(self.positions):
Expand Down Expand Up @@ -173,6 +173,29 @@ def _set_mm_meta(self):
for ch in self.mm_meta["Summary"].get("ChNames", []):
self.channel_names.append(ch)

# Parsing of data acquired with the OpenCell
# acquisition script on the Dragonfly miroscope
elif (
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()]
)

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])
pos = self._simplify_stage_position(
self.mm_meta["Summary"]["StagePositions"][site_idx]
)
self._stage_positions[p_idx] = pos

for ch in self.mm_meta["Summary"]["ChNames"]:
self.channel_names.append(ch)

else:
if self.mm_meta["Summary"]["Positions"] > 1:
self._stage_positions = []
Expand All @@ -186,15 +209,17 @@ def _set_mm_meta(self):
for ch in self.mm_meta["Summary"].get("ChNames", []):
self.channel_names.append(ch)

# dimensions based on mm metadata
# do not reflect final written dimensions
# these will change after data is loaded
self.z_step_size = self.mm_meta["Summary"]["z-step_um"]
self.height = self.mm_meta["Summary"]["Height"]
self.width = self.mm_meta["Summary"]["Width"]
self.frames = self.mm_meta["Summary"]["Frames"]
self.slices = self.mm_meta["Summary"]["Slices"]
self.channels = self.mm_meta["Summary"]["Channels"]

# dimensions based on mm metadata
# do not reflect final written dimensions
# these set in _gather_index_maps
#
# self.frames = self.mm_meta["Summary"]["Frames"]
# self.slices = self.mm_meta["Summary"]["Slices"]
# self.channels = self.mm_meta["Summary"]["Channels"]

def _simplify_stage_position(self, stage_pos: dict):
"""
Expand Down

0 comments on commit ca593de

Please sign in to comment.