Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug determining number of rows and cols #214

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading