Skip to content

Commit ef9e639

Browse files
committed
Use dedicated types for AllComponent specs
1 parent 5622473 commit ef9e639

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

src/ess/reduce/nexus/_nexus_loader.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
import scippnexus as snx
1414

1515
from ..logging import get_logger
16-
from .types import FilePath, NeXusEntryName, NeXusFile, NeXusGroup, NeXusLocationSpec
16+
from .types import (
17+
FilePath,
18+
NeXusAllLocationSpec,
19+
NeXusEntryName,
20+
NeXusFile,
21+
NeXusGroup,
22+
NeXusLocationSpec,
23+
)
1724

1825

1926
class NoNewDefinitionsType: ...
@@ -41,17 +48,12 @@ def load_component(
4148

4249

4350
def load_all_components(
44-
location: NeXusLocationSpec,
51+
location: NeXusAllLocationSpec,
4552
*,
4653
nx_class: type[snx.NXobject],
4754
definitions: Mapping | None | NoNewDefinitionsType = NoNewDefinitions,
4855
) -> sc.DataGroup:
4956
"""Load all components of a given class from NeXus."""
50-
if location.component_name is not None:
51-
raise ValueError(
52-
"`location.component_name` must be None when loading all "
53-
"components of a certain class."
54-
)
5557
with _open_component_parent(
5658
location, nx_class=nx_class, definitions=definitions
5759
) as parent:

src/ess/reduce/nexus/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,24 @@ class NeXusComponentLocationSpec(NeXusLocationSpec, Generic[Component, RunType])
230230
"""
231231

232232

233+
@dataclass
234+
class NeXusAllLocationSpec:
235+
"""
236+
NeXus parameters to identify all components of a class to load.
237+
"""
238+
239+
filename: FilePath | NeXusFile | NeXusGroup
240+
entry_name: NeXusEntryName | None = None
241+
selection: snx.typing.ScippIndex | slice = ()
242+
243+
244+
@dataclass
245+
class NeXusAllComponentLocationSpec(NeXusAllLocationSpec, Generic[Component, RunType]):
246+
"""
247+
NeXus parameters to identify all components of a class to load.
248+
"""
249+
250+
233251
@dataclass
234252
class NeXusDataLocationSpec(NeXusLocationSpec, Generic[Component, RunType]):
235253
"""NeXus filename and parameters to identify (parts of) detector data to load."""

src/ess/reduce/nexus/workflow.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MonitorData,
3333
MonitorPositionOffset,
3434
MonitorType,
35+
NeXusAllComponentLocationSpec,
3536
NeXusClass,
3637
NeXusComponent,
3738
NeXusComponentLocationSpec,
@@ -100,20 +101,11 @@ def component_spec_by_name(
100101
)
101102

102103

103-
def disk_chopper_component_spec(
104+
def all_component_spec(
104105
filename: NeXusFileSpec[RunType],
105-
) -> NeXusComponentLocationSpec[snx.NXdisk_chopper, RunType]:
106-
"""Create a location spec for a disk chopper group in a NeXus file."""
107-
return NeXusComponentLocationSpec[snx.NXdisk_chopper, RunType](
108-
filename=filename.value
109-
)
110-
111-
112-
def crystal_component_spec(
113-
filename: NeXusFileSpec[RunType],
114-
) -> NeXusComponentLocationSpec[snx.NXcrystal, RunType]:
115-
"""Create a location spec for a crystal / analyzer group in a NeXus file."""
116-
return NeXusComponentLocationSpec[snx.NXcrystal, RunType](filename=filename.value)
106+
) -> NeXusAllComponentLocationSpec[Component, RunType]:
107+
"""Create a location spec for all components of a class in a NeXus file."""
108+
return NeXusAllComponentLocationSpec[Component, RunType](filename=filename.value)
117109

118110

119111
def unique_component_spec(
@@ -235,7 +227,7 @@ def load_nexus_component(
235227

236228

237229
def load_all_nexus_components(
238-
location: NeXusComponentLocationSpec[Component, RunType],
230+
location: NeXusAllComponentLocationSpec[Component, RunType],
239231
nx_class: NeXusClass[Component],
240232
) -> AllNeXusComponents[Component, RunType]:
241233
"""
@@ -604,9 +596,8 @@ def _add_variances(da: sc.DataArray) -> sc.DataArray:
604596
file_path_to_file_spec,
605597
full_time_interval,
606598
component_spec_by_name,
607-
disk_chopper_component_spec,
608-
crystal_component_spec,
609599
unique_component_spec, # after component_spec_by_name, partially overrides
600+
all_component_spec,
610601
get_transformation_chain,
611602
to_transformation,
612603
compute_position,

0 commit comments

Comments
 (0)