From 47e23cabc03b7bf4492f5b43e7460dcfd123f3e4 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Tue, 6 May 2025 10:42:15 +0200 Subject: [PATCH] fix: show nonnan aggregates --- src/ess/reflectometry/orso.py | 4 ++-- tests/orso_test.py | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/ess/reflectometry/orso.py b/src/ess/reflectometry/orso.py index 5f75eca0..268866e0 100644 --- a/src/ess/reflectometry/orso.py +++ b/src/ess/reflectometry/orso.py @@ -244,8 +244,8 @@ def _extract_values_array(var: sc.Variable) -> np.ndarray: def _limits_of_coord(data: sc.DataArray, name: str) -> tuple[float, float, str] | None: if (coord := _get_coord(data, name)) is None: return None - min_ = coord.min().value - max_ = coord.max().value + min_ = coord.nanmin().value + max_ = coord.nanmax().value # Explicit conversions to float because orsopy does not like np.float* types. return float(min_), float(max_), _ascii_unit(coord.unit) diff --git a/tests/orso_test.py b/tests/orso_test.py index c1f7b484..89feba08 100644 --- a/tests/orso_test.py +++ b/tests/orso_test.py @@ -1,14 +1,16 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) from datetime import datetime +from math import isnan import sciline +import scipp as sc from orsopy import fileio from ess import amor, reflectometry from ess.amor import data # noqa: F401 from ess.reflectometry import orso -from ess.reflectometry.types import Filename, ReferenceRun, SampleRun +from ess.reflectometry.types import Filename, ReducibleData, ReferenceRun, SampleRun def test_build_orso_data_source(): @@ -54,3 +56,23 @@ def test_build_orso_reduction_with_creator(): assert reduction.software.name == "ess.reflectometry" assert reduction.software.version == str(reflectometry.__version__) assert reduction.creator == creator + + +def test_build_orso_aggregates_are_not_nan(): + events = sc.DataArray( + sc.array(dims='x', values=[1, 2, 3, 4]), + coords={ + 'theta': sc.array(dims='x', values=[0, 0.5, 1, float('nan')]), + 'wavelength': sc.array(dims='x', values=[0, 0.5, 1, float('nan')]), + }, + ) + pipeline = sciline.Pipeline( + orso.providers, params={ReducibleData[SampleRun]: events} + ) + instrument = pipeline.compute(orso.OrsoInstrument) + assert not any( + isnan(getattr(instrument.incident_angle, attr)) for attr in ('min', 'max') + ) + assert not any( + isnan(getattr(instrument.wavelength, attr)) for attr in ('min', 'max') + )