essreduce 25.10.1__py3-none-any.whl → 25.10.2__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.
@@ -20,6 +20,8 @@ from ._nexus_loader import (
20
20
  load_all_components,
21
21
  load_component,
22
22
  load_data,
23
+ open_component_group,
24
+ open_nexus_file,
23
25
  )
24
26
  from .workflow import GenericNeXusWorkflow
25
27
 
@@ -31,5 +33,7 @@ __all__ = [
31
33
  'load_all_components',
32
34
  'load_component',
33
35
  'load_data',
36
+ 'open_component_group',
37
+ 'open_nexus_file',
34
38
  'types',
35
39
  ]
@@ -46,17 +46,37 @@ def load_component(
46
46
  location: NeXusLocationSpec,
47
47
  *,
48
48
  nx_class: type[snx.NXobject],
49
+ parent_class: type[snx.NXobject] | None = None,
49
50
  definitions: Mapping | None | NoNewDefinitionsType = NoNewDefinitions,
50
51
  ) -> sc.DataGroup:
51
- """Load a single component of a given class from NeXus."""
52
+ """Load a single component of a given class from NeXus.
53
+
54
+ Parameters
55
+ ----------
56
+ location:
57
+ Specifies (part of) the location of the component to load.
58
+ nx_class:
59
+ NeXus class of the component to load.
60
+ parent_class:
61
+ NeXus class of the parent of the component to load.
62
+ If ``None``, is deduced from ``nx_class`` if possible.
63
+ definitions:
64
+ Application definitions to use for the file.
65
+
66
+ Returns
67
+ -------
68
+ :
69
+ The loaded component as a data group.
70
+ """
52
71
  selection = location.selection
53
- group_name = location.component_name
54
- with _open_component_parent(
55
- location, nx_class=nx_class, definitions=definitions
56
- ) as parent:
57
- component = _unique_child_group(parent, nx_class, group_name)
58
- loaded = cast(sc.DataGroup, component[selection])
59
- loaded['nexus_component_name'] = component.name.rsplit('/', 1)[-1]
72
+ with open_component_group(
73
+ location,
74
+ nx_class=nx_class,
75
+ parent_class=parent_class,
76
+ definitions=definitions,
77
+ ) as group:
78
+ loaded = cast(sc.DataGroup, group[selection])
79
+ loaded['nexus_component_name'] = group.name.rsplit('/', 1)[-1]
60
80
  return loaded
61
81
 
62
82
 
@@ -64,11 +84,14 @@ def load_all_components(
64
84
  location: NeXusAllLocationSpec,
65
85
  *,
66
86
  nx_class: type[snx.NXobject],
87
+ parent_class: type[snx.NXobject] | None = None,
67
88
  definitions: Mapping | None | NoNewDefinitionsType = NoNewDefinitions,
68
89
  ) -> sc.DataGroup:
69
90
  """Load all components of a given class from NeXus."""
70
91
  with _open_component_parent(
71
- location, nx_class=nx_class, definitions=definitions
92
+ location,
93
+ parent_class=_deduce_component_parent_class(nx_class, parent_class),
94
+ definitions=definitions,
72
95
  ) as parent:
73
96
  components = sc.DataGroup()
74
97
  for name, component in parent[nx_class].items():
@@ -119,6 +142,29 @@ def open_nexus_file(
119
142
  *,
120
143
  locking: bool | str | None | NoLockingIfNeededType = NoLockingIfNeeded,
121
144
  ) -> AbstractContextManager[snx.Group]:
145
+ """Open a NeXus file.
146
+
147
+ Parameters
148
+ ----------
149
+ file_path:
150
+ Path of the file to open or a NeXus file or group handle.
151
+ definitions:
152
+ If set, application definitions to use for the file.
153
+ If ``file_path`` is a NeXus file or group, this must be unset or match
154
+ the existing definitions.
155
+ locking:
156
+ This is an advanced feature to work around a limitation of the DMSC file system.
157
+ It may be removed in the future.
158
+
159
+ This flag can disable or force locking the HDF5 file.
160
+ By default, the file is locked if possible but may remain unlocked
161
+ if it is on a read-only filesystem.
162
+
163
+ Returns
164
+ -------
165
+ :
166
+ A context manager for the opened file.
167
+ """
122
168
  if isinstance(file_path, getattr(NeXusGroup, '__supertype__', type(None))):
