Skip to content

Commit

Permalink
Fix bug determining number of rows and cols (#214)
Browse files Browse the repository at this point in the history
* fix bug determining number of rows and cols

* add another XY Stage variation

* add docs and fix style
  • Loading branch information
ieivanov authored Mar 11, 2024
1 parent 3ab89ba commit 0c6984e
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions iohub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,41 @@ def _make_default_grid(self):
)

def _get_position_coords(self):
row_max = 0
col_max = 0
coords_list = []
"""Get the position coordinates from the reader metadata.
Raises:
ValueError: If stage positions are not available.
Returns:
list: XY stage position coordinates.
int: Number of grid rows.
int: Number of grid columns.
"""
rows = set()
cols = set()
xy_coords = []

# TODO: read rows, cols directly from XY corods
# TODO: account for non MM2gamma meta?
if not self.reader.stage_positions:
raise ValueError("Stage positions not available.")
for idx, pos in enumerate(self.reader.stage_positions):
stage_pos = pos.get("XYStage") or pos.get("XY")
stage_pos = (
pos.get("XYStage") or pos.get("XY") or pos.get("XY Stage")
)
if stage_pos is None:
raise ValueError(
f"Stage position is not available for position {idx}"
)
coords_list.append(stage_pos)
xy_coords.append(stage_pos)
try:
row = pos["GridRow"]
col = pos["GridCol"]
rows.add(pos["GridRow"])
cols.add(pos["GridCol"])
except KeyError:
raise ValueError(
f"Grid indices not available for position {idx}"
)
row_max = row if row > row_max else row_max
col_max = col if col > col_max else col_max

return coords_list, row_max + 1, col_max + 1
return xy_coords, len(rows), len(cols)

def _get_pos_names(self):
"""Append a list of pos names in ascending order
Expand Down

0 comments on commit 0c6984e

Please sign in to comment.