Skip to content

Commit

Permalink
Merge pull request bluesky#1025 from DominicOram/fix_AD_trigger_statu…
Browse files Browse the repository at this point in the history
…s_fraction

BUG: Fixed fraction in ADTriggerStatus to match docs
  • Loading branch information
DominicOram committed Jan 16, 2024
2 parents 4528dba + 1540899 commit 264e3df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ophyd/areadetector/trigger_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def _notify_watchers(self, value, *args, **kwargs):
initial = 0
time_elapsed = ttime.time() - self.start_ts
try:
fraction = (current - initial) / (target - initial)
fraction = 1 - (current - initial) / (target - initial)
except ZeroDivisionError:
fraction = 1
fraction = 0
except Exception:
fraction = None
time_remaining = None
Expand Down
25 changes: 25 additions & 0 deletions ophyd/tests/test_areadetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from ophyd.areadetector.util import stub_templates
from ophyd.device import Component as Cpt
from ophyd.signal import Signal
from ophyd.sim import make_fake_device
from ophyd.utils.paths import make_dir_tree

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -951,3 +952,27 @@ class MyDetector(SimDetector):
{n: getattr(d, n).read_configuration() for n in d.component_names}
{n: getattr(d, n).describe_configuration() for n in d.component_names}
d.unstage()


def test_ADTriggerStatus_gives_correct_fraction():
class MyDetector(SingleTrigger, SimDetector):
pass

FakeMyDetector = make_fake_device(MyDetector)

det: MyDetector = FakeMyDetector("", name="test")
det.cam.num_images.put(5)
det.cam.array_counter.put(0)

det.stage()
st = det.trigger()

watcher = Mock()
st.watch(watcher)

det.cam.array_counter.put(1)
mock_called_kwargs = watcher.call_args[1]
assert mock_called_kwargs["initial"] == 0
assert mock_called_kwargs["target"] == 5
assert mock_called_kwargs["current"] == 1
assert mock_called_kwargs["fraction"] == 4 / 5

0 comments on commit 264e3df

Please sign in to comment.