Skip to content

Commit 625a184

Browse files
authored
Merge pull request #136 from scipp/instr-config-for-lookup
Use instrument configuration to find time-of-flight lookup table
2 parents ce8629b + 535fb24 commit 625a184

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

docs/user-guide/dream/dream-data-reduction.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
"workflow[WavelengthMask] = None\n",
7777
"# No pixel masks\n",
7878
"workflow = powder.with_pixel_mask_filenames(workflow, [])\n",
79-
"# Time-of-flight lookup table\n",
80-
"workflow[TimeOfFlightLookupTableFilename] = dream.data.tof_lookup_table_high_flux()"
79+
"# Select instrument chopper configuration\n",
80+
"workflow[dream.InstrumentConfiguration] = dream.InstrumentConfiguration.high_flux"
8181
]
8282
},
8383
{
@@ -303,7 +303,7 @@
303303
"workflow[TwoThetaMask] = None\n",
304304
"workflow[WavelengthMask] = None\n",
305305
"workflow = powder.with_pixel_mask_filenames(workflow, [])\n",
306-
"workflow[TimeOfFlightLookupTableFilename] = dream.data.tof_lookup_table_high_flux()"
306+
"workflow[dream.InstrumentConfiguration] = dream.InstrumentConfiguration.high_flux"
307307
]
308308
},
309309
{

docs/user-guide/dream/workflow-widget-dream.ipynb

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
},
4848
"outputs": [],
4949
"source": [
50-
"from ess.powder.types import DspacingBins, Filename, SampleRun, TimeOfFlightLookupTableFilename, VanadiumRun\n",
50+
"from ess.powder.types import DspacingBins, Filename, SampleRun, VanadiumRun\n",
5151
"import ess.dream.data # noqa: F401\n",
52+
"from ess.dream import InstrumentConfiguration\n",
5253
"\n",
5354
"select = widget.children[0].children[0]\n",
5455
"keys, values = zip(*select.options, strict=True)\n",
@@ -66,7 +67,7 @@
6667
"# Set parameters\n",
6768
"pbox._input_widgets[Filename[SampleRun]].children[0].value = dream.data.simulated_diamond_sample()\n",
6869
"pbox._input_widgets[Filename[VanadiumRun]].children[0].value = dream.data.simulated_vanadium_sample()\n",
69-
"pbox._input_widgets[TimeOfFlightLookupTableFilename].children[0].value = dream.data.tof_lookup_table_high_flux()\n",
70+
"pbox._input_widgets[InstrumentConfiguration].value = InstrumentConfiguration.high_flux\n",
7071
"pbox._input_widgets[DspacingBins].fields[\"stop\"].value = 2.3434\n",
7172
"# Run the workflow\n",
7273
"rbox = wfw.result_box\n",

src/ess/dream/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import importlib.metadata
99

10-
from . import beamline
10+
from .beamline import InstrumentConfiguration
1111
from .instrument_view import instrument_view
1212
from .io import load_geant4_csv, nexus
1313
from .workflow import DreamGeant4Workflow, default_parameters
@@ -21,8 +21,8 @@
2121

2222
__all__ = [
2323
'DreamGeant4Workflow',
24+
'InstrumentConfiguration',
2425
'__version__',
25-
'beamline',
2626
'default_parameters',
2727
'instrument_view',
2828
'load_geant4_csv',

src/ess/dream/parameters.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
PixelMaskFilename,
1717
ReducedTofCIF,
1818
SampleRun,
19-
TimeOfFlightLookupTableFilename,
2019
UncertaintyBroadcastMode,
2120
VanadiumRun,
2221
)
@@ -29,6 +28,8 @@
2928
parameter_registry,
3029
)
3130

31+
from .beamline import InstrumentConfiguration
32+
3233
parameter_registry[Filename[SampleRun]] = FilenameParameter.from_type(
3334
Filename[SampleRun]
3435
)
@@ -41,8 +42,8 @@
4142
parameter_registry[CalibrationFilename] = FilenameParameter.from_type(
4243
CalibrationFilename
4344
)
44-
parameter_registry[TimeOfFlightLookupTableFilename] = FilenameParameter.from_type(
45-
TimeOfFlightLookupTableFilename
45+
parameter_registry[InstrumentConfiguration] = ParamWithOptions.from_enum(
46+
InstrumentConfiguration, default=InstrumentConfiguration.high_flux
4647
)
4748
parameter_registry[MonitorFilename[SampleRun]] = FilenameParameter.from_type(
4849
MonitorFilename[SampleRun]

src/ess/dream/workflow.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Position,
2424
ReducerSoftwares,
2525
SampleRun,
26+
TimeOfFlightLookupTableFilename,
2627
TofMask,
2728
TwoThetaMask,
2829
VanadiumRun,
@@ -32,11 +33,30 @@
3233
from ess.reduce.parameter import parameter_mappers
3334
from ess.reduce.workflow import register_workflow
3435

36+
from .beamline import InstrumentConfiguration
3537
from .io.cif import CIFAuthors, prepare_reduced_tof_cif
3638
from .io.geant4 import LoadGeant4Workflow
3739
from .parameters import typical_outputs
3840

39-
_dream_providers = (prepare_reduced_tof_cif,)
41+
42+
def _get_lookup_table_filename_from_configuration(
43+
configuration: InstrumentConfiguration,
44+
) -> TimeOfFlightLookupTableFilename:
45+
from .data import tof_lookup_table_high_flux
46+
47+
match configuration:
48+
case InstrumentConfiguration.high_flux:
49+
out = tof_lookup_table_high_flux()
50+
case InstrumentConfiguration.high_resolution:
51+
raise NotImplementedError("High resolution configuration not yet supported")
52+
53+
return TimeOfFlightLookupTableFilename(out)
54+
55+
56+
_dream_providers = (
57+
prepare_reduced_tof_cif,
58+
_get_lookup_table_filename_from_configuration,
59+
)
4060

4161
parameter_mappers[PixelMaskFilename] = with_pixel_mask_filenames
4262

tests/dream/geant4_reduction_test.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
MonitorFilename[SampleRun]: dream.data.simulated_monitor_diamond_sample(),
6565
MonitorFilename[VanadiumRun]: dream.data.simulated_monitor_vanadium_sample(),
6666
MonitorFilename[BackgroundRun]: dream.data.simulated_monitor_empty_can(),
67-
TimeOfFlightLookupTableFilename: dream.data.tof_lookup_table_high_flux(),
67+
dream.InstrumentConfiguration: dream.beamline.InstrumentConfiguration.high_flux,
6868
CalibrationFilename: None,
6969
UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,
7070
DspacingBins: sc.linspace('dspacing', 0.0, 2.3434, 201, unit='angstrom'),
@@ -117,6 +117,14 @@ def test_pipeline_can_compute_dspacing_result(workflow):
117117
assert sc.identical(result.coords['dspacing'], params[DspacingBins])
118118

119119

120+
def test_pipeline_can_compute_dspacing_result_using_lookup_table_filename(workflow):
121+
workflow = powder.with_pixel_mask_filenames(workflow, [])
122+
workflow[TimeOfFlightLookupTableFilename] = dream.data.tof_lookup_table_high_flux()
123+
result = workflow.compute(IofDspacing)
124+
assert result.sizes == {'dspacing': len(params[DspacingBins]) - 1}
125+
assert sc.identical(result.coords['dspacing'], params[DspacingBins])
126+
127+
120128
@pytest.fixture(scope="module")
121129
def simulation_dream_choppers():
122130
return time_of_flight.simulate_beamline(

0 commit comments

Comments
 (0)