Skip to content

Commit

Permalink
MNT #1260 refactor per discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Jul 31, 2024
1 parent 1e9b4f7 commit f2af9c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions ophyd/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ def test_set_signal_to_None():
# compare array shapes
[[1, 2, 3], [1, 2, 3], [], None, None, True], # identical
[[1, 2, 3], [0, 0, 0], [], None, None, False], # b has different values
[[1, 2, 3], [1, 2, 3, 0], [], None, None, True], # only compares len(a) items
[[1, 2, 3, 0], [1, 2, 3], [], None, None, False], # len(a) > len(b)
[[1, 2, 3], [1, 2, 3, 0], [], None, None, False], # different shape
# [[1, 2, 3, 0], [1, 2, 3], [], None, None, False], # len(a) > len(b)
[5, [1, 2, 3], [], None, None, False], # not the same type
[[1, 2, 3], 5, [], None, None, False], # not the same type
# numpy arrays
[[1, 2, 3], np.array([1, 2, 3]), [], None, None, True], # identical
[[1, 2, 3], np.array([1, 2, 3, 0]), [], None, None, True], # len(a)
# [[1, 2, 3], np.array([1, 2, 3, 0]), [], None, None, True], # len(a)
# tuple
[(1, 2, 3), np.array([1, 2, 3]), [], None, None, True], # identical
# with tolerance
Expand Down
24 changes: 13 additions & 11 deletions ophyd/utils/epics_pvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ def _wait_for_value(signal, val, poll_time=0.01, timeout=10, rtol=None, atol=Non
TimeoutError if timeout is exceeded
"""
expiration_time = ttime.time() + timeout if timeout is not None else None
current_value = signal.get()
array_like = (list, np.ndarray, tuple)
item_count = None if not isinstance(val, array_like) else len(val)
current_value = signal.get(count=item_count)

if atol is None and hasattr(signal, "tolerance"):
atol = signal.tolerance
Expand Down Expand Up @@ -305,7 +307,7 @@ def _wait_for_value(signal, val, poll_time=0.01, timeout=10, rtol=None, atol=Non
ttime.sleep(poll_time)
if poll_time < 0.1:
poll_time *= 2 # logarithmic back-off
current_value = signal.get()
current_value = signal.get(count=item_count)
if expiration_time is not None and ttime.time() > expiration_time:
raise TimeoutError(
"Attempted to set %r to value %r and timed "
Expand Down Expand Up @@ -335,15 +337,15 @@ def _compare_maybe_enum(a, b, enums, atol, rtol):
# then compare the strings
return a == b

array_like = (list, np.ndarray, tuple)
if isinstance(a, array_like) and isinstance(b, array_like):
a = np.array(a) # target
b = np.array(b) # reported by EPICS
if len(a.shape) == 1 and len(b.shape) == 1 and len(a) < len(b):
b = b[: len(a)] # cut 1-D EPICS array down to requested size

if a.shape != b.shape:
return False
# array_like = (list, np.ndarray, tuple)
# if isinstance(a, array_like) and isinstance(b, array_like):
# a = np.array(a) # target
# b = np.array(b) # reported by EPICS
# if len(a.shape) == 1 and len(b.shape) == 1 and len(a) < len(b):
# b = b[: len(a)] # cut 1-D EPICS array down to requested size

# if a.shape != b.shape:
# return False

# if either relative/absolute tolerance is used, use numpy
# to compare:
Expand Down

0 comments on commit f2af9c0

Please sign in to comment.