|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Workflow widgets example\n", |
| 9 | + "\n", |
| 10 | + "This notebook illustrates how we can use ESSreduce’s [workflow widgets](https://scipp.github.io/essreduce/user-guide/widget.html) to generate a graphical interface for running the LoKI tutorial workflow.\n", |
| 11 | + "\n", |
| 12 | + "## Initializing the GUI\n", |
| 13 | + "\n", |
| 14 | + "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)." |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "code", |
| 19 | + "execution_count": null, |
| 20 | + "id": "1", |
| 21 | + "metadata": {}, |
| 22 | + "outputs": [], |
| 23 | + "source": [ |
| 24 | + "# Import dream submodule to register workflow\n", |
| 25 | + "from ess import dream\n", |
| 26 | + "from ess.reduce import ui\n", |
| 27 | + "\n", |
| 28 | + "# Prepare a container for accessing the results computed by the GUI\n", |
| 29 | + "results = {}\n", |
| 30 | + "\n", |
| 31 | + "# Initialize the GUI widget\n", |
| 32 | + "widget = ui.workflow_widget(result_registry=results)\n", |
| 33 | + "widget" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": null, |
| 39 | + "id": "2", |
| 40 | + "metadata": { |
| 41 | + "editable": true, |
| 42 | + "slideshow": { |
| 43 | + "slide_type": "" |
| 44 | + }, |
| 45 | + "tags": [] |
| 46 | + }, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "from ess.powder.types import DspacingBins, Filename, SampleRun, VanadiumRun\n", |
| 50 | + "import ess.dream.data # noqa: F401\n", |
| 51 | + "\n", |
| 52 | + "select = widget.children[0].children[0]\n", |
| 53 | + "keys, values = zip(*select.options, strict=True)\n", |
| 54 | + "ind = keys.index(\"DreamGeant4ProtonChargeWorkflow\")\n", |
| 55 | + "select.value = values[ind]\n", |
| 56 | + "# Select IofDspacing output\n", |
| 57 | + "wfw = widget.children[1].children[0]\n", |
| 58 | + "outputs = wfw.output_selection_box.typical_outputs_widget\n", |
| 59 | + "keys, values = zip(*outputs.options, strict=True)\n", |
| 60 | + "ind = keys.index(\"IofTof\")\n", |
| 61 | + "outputs.value = (values[ind],)\n", |
| 62 | + "# Refresh parameters\n", |
| 63 | + "pbox = wfw.parameter_box\n", |
| 64 | + "pbox.parameter_refresh_button.click()\n", |
| 65 | + "# Set parameters\n", |
| 66 | + "pbox._input_widgets[Filename[SampleRun]].children[0].value = dream.data.simulated_diamond_sample()\n", |
| 67 | + "pbox._input_widgets[Filename[VanadiumRun]].children[0].value = dream.data.simulated_vanadium_sample()\n", |
| 68 | + "pbox._input_widgets[DspacingBins].children[0].fields[\"stop\"].value = 2.3434\n", |
| 69 | + "# Run the workflow\n", |
| 70 | + "rbox = wfw.result_box\n", |
| 71 | + "rbox.run_button.click()" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "markdown", |
| 76 | + "id": "3", |
| 77 | + "metadata": { |
| 78 | + "editable": true, |
| 79 | + "slideshow": { |
| 80 | + "slide_type": "" |
| 81 | + }, |
| 82 | + "tags": [] |
| 83 | + }, |
| 84 | + "source": [ |
| 85 | + "## Accessing the results\n", |
| 86 | + "\n", |
| 87 | + "We can now access the computed result in the `results` dictionary:" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "code", |
| 92 | + "execution_count": null, |
| 93 | + "id": "4", |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "results" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "id": "5", |
| 103 | + "metadata": {}, |
| 104 | + "source": [ |
| 105 | + "The result can be plotted using" |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": null, |
| 111 | + "id": "6", |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "(da,) = results.values()\n", |
| 116 | + "da.hist(tof=200).plot()" |
| 117 | + ] |
| 118 | + } |
| 119 | + ], |
| 120 | + "metadata": { |
| 121 | + "kernelspec": { |
| 122 | + "display_name": "Python 3 (ipykernel)", |
| 123 | + "language": "python", |
| 124 | + "name": "python3" |
| 125 | + }, |
| 126 | + "language_info": { |
| 127 | + "codemirror_mode": { |
| 128 | + "name": "ipython", |
| 129 | + "version": 3 |
| 130 | + }, |
| 131 | + "file_extension": ".py", |
| 132 | + "mimetype": "text/x-python", |
| 133 | + "name": "python", |
| 134 | + "nbconvert_exporter": "python", |
| 135 | + "pygments_lexer": "ipython3" |
| 136 | + } |
| 137 | + }, |
| 138 | + "nbformat": 4, |
| 139 | + "nbformat_minor": 5 |
| 140 | +} |
0 commit comments