essreduce 25.11.0__py3-none-any.whl → 25.11.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -385,7 +385,11 @@ def get_calibrated_detector(
385
385
  # If the NXdetector in the file is not 1-D, we want to match the order of dims.
386
386
  # zip_pixel_offsets otherwise yields a vector with dimensions in the order given
387
387
  # by the x/y/z offsets.
388
- offsets = snx.zip_pixel_offsets(da.coords).transpose(da.dims).copy()
388
+ offsets = snx.zip_pixel_offsets(da.coords)
389
+ # Get the dims in the order of the detector data array, but filter out dims that
390
+ # don't exist in the offsets (e.g. the detector data may have a 'time' dimension).
391
+ dims = [dim for dim in da.dims if dim in offsets.dims]
392
+ offsets = offsets.transpose(dims).copy()
389
393
  # We use the unit of the offsets as this is likely what the user expects.
390
394
  if transform.value.unit is not None and transform.value.unit != '':
391
395
  transform_value = transform.value.to(unit=offsets.unit)
@@ -399,7 +403,7 @@ def get_calibrated_detector(
399
403
 
400
404
  def assemble_detector_data(
401
405
  detector: EmptyDetector[RunType],
402
- event_data: NeXusData[snx.NXdetector, RunType],
406
+ neutron_data: NeXusData[snx.NXdetector, RunType],
403
407
  ) -> RawDetector[RunType]:
404
408
  """
405
409
  Assemble a detector data array with event data.
@@ -410,14 +414,15 @@ def assemble_detector_data(
410
414
  ----------
411
415
  detector:
412
416
  Calibrated detector data array.
413
- event_data:
414
- Event data array.
417
+ neutron_data:
418
+ Neutron data array (events or histogram).
415
419
  """
416
- grouped = nexus.group_event_data(
417
- event_data=event_data, detector_number=detector.coords['detector_number']
418
- )
420
+ if neutron_data.bins is not None:
421
+ neutron_data = nexus.group_event_data(
422
+ event_data=neutron_data, detector_number=detector.coords['detector_number']
423
+ )
419
424
  return RawDetector[RunType](
420
- _add_variances(grouped)
425
+ _add_variances(neutron_data)
421
426
  .assign_coords(detector.coords)
422
427
  .assign_masks(detector.masks)
423
428
  )
@@ -504,6 +509,19 @@ def _drop(
504
509
  }
505
510
 
506
511
 
512
+ class _EmptyField:
513
+ """Empty field that can replace a missing detector_number in NXdetector."""
514
+
515
+ def __init__(self, sizes: dict[str, int]):
516
+ self.attrs = {}
517
+ self.sizes = sizes.copy()
518
+ self.dims = tuple(sizes.keys())
519
+ self.shape = tuple(sizes.values())
520
+
521
+ def __getitem__(self, key: Any) -> sc.Variable:
522
+ return sc.zeros(dims=self.dims, shape=self.shape, unit=None, dtype='int32')
523
+
524
+
507
525
  class _StrippedDetector(snx.NXdetector):
508
526
  """Detector definition without large geometry or event data for ScippNexus.
509
527
 
@@ -513,8 +531,36 @@ class _StrippedDetector(snx.NXdetector):
513
531
  def __init__(
514
532
  self, attrs: dict[str, Any], children: dict[str, snx.Field | snx.Group]
515
533
  ):
516
- children = _drop(children, (snx.NXoff_geometry, snx.NXevent_data))
517
- children['data'] = children['detector_number']
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
+ )
543
+ if 'value' not in children['data']:
544
+ raise KeyError(
545
+ "StrippedDetector: Cannot determine shape of the detector. "
546
+ "The 'data' entry has no 'value'."
547
+ )
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
+ )
557
+
558
+ children = _drop(
559
+ children, (snx.NXoff_geometry, snx.NXevent_data, snx.NXdata, snx.NXlog)
560
+ )
561
+
562
+ children['data'] = data
563
+
518
564
  super().__init__(attrs=attrs, children=children)
519
565
 
520
566
 
@@ -528,7 +574,7 @@ class _DummyField:
528
574
  self.shape = (0,)
529
575
 
530
576
  def __getitem__(self, key: Any) -> sc.Variable:
531
- return sc.empty(dims=self.dims, shape=self.shape, unit=None)
577
+ return sc.zeros(dims=self.dims, shape=self.shape, unit=None, dtype='int32')
532
578
 
533
579
 
534
580
  class _StrippedMonitor(snx.NXmonitor):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: essreduce
3
- Version: 25.11.0
3
+ Version: 25.11.1
4
4
  Summary: Common data reduction tools for the ESS facility
5
5
  Author: Scipp contributors
6
6
  License-Expression: BSD-3-Clause
@@ -17,7 +17,7 @@ ess/reduce/nexus/_nexus_loader.py,sha256=8jN97CbFaSJ6XZEFzkoeAGyol8WpLTUZsHkUWu8
17
17
  ess/reduce/nexus/json_generator.py,sha256=ME2Xn8L7Oi3uHJk9ZZdCRQTRX-OV_wh9-DJn07Alplk,2529
18
18
  ess/reduce/nexus/json_nexus.py,sha256=QrVc0p424nZ5dHX9gebAJppTw6lGZq9404P_OFl1giA,10282
19
19
  ess/reduce/nexus/types.py,sha256=g5oBBEYPH7urF1tDP0tqXtixhQN8JDpe8vmiKrPiUW0,9320
20
- ess/reduce/nexus/workflow.py,sha256=6mgvYW69kBtyhzbfZCi-WzJ3VhcKnx9z2qtXTVXH04E,23169
20
+ ess/reduce/nexus/workflow.py,sha256=nU_YzaRJO5yUGNIHVPScJF_oEddZxaA2gChPF9mMhDQ,25031
21
21
  ess/reduce/scripts/grow_nexus.py,sha256=hET3h06M0xlJd62E3palNLFvJMyNax2kK4XyJcOhl-I,3387
22
22
  ess/reduce/time_of_flight/__init__.py,sha256=Av6Pu_AKO0tF8IsWXchUXjjHps7ts2NFVnui6k3Eq-o,1425
23
23
  ess/reduce/time_of_flight/eto_to_tof.py,sha256=aPPQYbbz_73eq5dQCS97q02D2UUFntOfow2lWkkRyxg,14993
@@ -40,9 +40,9 @@ ess/reduce/widgets/_spinner.py,sha256=2VY4Fhfa7HMXox2O7UbofcdKsYG-AJGrsgGJB85nDX
40
40
  ess/reduce/widgets/_string_widget.py,sha256=iPAdfANyXHf-nkfhgkyH6gQDklia0LebLTmwi3m-iYQ,1482
41
41
  ess/reduce/widgets/_switchable_widget.py,sha256=fjKz99SKLhIF1BLgGVBSKKn3Lu_jYBwDYGeAjbJY3Q8,2390
42
42
  ess/reduce/widgets/_vector_widget.py,sha256=aTaBqCFHZQhrIoX6-sSqFWCPePEW8HQt5kUio8jP1t8,1203
43
- essreduce-25.11.0.dist-info/licenses/LICENSE,sha256=nVEiume4Qj6jMYfSRjHTM2jtJ4FGu0g-5Sdh7osfEYw,1553
44
- essreduce-25.11.0.dist-info/METADATA,sha256=q1TSHnOhJnGdAOulSP-Z-ML81kytiWoqn7PRpMn7wYM,1937
45
- essreduce-25.11.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- essreduce-25.11.0.dist-info/entry_points.txt,sha256=PMZOIYzCifHMTe4pK3HbhxUwxjFaZizYlLD0td4Isb0,66
47
- essreduce-25.11.0.dist-info/top_level.txt,sha256=0JxTCgMKPLKtp14wb1-RKisQPQWX7i96innZNvHBr-s,4
48
- essreduce-25.11.0.dist-info/RECORD,,
43
+ essreduce-25.11.1.dist-info/licenses/LICENSE,sha256=nVEiume4Qj6jMYfSRjHTM2jtJ4FGu0g-5Sdh7osfEYw,1553
44
+ essreduce-25.11.1.dist-info/METADATA,sha256=YJBtrUy0Gw60xZHi0TrmkBhC4XroNNC_CIEL0qRD5z8,1937
45
+ essreduce-25.11.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
+ essreduce-25.11.1.dist-info/entry_points.txt,sha256=PMZOIYzCifHMTe4pK3HbhxUwxjFaZizYlLD0td4Isb0,66
47
+ essreduce-25.11.1.dist-info/top_level.txt,sha256=0JxTCgMKPLKtp14wb1-RKisQPQWX7i96innZNvHBr-s,4
48
+ essreduce-25.11.1.dist-info/RECORD,,