Skip to content

Commit

Permalink
Support unsorted bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Feb 7, 2025
1 parent f21e22b commit 5e25b53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ess/reduce/live/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def select_indices_in_intervals(
indices will be returned concatenated into a dense array.
"""
out_dim = 'index'
for dim, (low, high) in intervals.items():
for dim, bounds in intervals.items():
low, high = sorted(bounds)
indices = indices[dim, low:high]
indices = indices.flatten(to=out_dim)
if indices.bins is None:
Expand Down
10 changes: 10 additions & 0 deletions tests/live/roi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ def test_select_indices_label_based_indexing(binned_indices):
assert selected.sizes[selected.dim] < binned_indices.bins.size().sum().value


def test_select_indices_label_based_indexing_reverse_order(binned_indices):
selected = roi.select_indices_in_intervals(
intervals=sc.DataGroup(x=(sc.scalar(0.5, unit='m'), sc.scalar(0.3, unit='m'))),
indices=binned_indices,
)
assert selected.dim == 'index'
assert selected.sizes[selected.dim] > 0
assert selected.sizes[selected.dim] < binned_indices.bins.size().sum().value


def test_select_indices_fails_with_invalid_dimension():
data = sc.data.table_xyz(10)
with pytest.raises(sc.DimensionError):
Expand Down

0 comments on commit 5e25b53

Please sign in to comment.