Skip to content

Commit 29845d0

Browse files
committed
change logic around EmptyField to assume that we must have a data and a value field.
1 parent dc5579f commit 29845d0

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/ess/reduce/nexus/workflow.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -531,28 +531,35 @@ class _StrippedDetector(snx.NXdetector):
531531
def __init__(
532532
self, attrs: dict[str, Any], children: dict[str, snx.Field | snx.Group]
533533
):
534-
# We get the 'data' sizes before the NXdata is dropped
535-
field_sizes = None
536-
if ('detector_number' not in children) and ('data' in children):
534+
if 'detector_number' in children:
535+
data = children['detector_number']
536+
else:
537+
# We get the 'data' sizes before the NXdata is dropped
538+
if 'data' not in children:
539+
raise KeyError(
540+
"StrippedDetector: Cannot determine shape of the detector. "
541+
"No 'detector_number' was found, and the 'data' entry is missing."
542+
)
537543
if 'value' not in children['data']:
538544
raise KeyError(
539-
"Cannot determine shape of detector data as 'data' field has no"
540-
"'value'."
545+
"StrippedDetector: Cannot determine shape of the detector. "
546+
"The 'data' entry has no 'value'."
541547
)
542-
field_sizes = {
543-
dim: size
544-
for dim, size in children['data']['value'].sizes.items()
545-
if dim not in ('time', 'frame_time')
546-
}
548+
# We drop any time-related dimension from the data sizes, as they are not
549+
# relevant for the detector geometry/shape.
550+
data = _EmptyField(
551+
sizes={
552+
dim: size
553+
for dim, size in children['data']['value'].sizes.items()
554+
if dim not in ('time', 'frame_time')
555+
}
556+
)
547557

548558
children = _drop(
549559
children, (snx.NXoff_geometry, snx.NXevent_data, snx.NXdata, snx.NXlog)
550560
)
551561

552-
if 'detector_number' in children:
553-
children['data'] = children['detector_number']
554-
elif field_sizes is not None:
555-
children['data'] = _EmptyField(sizes=field_sizes)
562+
children['data'] = data
556563

557564
super().__init__(attrs=attrs, children=children)
558565

0 commit comments

Comments
 (0)