Workflow widgets example#

This notebook illustrates how we can use ESSreduce’s workflow widgets to generate a graphical interface for running the LoKI tutorial workflow.

Initializing the GUI#

It is as simple as importing the dream submodule and generating a GUI using workflow_widget (the workflow automatically registers itself to a library of workflows when imported).

[1]:
# Import dream submodule to register workflow
from ess import dream
from ess.reduce import ui

# Prepare a container for accessing the results computed by the GUI
results = {}

# Initialize the GUI widget
widget = ui.workflow_widget(result_registry=results)
widget
[1]:
[2]:
from ess.powder.types import DspacingBins, Filename, SampleRun, VanadiumRun
import ess.dream.data  # noqa: F401

select = widget.children[0].children[0]
keys, values = zip(*select.options, strict=True)
ind = keys.index("DreamGeant4ProtonChargeWorkflow")
select.value = values[ind]
# Select IofDspacing output
wfw = widget.children[1].children[0]
outputs = wfw.output_selection_box.typical_outputs_widget
keys, values = zip(*outputs.options, strict=True)
ind = keys.index("IofTof")
outputs.value = (values[ind],)
# Refresh parameters
pbox = wfw.parameter_box
pbox.parameter_refresh_button.click()
# Set parameters
pbox._input_widgets[Filename[SampleRun]].children[0].value = dream.data.simulated_diamond_sample()
pbox._input_widgets[Filename[VanadiumRun]].children[0].value = dream.data.simulated_vanadium_sample()
pbox._input_widgets[DspacingBins].children[0].fields["stop"].value = 2.3434
# Run the workflow
rbox = wfw.result_box
rbox.run_button.click()

Accessing the results#

We can now access the computed result in the results dictionary:

[3]:
results
[3]:
{ess.powder.types.IofTof: <scipp.DataArray>
 Dimensions: Sizes[tof:200, ]
 Coordinates:
 * gravity                   vector3          [m/s^2]  ()  (0, -9.80665, 0)
   sample_position           vector3             [mm]  ()  (0, 0, 0)
   source_position           vector3             [mm]  ()  (-3.478, 0, -76550)
 * tof                       float64            [µs]  (tof [bin-edge])  [0, 332.591, ..., 66185.6, 66518.2]
 Data:
                           DataArrayView        <no unit>  (tof)  binned data: dim='event', content=DataArray(
           dims=(event: 1278620),
           data=float64[dimensionless],
           coords={'tof':float64[µs]})
 }

The result can be plotted using

[4]:
(da,) = results.values()
da.hist(tof=200).plot()
[4]:
../../_images/user-guide_dream_workflow-widget-dream_6_0.svg