Skip to content

Commit

Permalink
Fix RollingDetectorView.clear_counts
Browse files Browse the repository at this point in the history
startinew.clear_countsV
  • Loading branch information
SimonHeybrock committed Feb 3, 2025
1 parent b4f248b commit e9473d8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ess/reduce/live/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ def __init__(
self._current = 0
self._history: sc.DataArray | None = None
self._cache: sc.DataArray | None = None
self.clear_counts()

def clear_counts(self) -> None:
"""
Clear counts.
Overrides Detector.clear_counts, to properly clear sliding window history and
cache.
"""
counts = sc.zeros_like(self.data)
if self._projection is not None:
counts = self._projection(counts)
Expand Down
17 changes: 17 additions & 0 deletions tests/live/raw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ def test_RollingDetectorView_partial_window() -> None:
assert det.get(3).sum().value == 4


def test_RollingDetectorView_clear_counts() -> None:
detector_number = sc.array(dims=['pixel'], values=[1, 2, 3], unit=None)
det = raw.RollingDetectorView(detector_number=detector_number, window=3)
det.add_counts([1, 2, 3, 2])
assert det.get(0).sum().value == 0
assert det.get(1).sum().value == 4
assert det.get(2).sum().value == 4
assert det.get(3).sum().value == 4
assert det.get().sum().value == 4
det.clear_counts()
assert det.get(0).sum().value == 0
assert det.get(1).sum().value == 0
assert det.get(2).sum().value == 0
assert det.get(3).sum().value == 0
assert det.get().sum().value == 0


def test_RollingDetectorView_raises_if_subwindow_exceeds_window() -> None:
detector_number = sc.array(dims=['pixel'], values=[1, 2, 3], unit=None)
det = raw.RollingDetectorView(detector_number=detector_number, window=3)
Expand Down

0 comments on commit e9473d8

Please sign in to comment.