diff --git a/iohub/convert.py b/iohub/convert.py index a7c409ea..2528a15d 100644 --- a/iohub/convert.py +++ b/iohub/convert.py @@ -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