-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dream instrument view #184
Changes from all commits
a983ef7
0709ace
595f6a4
31e621a
cc054d3
f90bbc8
8cbbf28
3e8d203
e8a3da1
914ce18
c0a1716
fb97651
0be2770
7929cf4
12307fa
86d23aa
117d62b
2e4672f
72aea28
52523dc
e190692
c13823a
c0828bc
a08857c
a7954bf
7b5fc25
e63d39b
695b712
88e876a
de11d39
9a8b218
7797731
cd8876a
794b8e0
57065fa
e3c9784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "4852fe41-3f9a-4cdb-8aba-ff7c7f198e6c", | ||
"metadata": {}, | ||
"source": [ | ||
"# DREAM instrument view\n", | ||
"\n", | ||
"This notebook is a simple example on how to use the instrument view for the DREAM instrument.\n", | ||
"\n", | ||
"- The DREAM-specific instrument view is capable of slicing the data with a slider widget along a dimension (e.g. `tof`) by using the `dim` argument.\n", | ||
"- There are also checkboxes to hide/show the different elements that make up the DREAM detectors." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3f416595-83b4-44d1-b506-9ba73bf0786e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import scipp as sc\n", | ||
"from ess import dream" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "228a23dc-17f2-4273-a4c9-3e3276db8c54", | ||
"metadata": {}, | ||
"source": [ | ||
"## Load the data\n", | ||
"\n", | ||
"We load a data set from a Geant4 simulation (stored as a `.csv` file).\n", | ||
"In each detector bank, the data is organised by `wire`, `strip`, `module`, `segment`, and `counter`.\n", | ||
"The end caps also have an additional `sumo` dimension." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1ef8f35b-815f-436a-80e5-cbe4b3172b58", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dg = dream.io.load_geant4_csv(\n", | ||
" dream.data.get_path('data_dream_HF_mil_closed_alldets_1e9.csv.zip')\n", | ||
")\n", | ||
"dg = dg['instrument'] # Extract the instrument data\n", | ||
"\n", | ||
"# Construct the pixel positions from event positions\n", | ||
"for da in dg.values():\n", | ||
" da.coords['position'] = da.bins.coords['position'].bins.mean()\n", | ||
"\n", | ||
"dg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e8325797-5651-43c1-b601-3db6d4348758", | ||
"metadata": { | ||
"editable": true, | ||
"nbsphinx": "hidden", | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Only plot half of the pixels to reduce html docs size\n", | ||
"dg = dg['counter', 0]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "49595486-ab4e-4662-86f7-d301aedcf974", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"## Full instrument view\n", | ||
"\n", | ||
"We first histogram the data along the time-of-flight (`tof`) dimension,\n", | ||
"making sure the same bins are used for all elements:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e85a8364-e0a1-4c10-8cae-c873f297e651", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"tof_edges = sc.linspace('tof', 1.0e7, 1.0e8, 51, unit='ns', dtype=int)\n", | ||
"data = dg.hist(tof=tof_edges)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d08ca911-b1a4-4f17-ba1e-355971531ffe", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"We now use the `instrument_view` function to show the 3D view of the instrument pixels,\n", | ||
"specifying that we wish to have a slider along the `tof` dimension:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "43f9ffbc-6bf5-4407-b3ad-5d1626efc43d", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"full_view = dream.instrument_view(data, dim='tof')\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the intention here that one could pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a sentence. |
||
"full_view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a7030d56-a375-47b5-898c-28fd06c2f361", | ||
"metadata": { | ||
"editable": true, | ||
"nbsphinx": "hidden", | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"full_view[2].controls['tof']['slider'].value = 35" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c0b29ebf-21ff-4385-bf8b-0e4fa14dfaf9", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"source": [ | ||
"Note that it is possible to use any dimension for the slider instead of `tof`, such as `wavelength` (if present in the data).\n", | ||
"\n", | ||
"## Displaying individual detector elements\n", | ||
"\n", | ||
"It is also possible to view a single detector element, selecting e.g. `mantle` from the original data:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "b417011e-0d12-4287-91d5-c1fb6ecc7cac", | ||
"metadata": { | ||
"editable": true, | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"mantle_view = dream.instrument_view(dg['mantle'].hist(wavelength=50), dim='wavelength')\n", | ||
"mantle_view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "299ec404-fb18-4533-ad96-e23bf8ba24d6", | ||
"metadata": { | ||
"editable": true, | ||
"nbsphinx": "hidden", | ||
"slideshow": { | ||
"slide_type": "" | ||
}, | ||
"tags": [] | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"mantle_view[1].controls['wavelength']['slider'].value = 43" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1df1aa56-5251-4555-a4f4-283145747198", | ||
"metadata": {}, | ||
"source": [ | ||
"The instrument view is designed to be flexible in terms of what it accepts as input.\n", | ||
"This means that you can easily inspect, for example, a single module by using the usual slicing notation for data arrays.\n", | ||
"\n", | ||
"Below, we display the first module in the backward end-cap detector:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0c86e491-3564-498d-9232-39485f5b95d7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dream.instrument_view(dg['endcap_backward']['module', 0].hist(tof=1))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DREAM | ||
===== | ||
|
||
.. toctree:: | ||
:maxdepth: 4 | ||
|
||
dream-instrument-view |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
_version = '1' | ||
|
||
__all__ = ['get_path'] | ||
|
||
from ..data import Registry | ||
|
||
def _make_pooch(): | ||
import pooch | ||
_registry = Registry( | ||
instrument='amor', | ||
files={ | ||
"reference.nxs": "md5:56d493c8051e1c5c86fb7a95f8ec643b", | ||
"sample.nxs": "md5:4e07ccc87b5c6549e190bc372c298e83", | ||
}, | ||
version='1', | ||
) | ||
|
||
return pooch.create( | ||
path=pooch.os_cache('ess/amor'), | ||
env='ESS_AMOR_DATA_DIR', | ||
base_url='https://public.esss.dk/groups/scipp/ess/amor/{version}/', | ||
version=_version, | ||
registry={ | ||
"reference.nxs": "md5:56d493c8051e1c5c86fb7a95f8ec643b", | ||
"sample.nxs": "md5:4e07ccc87b5c6549e190bc372c298e83", | ||
}, | ||
Comment on lines
+5
to
-19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code has been moved already, the refactor will get lost (but that is ok, I guess). |
||
) | ||
|
||
|
||
_pooch = _make_pooch() | ||
|
||
|
||
def get_path(name: str) -> str: | ||
""" | ||
Return the path to a data file bundled with scippneutron. | ||
|
||
This function only works with example data and cannot handle | ||
paths to custom files. | ||
""" | ||
return _pooch.fetch(name) | ||
get_path = _registry.get_path |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
|
||
from typing import Dict | ||
|
||
__all__ = ['Registry'] | ||
|
||
|
||
class Registry: | ||
def __init__(self, instrument: str, files: Dict[str, str], version: str): | ||
import pooch | ||
|
||
self._registry = pooch.create( | ||
path=pooch.os_cache(f'ess/{instrument}'), | ||
env=f'ESS_{instrument.upper()}_DATA_DIR', | ||
base_url=f'https://public.esss.dk/groups/scipp/ess/{instrument}/' | ||
+ '{version}/', | ||
version=version, | ||
registry=files, | ||
) | ||
|
||
def get_path(self, name: str, unzip: bool = False) -> str: | ||
""" | ||
Get the path to a file in the registry. | ||
|
||
Parameters | ||
---------- | ||
name: | ||
Name of the file to get the path for. | ||
unzip: | ||
If `True`, unzip the file before returning the path. | ||
""" | ||
import pooch | ||
|
||
return self._registry.fetch(name, processor=pooch.Unzip() if unzip else None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instrument view works correctly. But instead of displaying the SUMOs, I think that for consistency, the 4 tick boxes for the SUMOs should be replaced by 2 tick boxes for the endcap backward and forward detectors.
Note that for the endcap detectors, SUMOs are numbered starting from 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, I am just using the keys in the data group that is supplied as input, to keep it flexible.
If you want to replace the sumos with end-caps, it's probably at the data loading that we should do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, using
dream.load_geant4_csv
should make this go away.