Skip to content

Commit

Permalink
fix: fix slm image data repr and eq (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Nov 26, 2024
1 parent 3628eed commit 4b42d1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/useq/_mda_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SLMImage(UseqModel):
used. By default, `None`.
"""

data: Any
data: Any = Field(..., repr=False)
device: Optional[str] = None
exposure: Optional[float] = None

Expand All @@ -86,6 +86,15 @@ def __array__(self, *args: Any, **kwargs: Any) -> npt.NDArray:
"""Cast the image data to a numpy array."""
return np.asarray(self.data, *args, **kwargs)

def __eq__(self, other: object) -> bool:
if not isinstance(other, SLMImage):
return False
return (
self.device == other.device
and self.exposure == other.exposure
and np.array_equal(self.data, other.data)
)


class PropertyTuple(NamedTuple):
"""Three-tuple capturing a device, property, and value.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,5 @@ def test_slm_image() -> None:
# directly provide numpy array
event3 = MDAEvent(slm_image=SLMImage(data=np.ones((10, 10))))
print(repr(event3))

assert event3 != event2

0 comments on commit 4b42d1e

Please sign in to comment.