Skip to content

Commit 4d0b8a6

Browse files
authored
Merge pull request #704 from scipp/check-coords-instrument-view
Check coords are identical in slicing dimension in instrument view
2 parents 226a735 + c0c3e48 commit 4d0b8a6

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/scippneutron/instrument_view.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@ def _to_data_array(
1414
if isinstance(data, sc.DataArray):
1515
data = sc.DataGroup({"": data})
1616
pieces = []
17+
dim_coord = None
1718
for da in data.values():
1819
da = da.drop_coords(list(set(da.coords) - {pos, dim}))
1920
position_dims = tuple(da.coords[pos].dims)
2021
if dim is not None:
22+
if dim_coord is None:
23+
dim_coord = da.coords[dim]
24+
elif not sc.identical(dim_coord, da.coords[dim]):
25+
raise ValueError(
26+
"All inputs must have the same coordinate along the slider"
27+
f" dimension '{dim}'."
28+
)
2129
# Ensure that the dims to be flattened are contiguous, and place them at
2230
# the end so that slicing the first (outer) dim with the slider is
2331
# efficient.

tests/instrument_view_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import matplotlib
55
import numpy as np
6+
import pytest
67
import scipp as sc
78

89
import scippneutron as scn
@@ -92,3 +93,17 @@ def test_neutron_instrument_view_with_masks():
9293
def test_neutron_instrument_view_with_cmap_args():
9394
bank = make_detector_bank(center=(0, 0, 5))
9495
scn.instrument_view(bank, size=0.1, vmin=10.0, vmax=50.0, cmap="magma", logc=True)
96+
97+
98+
def test_instrument_view_two_banks_dict_with_dim_different_coords_raises():
99+
bank1 = make_detector_bank(center=(-1.5, 0, 5))
100+
bank2 = make_detector_bank(center=(1.5, 0, 5))
101+
bank2.coords['time'] *= 1.01
102+
bank3 = make_detector_bank(center=(1.5, 0, 5))
103+
with pytest.raises(
104+
ValueError,
105+
match="All inputs must have the same coordinate along the slider dimension",
106+
):
107+
scn.instrument_view(
108+
{"bank1": bank1, "bank2": bank2, "bank3": bank3}, size=0.1, dim='time'
109+
)

0 commit comments

Comments
 (0)