Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ieivanov committed Oct 5, 2024
1 parent eb5ee14 commit fc1b0c3
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions iohub/mm_fov.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,32 @@ def hcs_position_labels(self):
if not self.stage_positions:
raise ValueError("Stage position metadata not available.")

# See https://chatgpt.com/share/e/67009155-d960-8008-bd64-aa3117b142b6
try:
labels = [pos["Label"] for pos in self.stage_positions]
except KeyError:
raise ValueError("Stage positions do not have labels.")

# See https://chatgpt.com/share/e/670097cc-2854-8008-bd33-b54cad7c99b9
pattern = re.compile(
r"([A-Za-z])?(\d+)-(?:Site_(\d+)|Pos(?:-)?(\d+)[-_](\d+))"
r"([A-Z])(\d+)-Site_(\d+)|"
r"Pos-(\d+)-(\d+)_(\d+)|"
r"(\d+)-Pos(\d+)_(\d+)"
)
labels = [pos.get("Label") for pos in self.stage_positions]
row_col_fov = []
for label in labels:
if label:
match = re.match(pattern, label)
if match:
row = match.group(1) if match.group(1) else "0"
col = match.group(2)
fov = (
match.group(3)
if match.group(3)
else f"{match.group(4)}{match.group(5)}"
if (match := re.match(pattern, label)) is not None:
if match.group(1): # "A1-Site_0" case
row_col_fov.append(
(match.group(1), match.group(2), match.group(3))
)
elif match.group(4): # "Pos-5-000_005" case
row_col_fov.append(
("0", match.group(4), match.group(5) + match.group(6))
)
else: # "1-Pos000_000" case
row_col_fov.append(
("0", match.group(7), match.group(8) + match.group(9))
)

row_col_fov.append((row, col, fov))

if not row_col_fov:
raise ValueError(
Expand Down

0 comments on commit fc1b0c3

Please sign in to comment.