Skip to content

Commit

Permalink
feat: add well-plate model (#166)
Browse files Browse the repository at this point in the history
* wip plate plan

* style(pre-commit.ci): auto fixes [...]

* improvements

* style(pre-commit.ci): auto fixes [...]

* add some tests

* remove x

* rename

* random points

* temporarily include x.py

* Update src/useq/_plate.py

Co-authored-by: federico gasparoli <[email protected]>

* add way to register plates

* py38

* fix 38

* Update _plate.py

Co-authored-by: federico gasparoli <[email protected]>

* fix type

* more fix

* lint

* fix

* fix 389

* fix again

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: federico gasparoli <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 666a692 commit 6bed705
Show file tree
Hide file tree
Showing 10 changed files with 665 additions and 8 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ repos:
additional_dependencies:
- types-PyYAML
- pydantic >=2
- numpy >=2
10 changes: 10 additions & 0 deletions src/useq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from useq._hardware_autofocus import AnyAutofocusPlan, AutoFocusPlan, AxesBasedAF
from useq._mda_event import MDAEvent, PropertyTuple
from useq._mda_sequence import MDASequence
from useq._plate import (
WellPlate,
WellPlatePlan,
known_well_plate_keys,
register_well_plates,
)
from useq._position import Position
from useq._time import (
AnyTimePlan,
Expand All @@ -34,6 +40,7 @@
__all__ = [
"AcquireImage",
"Action",
"register_well_plates",
"AnyAutofocusPlan",
"AnyGridPlan",
"AnyTimePlan",
Expand All @@ -46,6 +53,7 @@
"GridRowsColumns",
"GridWidthHeight",
"HardwareAutofocus",
"known_well_plate_keys",
"MDAEvent",
"MDASequence",
"MultiPhaseTimePlan",
Expand All @@ -55,6 +63,8 @@
"TDurationLoops",
"TIntervalDuration",
"TIntervalLoops",
"WellPlatePlan",
"WellPlate",
"ZAboveBelow",
"ZAbsolutePositions",
"ZRangeAround",
Expand Down
4 changes: 2 additions & 2 deletions src/useq/_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def replace(self: _T, **kwargs: Any) -> _T:
state = self.model_dump(exclude={"uid"})
return type(self)(**{**state, **kwargs})


class UseqModel(FrozenModel):
def __repr_args__(self) -> "ReprArgs":
"""Only show fields that are not None or equal to their default value."""
return [
Expand All @@ -65,6 +63,8 @@ def __repr_args__(self) -> "ReprArgs":
)
]


class UseqModel(FrozenModel):
@classmethod
def from_file(cls: Type[_Y], path: Union[str, Path]) -> _Y:
"""Return an instance of this class from a file. Supports JSON and YAML."""
Expand Down
6 changes: 3 additions & 3 deletions src/useq/_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ class RandomPoints(_PointsPlan):
"""

num_points: int
max_width: float
max_height: float
shape: Shape
max_width: float = np.inf
max_height: float = np.inf
shape: Shape = Shape.ELLIPSE
random_seed: Optional[int] = None
allow_overlap: bool = True

Expand Down
6 changes: 5 additions & 1 deletion src/useq/_mda_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Optional,
Sequence,
Tuple,
Union,
)
from uuid import UUID, uuid4
from warnings import warn
Expand All @@ -22,6 +23,7 @@
from useq._grid import AnyGridPlan, GridPosition # noqa: TCH001
from useq._hardware_autofocus import AnyAutofocusPlan, AxesBasedAF
from useq._iter_sequence import iter_sequence
from useq._plate import WellPlatePlan # noqa: TCH001
from useq._position import Position
from useq._time import AnyTimePlan # noqa: TCH001
from useq._utils import AXES, Axis, TimeEstimate, estimate_sequence_duration
Expand Down Expand Up @@ -179,7 +181,9 @@ class MDASequence(UseqModel):

metadata: Dict[str, Any] = Field(default_factory=dict)
axis_order: Tuple[str, ...] = AXES
stage_positions: Tuple[Position, ...] = Field(default_factory=tuple)
stage_positions: Union[WellPlatePlan, Tuple[Position, ...]] = Field(
default_factory=tuple
)
grid_plan: Optional[AnyGridPlan] = None
channels: Tuple[Channel, ...] = Field(default_factory=tuple)
time_plan: Optional[AnyTimePlan] = None
Expand Down
Loading

0 comments on commit 6bed705

Please sign in to comment.