Skip to content

Commit dc48564

Browse files
authored
fix: clear x/y positions for absolute grid plans in MDASequence and PositionTable (#509)
1 parent 6044b50 commit dc48564

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/pymmcore_widgets/useq_widgets/_mda_sequence.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,26 @@ def usedAxes(self) -> tuple[str, ...]:
125125

126126
def value(self) -> useq.MDASequence:
127127
"""Return the current sequence as a [`useq.MDASequence`][]."""
128+
grid_plan = self.grid_plan.value() if self.isAxisUsed("g") else None
129+
positions = self.stage_positions.value() if self.isAxisUsed("p") else ()
130+
131+
# If a global absolute grid plan is used, x/y on positions are
132+
# meaningless (the grid defines them). Clear them to avoid useq
133+
# validation warnings.
134+
if grid_plan is not None and not grid_plan.is_relative and positions:
135+
positions = tuple(
136+
pos.replace(x=None, y=None)
137+
if pos.x is not None or pos.y is not None
138+
else pos
139+
for pos in positions
140+
)
141+
128142
return useq.MDASequence(
129143
z_plan=self.z_plan.value() if self.isAxisUsed("z") else None,
130144
time_plan=self.time_plan.value() if self.isAxisUsed("t") else None,
131-
stage_positions=(
132-
self.stage_positions.value() if self.isAxisUsed("p") else ()
133-
),
145+
stage_positions=positions,
134146
channels=self.channels.value() if self.isAxisUsed("c") else (),
135-
grid_plan=self.grid_plan.value() if self.isAxisUsed("g") else None,
147+
grid_plan=grid_plan,
136148
metadata={PYMMCW_METADATA_KEY: {"version": pymmcore_widgets.__version__}},
137149
)
138150

src/pymmcore_widgets/useq_widgets/_positions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ def value(
245245
# update the sub-sequence dict in the record
246246
r["sequence"] = sub_seq
247247

248+
# If a sub-sequence uses an absolute grid plan, x/y on the
249+
# position are meaningless (the grid defines them). Clear them
250+
# to avoid useq validation warnings.
251+
sub = r.get("sequence")
252+
if isinstance(sub, useq.MDASequence) and sub.grid_plan is not None:
253+
if not sub.grid_plan.is_relative:
254+
r.pop("x", None)
255+
r.pop("y", None)
256+
248257
pos = useq.Position(**r)
249258
out.append(pos)
250259

tests/test_useq_core_widgets.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,6 @@ def test_sub_wdg_channel_tab(qtbot: QtBot, global_mmcore: CMMCorePlus) -> None:
10711071
),
10721072
stage_positions=(
10731073
useq.AbsolutePosition(
1074-
x=1,
1075-
y=2,
10761074
z=3,
10771075
name="pos1",
10781076
sequence=useq.MDASequence(grid_plan=poly1),

0 commit comments

Comments
 (0)