Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion src/ess/dream/io/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
"""

import sciline
import scipp as sc

from ess.reduce.nexus.types import DetectorBankSizes
from ess.reduce.nexus.types import (
DetectorBankSizes,
DetectorData,
Filename,
NeXusDetectorName,
SampleRun,
)
from ess.reduce.nexus.workflow import GenericNeXusWorkflow

DETECTOR_BANK_SIZES = {
Expand Down Expand Up @@ -52,3 +59,48 @@ def LoadNeXusWorkflow() -> sciline.Pipeline:
wf = GenericNeXusWorkflow()
wf[DetectorBankSizes] = DETECTOR_BANK_SIZES
return wf


def load_detector(filename: str, detector_name: str) -> sc.DataArray:
"""
Load a NeXus file.

Parameters
----------
filename:
Path to the NeXus file.
detector_name:
Name of the detector, *excluding* the "_detector" suffix.

Returns
-------
scipp.DataArray
The loaded detector data.
"""
wf = LoadNeXusWorkflow()
wf[Filename[SampleRun]] = filename
wf[NeXusDetectorName] = f'{detector_name}_detector'
return wf.compute(DetectorData[SampleRun])


def load_all_detectors(filename: str) -> dict:
"""
Load all detectors from a NeXus file.

Parameters
----------
filename:
Path to the NeXus file.

Returns
-------
:
DataGroup with the loaded detectors.
"""
wf = LoadNeXusWorkflow()
wf[Filename[SampleRun]] = filename
detectors = sc.DataGroup()
for name in DETECTOR_BANK_SIZES:
wf[NeXusDetectorName] = name
detectors[name.removesuffix('_detector')] = wf.compute(DetectorData[SampleRun])
return detectors