Skip to content

Commit 211465f

Browse files
Merge pull request #868 from scipp/fix-monitor-histogram-edge-unit
Fix monitor histogram output losing user-configured edge unit
2 parents 81adb50 + 7e6e1c5 commit 211465f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/ess/livedata/handlers/monitor_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def _histogram_monitor(
5757
{target_dim: event_coord}
5858
)
5959
hist = data.hist({event_coord: edges_converted}, dim=data.dims)
60-
# Rename dimension and coordinate to target dimension
60+
# Rename dimension and coordinate back to target dimension and unit
6161
hist = hist.rename_dims({event_coord: target_dim})
62-
hist.coords[target_dim] = hist.coords.pop(event_coord)
62+
hist.coords[target_dim] = hist.coords.pop(event_coord).to(unit=edges.unit)
6363
else:
6464
# Histogram-mode: already histogrammed from Cumulative preprocessor
6565
# Rename dimension if needed

tests/handlers/monitor_workflow_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ def test_histogram_raw_monitor_event_mode(self, sample_events, toa_edges):
166166
# All 5 events should be histogrammed
167167
assert result.sum().value == 5.0
168168

169+
def test_histogram_raw_monitor_preserves_edge_unit(self, sample_events):
170+
edges = sc.linspace('time_of_arrival', 0, 10, num=6, unit='us')
171+
result = histogram_raw_monitor(sample_events, edges)
172+
assert result.coords['time_of_arrival'].unit == 'us'
173+
169174
def test_histogram_raw_monitor_histogram_mode(self, toa_edges):
170175
"""Test rebinning of already-histogrammed monitor data."""
171176
# Create input histogram with different edges (finer binning)

0 commit comments

Comments
 (0)