Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Sep 13, 2024
2 parents 6c7667c + fe35207 commit 45780f9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.6.4
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand Down
17 changes: 14 additions & 3 deletions src/useq/_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def from_str(cls, name: str) -> WellPlate:
f"Unknown plate name {name!r}. "
"Use `useq.register_well_plates` to add new plate definitions"
) from e
if isinstance(obj, dict) and "name" not in obj:
obj = {**obj, "name": name}
return WellPlate.model_validate(obj)


Expand All @@ -144,10 +146,11 @@ class WellPlatePlan(UseqModel, Sequence[Position]):
selected_wells : IndexExpression | None
Any <=2-dimensional index expression for selecting wells.
for example:
- None -> all wells are selected.
- None -> No wells are selected.
- slice(0) -> (also) select no wells.
- slice(None) -> Selects all wells.
- 0 -> Selects the first row.
- [0, 1, 2] -> Selects the first three rows.
- slice(0) -> select no wells
- slice(1, 5) -> selects wells from row 1 to row 4.
- (2, slice(1, 4)) -> select wells in the second row and only columns 1 to 3.
- ([1, 2], [3, 4]) -> select wells in (row, column): (1, 3) and (2, 4)
Expand Down Expand Up @@ -236,6 +239,10 @@ def _validate_selected_wells(

if isinstance(value, list):
value = tuple(value)
# make falsey values select no wells (rather than all wells)
if not value:
value = slice(0)

try:
selected = plate.indices(value)
except (TypeError, IndexError) as e:
Expand All @@ -261,11 +268,15 @@ def __iter__(self) -> Iterable[Position]: # type: ignore
def __len__(self) -> int:
"""Return the total number of points (stage positions) to be acquired."""
if self.selected_wells is None:
n_wells = self.plate.size
n_wells = 0
else:
n_wells = len(self.selected_wells[0])
return n_wells * self.num_points_per_well

def __bool__(self) -> bool:
"""bool(WellPlatePlan) == True."""
return True

@overload
def __getitem__(self, index: int) -> Position: ...

Expand Down
4 changes: 4 additions & 0 deletions tests/test_well_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ def test_plate_plan_well_points() -> None:
a1_center_xy=(500, 200),
rotation="0.2rad",
well_points_plan=useq.RandomPoints(num_points=10),
selected_wells=slice(None),
)
assert len(pp) == 96 * 10

pp2 = useq.WellPlatePlan(plate=96, a1_center_xy=(500, 200), selected_wells=None)
assert len(pp2) == 0


def test_plate_plan_plot(monkeypatch: pytest.MonkeyPatch) -> None:
mpl = pytest.importorskip("matplotlib.pyplot")
Expand Down

0 comments on commit 45780f9

Please sign in to comment.