Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ess/reflectometry/orso.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for curiosity when do events end up with a nan coord?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That typically happens when we are unable to estimate the wavelength of the neutron.
We are unable to estimate the wavelength of the neutron if it arrived at a time, at a place in the detector where

  • we don't expect to see any events, or
  • the wavelength of the neutron is ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an example, here is where the wavelength is computed in the Amor workflow: https://github.com/scipp/essreflectometry/blob/main/src/ess/amor/conversions.py#L122-L130

If the arrival time is outside of the expected range it's assigned nan.

# Explicit conversions to float because orsopy does not like np.float* types.
return float(min_), float(max_), _ascii_unit(coord.unit)

Expand Down
24 changes: 23 additions & 1 deletion tests/orso_test.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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')
)
Loading