Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience function load_detector and load_all_detector #103

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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