scipp / scippnexus

h5py-like utility for NeXus files with seamless scipp integration
https://scipp.github.io/scippnexus/
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

Support nested loading as DataGroup and change error handling #95

Closed SimonHeybrock closed 1 year ago

SimonHeybrock commented 1 year ago

Fixes #85. Fixes #73.

There are two major changes here:

  1. Any NXobject can now be loaded as scipp.DataGroup.
  2. If an implementation of NXobject fails to load (e.g., as a DataArray), the implementation will fall back to a generic load of all datasets in subgroups as a DataGroup. Previously, this was handled in a variety of cases by simply skipping the offending dataset or group.

Note that this depends on scipp 23.01.0, and I will need to run pip-compile-multi after that is released. For now the builds will fail.

While 2.) is generally an improvement, there are cases where it hurts usability. For example, for a WISH file we previously got:

/home/simon/code/scipp/scippnexus/src/scippnexus/nxdata.py:243: UserWarning: Skipped load of axis /raw_data_1/instrument/detector_1/event_frame_number due to:
Expected dimension to be in [spectrum_index:97280, ], got dim_0.
  warn(f"Skipped load of axis {field.name} due to:\n{e}")
/home/simon/code/scipp/scippnexus/src/scippnexus/nxdata.py:243: UserWarning: Skipped load of axis /raw_data_1/instrument/detector_1/event_time_bins due to:
Expected dimension to be in [spectrum_index:97280, ], got dim_0.
  warn(f"Skipped load of axis {field.name} due to:\n{e}")
/home/simon/code/scipp/scippnexus/src/scippnexus/nxdata.py:243: UserWarning: Skipped load of axis /raw_data_1/instrument/detector_1/time_of_flight due to:
Expected dimension to be in [spectrum_index:97280, ], got dim_0.
  warn(f"Skipped load of axis {field.name} due to:\n{e}")
/home/simon/code/scipp/scippnexus/src/scippnexus/nxobject.py:295: UserWarning: Unrecognized unit 'pulses' for value dataset in '/raw_data_1/instrument/detector_1/time_of_flight_raw'; setting unit as 'dimensionless'
  warnings.warn(f"Unrecognized unit '{unit}' for value dataset "
/home/simon/code/scipp/scippnexus/src/scippnexus/nxdata.py:243: UserWarning: Skipped load of axis /raw_data_1/instrument/detector_1/time_of_flight_raw due to:
Expected dimension to be in [spectrum_index:97280, ], got dim_0.
  warn(f"Skipped load of axis {field.name} due to:\n{e}")

with a (partially) successful load as data binned into pixels:

image

Now we get this instead:

image

This is more complete, but less useful for the average user.

SimonHeybrock commented 1 year ago

@jl-wynen Do you have more comments on this? Builds are passing now, I think.