Skip to content

Commit

Permalink
Merge pull request #135 from scipp/sciline-next2
Browse files Browse the repository at this point in the history
Refactor for next Sciline (Optional, param tables, and more)
  • Loading branch information
SimonHeybrock authored Jun 17, 2024
2 parents 4d51289 + e83a965 commit 7d6a037
Show file tree
Hide file tree
Showing 38 changed files with 530 additions and 568 deletions.
4 changes: 4 additions & 0 deletions docs/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
:recursive:
providers
with_background_runs
with_banks
with_pixel_mask_filenames
with_sample_runs
```

## Submodules
Expand Down
8 changes: 6 additions & 2 deletions docs/user-guide/common/beam-center-finder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"workflow = isis.sans2d.Sans2dTutorialWorkflow()\n",
"# For real data use:\n",
"# workflow = isis.sans2d.Sans2dWorkflow()\n",
"workflow[Filename[SampleRun]] = isis.data.sans2d_tutorial_sample_run()"
"workflow[Filename[SampleRun]] = isis.data.sans2d_tutorial_sample_run()\n",
"workflow[isis.sans2d.LowCountThreshold] = sc.scalar(-1, unit=\"counts\")"
]
},
{
Expand Down Expand Up @@ -281,7 +282,10 @@
"workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.upper_bound\n",
"workflow[sans.beam_center_finder.BeamCenterFinderQBins] = sc.linspace(\n",
" 'Q', 0.02, 0.25, 71, unit='1/angstrom'\n",
")"
")\n",
"workflow[sans.beam_center_finder.BeamCenterFinderMinimizer] = None\n",
"workflow[sans.beam_center_finder.BeamCenterFinderTolerance] = None\n",
"workflow[DirectBeam] = None"
]
},
{
Expand Down
41 changes: 1 addition & 40 deletions docs/user-guide/isis/sans2d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"outputs": [],
"source": [
"# left-right layout works better for this graph\n",
"workflow.visualize(IofQ[SampleRun], graph_attr={'rankdir': 'LR'})"
"workflow.visualize(IofQ[SampleRun], graph_attr={\"rankdir\": \"LR\"})"
]
},
{
Expand Down Expand Up @@ -311,45 +311,6 @@
"display(sc.plot(iofqs, norm='log'))"
]
},
{
"cell_type": "markdown",
"id": "372b8d4f",
"metadata": {},
"source": [
"### Avoiding duplicate computation with parameter tables\n",
"\n",
"We have seen above that Sciline can avoid duplicate computation by requesting multiple results.\n",
"However, this is not always possible, for example if we want to compute the final result with different parameters.\n",
"In this case we can use parameter tables to avoid duplicate computation.\n",
"For example, we can compute the final result with different values for handling the uncertainties of the normalization factors.\n",
"This will avoid repeating loading files as well as some computation steps:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ceb079ee",
"metadata": {},
"outputs": [],
"source": [
"from typing import NewType\n",
"\n",
"Mode = NewType('Mode', str)\n",
"param_table = sciline.ParamTable(\n",
" Mode,\n",
" {\n",
" UncertaintyBroadcastMode: [\n",
" UncertaintyBroadcastMode.upper_bound,\n",
" UncertaintyBroadcastMode.drop,\n",
" ]\n",
" },\n",
" index=[Mode('upper_bound'), Mode('drop')],\n",
")\n",
"workflow.set_param_table(param_table)\n",
"results = workflow.compute(sciline.Series[Mode, BackgroundSubtractedIofQ])\n",
"sc.DataGroup(results).hist().plot(norm='log')"
]
},
{
"cell_type": "markdown",
"id": "94062d33-04cb-4a4d-aef1-e5ec58c228c4",
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/isis/zoom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"workflow[isis.SampleOffset] = sc.vector([0.0, 0.0, 0.11], unit='m')\n",
"workflow[isis.DetectorBankOffset] = sc.vector([0.0, 0.0, 0.5], unit='m')\n",
"masks = isis.data.zoom_tutorial_mask_filenames()\n",
"workflow.set_param_series(PixelMaskFilename, masks)"
"workflow = sans.with_pixel_mask_filenames(workflow, masks)"
]
},
{
Expand Down
26 changes: 10 additions & 16 deletions docs/user-guide/loki/loki-direct-beam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@
"metadata": {},
"outputs": [],
"source": [
"masks = loki.data.loki_tutorial_mask_filenames()\n",
"banks = ['larmor_detector']\n",
"workflow.insert(sans.merge_banks)\n",
"workflow.set_param_series(PixelMaskFilename, masks)\n",
"workflow.set_param_series(NeXusDetectorName, banks)"
"workflow = sans.with_pixel_mask_filenames(\n",
" workflow, masks=loki.data.loki_tutorial_mask_filenames()\n",
")\n",
"workflow[NeXusDetectorName] = 'larmor_detector'"
]
},
{
Expand Down Expand Up @@ -206,8 +205,6 @@
"outputs": [],
"source": [
"bc_workflow = workflow.copy()\n",
"bc_workflow.del_param_table(NeXusDetectorName)\n",
"bc_workflow[NeXusDetectorName] = 'larmor_detector'\n",
"bc_workflow.insert(sans.beam_center_from_center_of_mass)"
]
},
Expand Down Expand Up @@ -544,7 +541,7 @@
"id": "c3e2ff3d-2b3d-4ba7-b4ca-f0a5617d22dc",
"metadata": {},
"source": [
"We update the workflow, inserting parameter series and merging providers:"
"We modify the workflow, setting multiple background and sample runs:"
]
},
{
Expand All @@ -557,12 +554,9 @@
"# Reset workflow\n",
"workflow[DimsToKeep] = []\n",
"\n",
"# Set parameter series for file names\n",
"workflow.set_param_series(Filename[SampleRun], sample_runs)\n",
"workflow.set_param_series(Filename[BackgroundRun], background_runs)\n",
"\n",
"# Add event merging provider\n",
"workflow.insert(sans.merge_runs)"
"# Transform base workflow to use multiple sample and background runs\n",
"workflow = sans.with_background_runs(workflow, runs=background_runs)\n",
"workflow = sans.with_sample_runs(workflow, runs=sample_runs)"
]
},
{
Expand All @@ -571,8 +565,8 @@
"metadata": {},
"source": [
"If we now visualize the workflow,\n",
"we can see that every step for the `SampleRun` and `BackgroundRun` branches are now series of types (3D-looking boxes instead of flat rectangles).\n",
"There is also the new `merge_multiple_runs` step that combines the events from the two runs,\n",
"we can see that every step for the `SampleRun` and `BackgroundRun` branches are now replicated (drawn as 3D-looking boxes instead of flat rectangles, set `compact=False` to show flattened version).\n",
"There is also the new `merge_contributions` step that combines the events from the two runs,\n",
"just before the normalization."
]
},
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ dependencies = [
"dask",
"graphviz",
"essreduce",
"numpy<2.0.0",
"pandas",
"plopp",
"pythreejs",
"sciline>=24.4.1",
"sciline>=24.06.0",
"scipp>=23.8.0",
"scippneutron>=23.9.0",
"scippnexus>=23.12.1", # 23.12.0 and below deadlock in threaded use
Expand Down
4 changes: 3 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
dask
graphviz
essreduce
numpy<2.0.0
pandas
plopp
pythreejs
sciline>=24.4.1
sciline>=24.06.0
scipp>=23.8.0
scippneutron>=23.9.0
scippnexus>=23.12.1
81 changes: 50 additions & 31 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:a7107dcab866c4c7fe8573b3c5cbaf22e7b1f587
# SHA1:397546fc6b5f1262c66d9da45a959b3f1266e092
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -7,9 +7,7 @@
#
asttokens==2.4.1
# via stack-data
backcall==0.2.0
# via ipython
certifi==2024.2.2
certifi==2024.6.2
# via requests
charset-normalizer==3.3.2
# via requests
Expand All @@ -21,115 +19,130 @@ comm==0.2.2
# via ipywidgets
contourpy==1.2.1
# via matplotlib
cyclebane==24.6.0
# via sciline
cycler==0.12.1
# via matplotlib
dask==2024.4.1
dask==2024.6.0
# via -r base.in
decorator==5.1.1
# via ipython
essreduce==24.3.11
# via -r base.in
exceptiongroup==1.2.1
# via ipython
executing==2.0.1
# via stack-data
fonttools==4.50.0
fonttools==4.53.0
# via matplotlib
fsspec==2024.3.1
fsspec==2024.6.0
# via dask
graphviz==0.20.3
# via -r base.in
h5py==3.10.0
h5py==3.11.0
# via
# scippneutron
# scippnexus
idna==3.6
idna==3.7
# via requests
importlib-metadata==7.1.0
# via dask
ipydatawidgets==4.3.5
# via pythreejs
ipython==8.9.0
ipython==8.25.0
# via ipywidgets
ipywidgets==8.1.2
ipywidgets==8.1.3
# via
# ipydatawidgets
# pythreejs
jedi==0.19.1
# via ipython
jupyterlab-widgets==3.0.10
jupyterlab-widgets==3.0.11
# via ipywidgets
kiwisolver==1.4.5
# via matplotlib
locket==1.0.0
# via partd
matplotlib==3.8.4
matplotlib==3.9.0
# via plopp
matplotlib-inline==0.1.6
matplotlib-inline==0.1.7
# via ipython
networkx==3.3
# via cyclebane
numpy==1.26.4
# via
# -r base.in
# contourpy
# h5py
# ipydatawidgets
# matplotlib
# pandas
# pythreejs
# scipp
# scippneutron
# scipy
packaging==24.0
packaging==24.1
# via
# dask
# matplotlib
# pooch
parso==0.8.3
pandas==2.2.2
# via -r base.in
parso==0.8.4
# via jedi
partd==1.4.1
partd==1.4.2
# via dask
pexpect==4.9.0
# via ipython
pickleshare==0.7.5
# via ipython
pillow==10.3.0
# via matplotlib
platformdirs==4.2.0
platformdirs==4.2.2
# via pooch
plopp==24.2.0
# via -r base.in
pooch==1.8.1
plopp==24.5.0
# via
# -r base.in
# scippneutron
pooch==1.8.2
# via scippneutron
prompt-toolkit==3.0.36
prompt-toolkit==3.0.47
# via ipython
ptyprocess==0.7.0
# via pexpect
pure-eval==0.2.2
# via stack-data
pygments==2.17.2
pygments==2.18.0
# via ipython
pyparsing==3.1.2
# via matplotlib
python-dateutil==2.9.0.post0
# via
# matplotlib
# pandas
# scippnexus
pythreejs==2.4.2
# via -r base.in
pytz==2024.1
# via pandas
pyyaml==6.0.1
# via dask
requests==2.31.0
requests==2.32.3
# via pooch
sciline==24.4.1
sciline==24.6.0
# via -r base.in
scipp==24.5.1
# via
# -r base.in
# essreduce
# scippneutron
# scippnexus
scippneutron==24.3.0
scippneutron==24.5.0
# via -r base.in
scippnexus==24.3.1
# via
# -r base.in
# essreduce
# scippneutron
scipy==1.13.0
scipy==1.13.1
# via
# scippneutron
# scippnexus
Expand All @@ -143,7 +156,7 @@ toolz==0.12.1
# via
# dask
# partd
traitlets==5.14.2
traitlets==5.14.3
# via
# comm
# ipython
Expand All @@ -153,9 +166,15 @@ traitlets==5.14.2
# traittypes
traittypes==0.2.1
# via ipydatawidgets
typing-extensions==4.12.2
# via ipython
tzdata==2024.1
# via pandas
urllib3==2.2.1
# via requests
wcwidth==0.2.13
# via prompt-toolkit
widgetsnbextension==4.0.10
widgetsnbextension==4.0.11
# via ipywidgets
zipp==3.19.2
# via importlib-metadata
Loading

0 comments on commit 7d6a037

Please sign in to comment.