123
169
  if (
124
170
  definitions is not NoNewDefinitions
@@ -203,10 +249,46 @@ def _open_nexus_file_from_path(
203
249
 
204
250
 
205
251
  @contextmanager
206
- def _open_component_parent(
252
+ def open_component_group(
207
253
  location: NeXusLocationSpec,
208
254
  *,
209
255
  nx_class: type[snx.NXobject],
256
+ parent_class: type[snx.NXobject] | None = None,
257
+ definitions: Mapping | None | NoNewDefinitionsType = NoNewDefinitions,
258
+ ) -> Generator[snx.Group, None, None]:
259
+ """Open the HDF5 group of a NeXus component.
260
+
261
+ Parameters
262
+ ----------
263
+ location:
264
+ Specifies (part of) the location of the component to load.
265
+ nx_class:
266
+ NeXus class of the component to load.
267
+ parent_class:
268
+ NeXus class of the parent of the component to load.
269
+ If ``None``, is deduced from ``nx_class`` if possible.
270
+ definitions:
271
+ Application definitions to use for the file.
272
+
273
+ Returns
274
+ -------
275
+ :
276
+ A context manager for the group of the specified component.
277
+ """
278
+ group_name = location.component_name
279
+ with _open_component_parent(
280
+ location,
281
+ parent_class=_deduce_component_parent_class(nx_class, parent_class),
282
+ definitions=definitions,
283
+ ) as parent:
284
+ yield _unique_child_group(parent, nx_class, group_name)
285
+
286
+
287
+ @contextmanager
288
+ def _open_component_parent(
289
+ location: NeXusLocationSpec,
290
+ *,
291
+ parent_class: type[snx.NXobject],
210
292
  definitions: Mapping | None | NoNewDefinitionsType = NoNewDefinitions,
211
293
  ) -> Generator[snx.Group, None, None]:
212
294
  """Locate the parent group of a NeXus component."""
@@ -214,10 +296,30 @@ def _open_component_parent(
214
296
  entry_name = location.entry_name
215
297
  with open_nexus_file(file_path, definitions=definitions) as f:
216
298
  entry = _unique_child_group(f, snx.NXentry, entry_name)
217
- if nx_class is snx.NXsample:
218
- yield entry
219
- else:
220
- yield _unique_child_group(entry, snx.NXinstrument, None)
299
+ match parent_class:
300
+ case snx.NXentry:
301
+ yield entry
302
+ case snx.NXinstrument:
303
+ yield _unique_child_group(entry, snx.NXinstrument, None)
304
+ case _:
305
+ raise NotImplementedError(
306
+ f"No support for loading a NeXus component from a {parent_class}."
307
+ )
308
+
309
+
310
+ def _deduce_component_parent_class(
311
+ nx_class: type[snx.NXobject], parent_class: type[snx.NXobject] | None
312
+ ) -> type[snx.NXobject]:
313
+ if parent_class is not None:
314
+ return parent_class
315
+
316
+ match nx_class:
317
+ case snx.NXsample:
318
+ return snx.NXentry
319
+ case _:
320
+ # Most components are in the instrument,
321
+ # callers need to override this for specialized components stored elsewhere.
322
+ return snx.NXinstrument
221
323
 
222
324
 
223
325
  def _unique_child_group(
@@ -367,6 +469,9 @@ def load_data(
367
469
  elif _contains_nx_class(component, snx.NXdata):
368
470
  data = _unique_child_group(component, snx.NXdata, None)
369
471
  sel = _to_snx_selection(selection, for_events=False)
472
+ elif _contains_nx_class(component, snx.NXlog):
473
+ data = _unique_child_group(component, snx.NXlog, "data")
474
+ sel = _to_snx_selection(selection, for_events=False)
370
475
  else:
371
476
  raise ValueError(
372
477
  f"NeXus group '{component.name}' contains neither "
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: essreduce
3
- Version: 25.10.1
3
+ Version: 25.10.2
4
4
  Summary: Common data reduction tools for the ESS facility
5
5
  Author: Scipp contributors
6
6
  License-Expression: BSD-3-Clause
@@ -23,7 +23,7 @@ License-File: LICENSE
23
23
  Requires-Dist: sciline>=25.05.1
24
24
  Requires-Dist: scipp>=25.04.0
25
25
  Requires-Dist: scippneutron>=25.02.0
26
- Requires-Dist: scippnexus>=24.11.0
26
+ Requires-Dist: scippnexus>=25.06.0
27
27
  Provides-Extra: test
28
28
  Requires-Dist: ipywidgets>=8.1; extra == "test"
29
29
  Requires-Dist: numba>=0.59; extra == "test"
@@ -12,8 +12,8 @@ ess/reduce/live/__init__.py,sha256=jPQVhihRVNtEDrE20PoKkclKV2aBF1lS7cCHootgFgI,2
12
12
  ess/reduce/live/raw.py,sha256=66qV0G2rP8gK5tXuk-syTlDLE2jT3ehfmSnET7Xzfd0,24392
13
13
  ess/reduce/live/roi.py,sha256=Hs-pW98k41WU6Kl3UQ41kQawk80c2QNOQ_WNctLzDPE,3795
14
14
  ess/reduce/live/workflow.py,sha256=bsbwvTqPhRO6mC__3b7MgU7DWwAnOvGvG-t2n22EKq8,4285
15
- ess/reduce/nexus/__init__.py,sha256=59bxKkNYg8DYcSykNvH6nCa5SYchJC4SbgZEKhkNdYc,967
16
- ess/reduce/nexus/_nexus_loader.py,sha256=5N48AMJx1AaFZb6WZPPbVKUlXyFMVVtZrn7Bae57O3A,19842
15
+ ess/reduce/nexus/__init__.py,sha256=8TLqqALxRV5_QdCwLAjq3r6xneq6rzdh2dD7d9AXkYo,1065
16
+ ess/reduce/nexus/_nexus_loader.py,sha256=8jN97CbFaSJ6XZEFzkoeAGyol8WpLTUZsHkUWu8WHsU,23136
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=DE82JnbgpTlQnt7UN2a2Gur2N9QupV3CDL9j4Iy4lsE,9178
@@ -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.10.1.dist-info/licenses/LICENSE,sha256=nVEiume4Qj6jMYfSRjHTM2jtJ4FGu0g-5Sdh7osfEYw,1553
44
- essreduce-25.10.1.dist-info/METADATA,sha256=D1WNeIQ0DFiU74eL34et9ndrzzPZODUNqbwcj_D1Yzg,1937
45
- essreduce-25.10.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
- essreduce-25.10.1.dist-info/entry_points.txt,sha256=PMZOIYzCifHMTe4pK3HbhxUwxjFaZizYlLD0td4Isb0,66
47
- essreduce-25.10.1.dist-info/top_level.txt,sha256=0JxTCgMKPLKtp14wb1-RKisQPQWX7i96innZNvHBr-s,4
48
- essreduce-25.10.1.dist-info/RECORD,,
43
+ essreduce-25.10.2.dist-info/licenses/LICENSE,sha256=nVEiume4Qj6jMYfSRjHTM2jtJ4FGu0g-5Sdh7osfEYw,1553
44
+ essreduce-25.10.2.dist-info/METADATA,sha256=vCh-Way6GMm-vMBIAIDbApKC17IIgAiWc1KKI43iPj0,1937
45
+ essreduce-25.10.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
+ essreduce-25.10.2.dist-info/entry_points.txt,sha256=PMZOIYzCifHMTe4pK3HbhxUwxjFaZizYlLD0td4Isb0,66
47
+ essreduce-25.10.2.dist-info/top_level.txt,sha256=0JxTCgMKPLKtp14wb1-RKisQPQWX7i96innZNvHBr-s,4
48
+ essreduce-25.10.2.dist-info/RECORD,,