Skip to content

Commit 49e72e1

Browse files
authored
Merge pull request #156 from scipp/fix-orso-aggregates
fix: show nonnan aggregates
2 parents dba5d79 + 71a645e commit 49e72e1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/ess/reflectometry/orso.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def _extract_values_array(var: sc.Variable) -> np.ndarray:
244244
def _limits_of_coord(data: sc.DataArray, name: str) -> tuple[float, float, str] | None:
245245
if (coord := _get_coord(data, name)) is None:
246246
return None
247-
min_ = coord.min().value
248-
max_ = coord.max().value
247+
min_ = coord.nanmin().value
248+
max_ = coord.nanmax().value
249249
# Explicit conversions to float because orsopy does not like np.float* types.
250250
return float(min_), float(max_), _ascii_unit(coord.unit)
251251

tests/orso_test.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
33
from datetime import datetime
4+
from math import isnan
45

56
import sciline
7+
import scipp as sc
68
from orsopy import fileio
79

810
from ess import amor, reflectometry
911
from ess.amor import data # noqa: F401
1012
from ess.reflectometry import orso
11-
from ess.reflectometry.types import Filename, ReferenceRun, SampleRun
13+
from ess.reflectometry.types import Filename, ReducibleData, ReferenceRun, SampleRun
1214

1315

1416
def test_build_orso_data_source():
@@ -54,3 +56,23 @@ def test_build_orso_reduction_with_creator():
5456
assert reduction.software.name == "ess.reflectometry"
5557
assert reduction.software.version == str(reflectometry.__version__)
5658
assert reduction.creator == creator
59+
60+
61+
def test_build_orso_aggregates_are_not_nan():
62+
events = sc.DataArray(
63+
sc.array(dims='x', values=[1, 2, 3, 4]),
64+
coords={
65+
'theta': sc.array(dims='x', values=[0, 0.5, 1, float('nan')]),
66+
'wavelength': sc.array(dims='x', values=[0, 0.5, 1, float('nan')]),
67+
},
68+
)
69+
pipeline = sciline.Pipeline(
70+
orso.providers, params={ReducibleData[SampleRun]: events}
71+
)
72+
instrument = pipeline.compute(orso.OrsoInstrument)
73+
assert not any(
74+
isnan(getattr(instrument.incident_angle, attr)) for attr in ('min', 'max')
75+
)
76+
assert not any(
77+
isnan(getattr(instrument.wavelength, attr)) for attr in ('min', 'max')
78+
)

0 commit comments

Comments
 (0)