Skip to content

Commit

Permalink
Extract folding into helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Dec 7, 2023
1 parent 5d4a655 commit 0e955a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ess/dream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import importlib.metadata

from . import data
from .io import load_nexus
from .io import fold_nexus_detectors, load_nexus

try:
__version__ = importlib.metadata.version(__package__ or __name__)
Expand All @@ -18,5 +18,6 @@

__all__ = [
"data",
"fold_nexus_detectors",
"load_nexus",
]
15 changes: 13 additions & 2 deletions src/ess/dream/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,19 @@ def load_nexus(
with snx.File(path, definitions=definitions) as f:
dg = f[entry][()]
dg = snx.compute_positions(dg)
if not fold_detectors:
return dg
return fold_nexus_detectors(dg) if fold_detectors else dg


def fold_nexus_detectors(dg: sc.DataGroup) -> sc.DataGroup:
"""
Fold the detector data in a DREAM NeXus file.
The detector banks in the returned data group will have a multi-dimensional shape,
following the logical structure as far as possible. Note that the full structure
cannot be folded, as some dimensions are irregular.
"""
dg = dg.copy()
dg['instrument'] = dg['instrument'].copy()
instrument = dg['instrument']
mantle = instrument['mantle_detector']
mantle['mantle_event_data'] = mantle['mantle_event_data'].fold(
Expand Down

0 comments on commit 0e955a8

Please sign in to comment.