Skip to content

Commit 00aec9e

Browse files
committed
Use custom run and monitor types
1 parent 2e0a96f commit 00aec9e

File tree

8 files changed

+40
-37
lines changed

8 files changed

+40
-37
lines changed

src/ess/dream/io/geant4.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from scippneutron.metadata import ESS_SOURCE
99

1010
from ess.powder.types import (
11-
BackgroundRun,
1211
Beamline,
1312
CalibratedBeamline,
1413
CalibratedDetector,
@@ -18,6 +17,7 @@
1817
CaveMonitor,
1918
CaveMonitorPosition,
2019
DetectorData,
20+
EmptyCanRun,
2121
Filename,
2222
MonitorData,
2323
MonitorFilename,
@@ -321,7 +321,7 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
321321
Workflow for loading NeXus data.
322322
"""
323323
wf = GenericTofWorkflow(
324-
run_types=[SampleRun, VanadiumRun, BackgroundRun], monitor_types=[CaveMonitor]
324+
run_types=[SampleRun, VanadiumRun, EmptyCanRun], monitor_types=[CaveMonitor]
325325
)
326326
wf.insert(extract_geant4_detector)
327327
wf.insert(load_geant4_csv)

src/ess/dream/io/nexus.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515

1616
import sciline
1717

18-
from ess.powder.types import BunkerMonitor, CaveMonitor
18+
from ess.powder.types import (
19+
BunkerMonitor,
20+
CaveMonitor,
21+
EmptyCanRun,
22+
SampleRun,
23+
VanadiumRun,
24+
)
1925
from ess.reduce.nexus.types import DetectorBankSizes, NeXusName
2026
from ess.reduce.nexus.workflow import GenericNeXusWorkflow
2127

@@ -50,7 +56,10 @@ def LoadNeXusWorkflow() -> sciline.Pipeline:
5056
"""
5157
Workflow for loading NeXus data.
5258
"""
53-
wf = GenericNeXusWorkflow()
59+
wf = GenericNeXusWorkflow(
60+
run_types=(SampleRun, VanadiumRun, EmptyCanRun),
61+
monitor_types=(BunkerMonitor, CaveMonitor),
62+
)
5463
wf[DetectorBankSizes] = DETECTOR_BANK_SIZES
5564
wf[NeXusName[BunkerMonitor]] = "monitor_bunker"
5665
wf[NeXusName[CaveMonitor]] = "monitor_cave"

src/ess/dream/parameters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from __future__ import annotations
66

77
from ess.powder.types import (
8-
BackgroundRun,
98
CalibrationFilename,
109
DspacingBins,
10+
EmptyCanRun,
1111
Filename,
1212
IofDspacingTwoTheta,
1313
IofTof,
@@ -36,8 +36,8 @@
3636
parameter_registry[Filename[VanadiumRun]] = FilenameParameter.from_type(
3737
Filename[VanadiumRun]
3838
)
39-
parameter_registry[Filename[BackgroundRun]] = FilenameParameter.from_type(
40-
Filename[BackgroundRun]
39+
parameter_registry[Filename[EmptyCanRun]] = FilenameParameter.from_type(
40+
Filename[EmptyCanRun]
4141
)
4242
parameter_registry[CalibrationFilename] = FilenameParameter.from_type(
4343
CalibrationFilename

src/ess/dream/workflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
)
2121
from ess.powder.types import (
2222
AccumulatedProtonCharge,
23-
BackgroundRun,
2423
CaveMonitorPosition, # Should this be a DREAM-only parameter?
24+
EmptyCanRun,
2525
MonitorType,
2626
PixelMaskFilename,
2727
Position,
@@ -77,13 +77,13 @@ def default_parameters() -> dict:
7777
return {
7878
Position[snx.NXsample, SampleRun]: sample_position,
7979
Position[snx.NXsample, VanadiumRun]: sample_position,
80-
Position[snx.NXsample, BackgroundRun]: sample_position,
80+
Position[snx.NXsample, EmptyCanRun]: sample_position,
8181
Position[snx.NXsource, SampleRun]: source_position,
8282
Position[snx.NXsource, VanadiumRun]: source_position,
83-
Position[snx.NXsource, BackgroundRun]: source_position,
83+
Position[snx.NXsource, EmptyCanRun]: source_position,
8484
AccumulatedProtonCharge[SampleRun]: charge,
8585
AccumulatedProtonCharge[VanadiumRun]: charge,
86-
AccumulatedProtonCharge[BackgroundRun]: charge,
86+
AccumulatedProtonCharge[EmptyCanRun]: charge,
8787
TofMask: None,
8888
WavelengthMask: None,
8989
TwoThetaMask: None,

src/ess/powder/correction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
from ._util import event_or_outer_coord
1313
from .types import (
1414
AccumulatedProtonCharge,
15-
BackgroundRun,
1615
BackgroundSubtractedData,
1716
BackgroundSubtractedDataTwoTheta,
1817
CaveMonitor,
1918
DataWithScatteringCoordinates,
19+
EmptyCanRun,
2020
FocussedDataDspacing,
2121
FocussedDataDspacingTwoTheta,
2222
IofDspacing,
@@ -425,14 +425,14 @@ def _shallow_copy(da: sc.DataArray) -> sc.DataArray:
425425

426426
def subtract_background(
427427
data: FocussedDataDspacing[SampleRun],
428-
background: FocussedDataDspacing[BackgroundRun],
428+
background: FocussedDataDspacing[EmptyCanRun],
429429
) -> BackgroundSubtractedData[SampleRun]:
430430
return BackgroundSubtractedData[SampleRun](data.bins.concatenate(-background))
431431

432432

433433
def subtract_background_two_theta(
434434
data: FocussedDataDspacingTwoTheta[SampleRun],
435-
background: FocussedDataDspacingTwoTheta[BackgroundRun],
435+
background: FocussedDataDspacingTwoTheta[EmptyCanRun],
436436
) -> BackgroundSubtractedDataTwoTheta[SampleRun]:
437437
return BackgroundSubtractedDataTwoTheta[SampleRun](
438438
data.bins.concatenate(-background)

src/ess/powder/types.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,18 @@
2020
from ess.reduce.time_of_flight import types as tof_t
2121
from ess.reduce.uncertainty import UncertaintyBroadcastMode as _UncertaintyBroadcastMode
2222

23-
# 1 TypeVars used to parametrize the generic parts of the workflow
24-
25-
BackgroundRun = reduce_t.BackgroundRun
26-
BunkerMonitor = reduce_t.Monitor2
2723
CalibratedBeamline = reduce_t.CalibratedBeamline
2824
CalibratedDetector = reduce_t.CalibratedDetector
29-
CalibratedBeamline = reduce_t.CalibratedBeamline
3025
CalibratedMonitor = reduce_t.CalibratedMonitor
3126
DetectorData = reduce_t.DetectorData
3227
DetectorPositionOffset = reduce_t.DetectorPositionOffset
33-
EmptyBeamRun = reduce_t.EmptyBeamRun
3428
Filename = reduce_t.Filename
35-
CaveMonitor = reduce_t.Monitor1
3629
MonitorData = reduce_t.MonitorData
3730
MonitorPositionOffset = reduce_t.MonitorPositionOffset
3831
NeXusDetectorName = reduce_t.NeXusDetectorName
3932
NeXusMonitorName = reduce_t.NeXusName
4033
NeXusComponent = reduce_t.NeXusComponent
41-
SampleRun = reduce_t.SampleRun
4234
Position = reduce_t.Position
43-
VanadiumRun = reduce_t.VanadiumRun
4435

4536
DetectorBankSizes = reduce_t.DetectorBankSizes
4637

@@ -58,20 +49,23 @@
5849
TimeOfFlightLookupTableFilename = tof_t.TimeOfFlightLookupTableFilename
5950
SimulationResults = tof_t.SimulationResults
6051

61-
RunType = TypeVar("RunType", SampleRun, VanadiumRun, BackgroundRun)
62-
MonitorType = TypeVar("MonitorType", CaveMonitor, BunkerMonitor)
52+
SampleRun = reduce_t.SampleRun
53+
VanadiumRun = reduce_t.VanadiumRun
54+
EmptyCanRun = NewType("EmptyCanRun", int)
55+
56+
CaveMonitor = reduce_t.CaveMonitor
57+
BunkerMonitor = NewType("BunkerMonitor", int)
6358

59+
RunType = TypeVar("RunType", SampleRun, VanadiumRun, EmptyCanRun)
60+
MonitorType = TypeVar("MonitorType", CaveMonitor, BunkerMonitor)
6461

65-
# 2 Workflow parameters
6662

6763
CalibrationFilename = NewType("CalibrationFilename", str | None)
6864
"""Filename of the instrument calibration file."""
6965

70-
7166
DspacingBins = NewType("DspacingBins", sc.Variable)
7267
"""Bin edges for d-spacing."""
7368

74-
7569
OutFilename = NewType("OutFilename", str)
7670
"""Filename of the output."""
7771

tests/dream/geant4_reduction_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
)
2222
from ess.powder.types import (
2323
AccumulatedProtonCharge,
24-
BackgroundRun,
2524
CalibrationFilename,
2625
CaveMonitorPosition,
2726
CIFAuthors,
2827
DistanceResolution,
2928
DspacingBins,
3029
DspacingData,
30+
EmptyCanRun,
3131
Filename,
3232
IofDspacing,
3333
IofDspacingTwoTheta,
@@ -62,10 +62,10 @@
6262
params = {
6363
Filename[SampleRun]: dream.data.simulated_diamond_sample(small=True),
6464
Filename[VanadiumRun]: dream.data.simulated_vanadium_sample(small=True),
65-
Filename[BackgroundRun]: dream.data.simulated_empty_can(small=True),
65+
Filename[EmptyCanRun]: dream.data.simulated_empty_can(small=True),
6666
MonitorFilename[SampleRun]: dream.data.simulated_monitor_diamond_sample(),
6767
MonitorFilename[VanadiumRun]: dream.data.simulated_monitor_vanadium_sample(),
68-
MonitorFilename[BackgroundRun]: dream.data.simulated_monitor_empty_can(),
68+
MonitorFilename[EmptyCanRun]: dream.data.simulated_monitor_empty_can(),
6969
dream.InstrumentConfiguration: dream.beamline.InstrumentConfiguration.high_flux,
7070
CalibrationFilename: None,
7171
UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,
@@ -126,8 +126,8 @@ def test_pipeline_can_compute_dspacing_result(workflow):
126126

127127

128128
def test_pipeline_can_compute_dspacing_result_without_empty_can(workflow_no_empy_can):
129-
workflow_no_empy_can[Filename[BackgroundRun]] = None
130-
workflow_no_empy_can[MonitorFilename[BackgroundRun]] = None
129+
workflow_no_empy_can[Filename[EmptyCanRun]] = None
130+
workflow_no_empy_can[MonitorFilename[EmptyCanRun]] = None
131131
workflow_no_empy_can = powder.with_pixel_mask_filenames(workflow_no_empy_can, [])
132132
result = workflow_no_empy_can.compute(IofDspacing)
133133
assert result.sizes == {'dspacing': len(params[DspacingBins]) - 1}
@@ -333,4 +333,4 @@ def test_dream_workflow_parameters_returns_filtered_params():
333333
wf = DreamGeant4ProtonChargeWorkflow()
334334
parameters = reduce_workflow.get_parameters(wf, (DspacingData[SampleRun],))
335335
assert Filename[SampleRun] in parameters
336-
assert Filename[BackgroundRun] not in parameters
336+
assert Filename[EmptyCanRun] not in parameters

tests/dream/io/nexus_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
from ess.reduce.nexus.types import (
1010
CalibratedDetector,
1111
CalibratedMonitor,
12+
CaveMonitor,
1213
DetectorBankSizes,
1314
DetectorData,
1415
Filename,
15-
Monitor1,
1616
NeXusDetectorName,
1717
SampleRun,
1818
)
@@ -95,8 +95,8 @@ def test_can_load_nexus_monitor_data(nexus_workflow):
9595
nexus_workflow[Filename[SampleRun]] = dream.data.get_path(
9696
'TEST_DREAM_nexus_sorted-2023-12-07.nxs'
9797
)
98-
nexus_workflow[NeXusMonitorName[Monitor1]] = 'monitor_cave'
99-
result = nexus_workflow.compute(CalibratedMonitor[SampleRun, Monitor1])
98+
nexus_workflow[NeXusMonitorName[CaveMonitor]] = 'monitor_cave'
99+
result = nexus_workflow.compute(CalibratedMonitor[SampleRun, CaveMonitor])
100100
assert result.sizes == {'event_time_zero': 0}
101101

102102

0 commit comments

Comments
 (0)