Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion packages/essdiffraction/src/ess/beer/mcstas/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,19 @@ def load_beer_mcstas(
) -> sc.DataArray:
"""Load a detector bank from a BEER McStas file."""
if not isinstance(bank, DetectorBank):
raise ValueError('bank must be either DetectorBank.north or DetectorBank.south')
raise ValueError(
'bank must be ``DetectorBank.north``, '
'``DetectorBank.south``, or ``DetectorBank.both``'
)

if bank == DetectorBank.both:
return sc.concat(
[
load_beer_mcstas(filename, bank)
for bank in (DetectorBank.south, DetectorBank.north)
],
dim='pixel_id',
)

filename = Path(filename)
with mcstastox.Read(filename.parent, filename.name) as data:
Expand Down
1 change: 1 addition & 0 deletions packages/essdiffraction/src/ess/beer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class StreakClusteredData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
class DetectorBank(Enum):
north = 'north'
south = 'south'
both = 'both'


PulseLength = NewType("PulseLength", sc.Variable)
Expand Down
3 changes: 2 additions & 1 deletion packages/essdiffraction/src/ess/beer/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
wavelength_detector,
)
from .mcstas import mcstas_providers
from .types import PulseLength
from .types import DetectorBank, PulseLength

default_parameters = {
CalibrationData: None,
Expand All @@ -37,6 +37,7 @@
'south_detector': {'y': 200, 'x': 500},
'north_detector': {'y': 200, 'x': 500},
},
DetectorBank: DetectorBank.both,
}


Expand Down
11 changes: 11 additions & 0 deletions packages/essdiffraction/tests/beer/mcstas_reduction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ def test_can_load_all_detector_generations(fname, bank):
assert da.bins.size().sum().value > 0


def test_load_both_detector_banks():
filename = mcstas_few_neutrons_3d_detector_example()
north = load_beer_mcstas(filename, DetectorBank.north)
south = load_beer_mcstas(filename, DetectorBank.south)
both = load_beer_mcstas(filename, DetectorBank.both)

assert both.bins.size().sum().value == (
north.bins.size().sum().value + south.bins.size().sum().value
)


def test_loaded_mcstas_event_variances_are_squared_weights():
da = load_beer_mcstas(mcstas_few_neutrons_3d_detector_example(), DetectorBank.north)
weights = da.bins.constituents['data']
Expand Down
Loading