Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Open
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
165 changes: 165 additions & 0 deletions sans/CreateConvertPlotExample.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data manpulation widgets toy examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from example_widgets import ProcessWidget, PlotWidget, fake_load, setup_code_hiding, allowed_dimensions, filepath_converter\n",
"import scipp as sc\n",
"import functools\n",
"\n",
"# Workaround for the fact that you can't raise directly in tertiary expressions.\n",
"def raise_(ex):\n",
" raise ex\n",
"\n",
"setup_code_hiding()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plot_widget = PlotWidget(globals())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data Loading\n",
"Currently creates some example data rather than loading a file. The created file is a histogrammed time of flight data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data_creation = ProcessWidget(globals(), fake_load, 'Load', {'filepath': filepath_converter}, {'filepath': 'run number or file name'})\n",
"data_creation.subscribe(plot_widget)\n",
"data_creation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data conversion\n",
"This converts one physical dimension to another the current conversions support in scipp.neutron are:\n",
"* tof -> dspacing, wavelength, E\n",
"* d-spacing -> tof\n",
"* wavelength -> Q, tof\n",
"* E -> tof\n",
"* Q -> wavelength"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"dim_converter = lambda dim : dim if dim in allowed_dimensions else raise_(ValueError(\n",
" f'{dim} not an allowed dimension. Supported dimensions are {list(dimesion_to_unit.keys())}'))\n",
"data_converter = lambda name : globals()[name] if (name in globals()) else raise_(ValueError(\n",
" f'{name} does not exist in notebook.'))\n",
"data_options = lambda : [\n",
" key for key, item in globals().items()\n",
" if isinstance(item, (sc.DataArray, sc.Dataset, sc.Variable))\n",
" ]\n",
"\n",
"data_conversion = ProcessWidget(globals(), \n",
" sc.neutron.convert, 'Convert', \n",
" {'data': data_converter,\n",
" 'from' : dim_converter, 'to': dim_converter},\n",
" options={'from' : allowed_dimensions,\n",
" 'to': allowed_dimensions,\n",
" 'data': data_options})\n",
"data_conversion.subscribe(plot_widget)\n",
"data_conversion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Can also specify just some inputs of a function graphically."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Workaround because python doesn't like shadowing of from\n",
"kwargs = {'from':'tof'}\n",
"convert_tof = functools.partial(sc.neutron.convert, **kwargs)\n",
"data_conversion_tof = ProcessWidget(globals(), \n",
" convert_tof, 'Convert from tof', \n",
" {'data': data_converter,\n",
" 'to': dim_converter}, \n",
" options={'to': allowed_dimensions,\n",
" 'data': data_options})\n",
"data_conversion_tof.subscribe(plot_widget)\n",
"data_conversion_tof"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data plotting\n",
"Plots the data aquired by evaluating the expression entered."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"plot_widget"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading