Skip to content

Commit 3401b79

Browse files
committed
fix: text in notebook
1 parent c3c0a60 commit 3401b79

File tree

1 file changed

+64
-33
lines changed

1 file changed

+64
-33
lines changed

docs/user-guide/dream/dream-visualize-absorption.ipynb

Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
"source": [
88
"# DREAM instrument view\n",
99
"\n",
10-
"This notebook is a simple example of how to use the instrument view for the DREAM instrument.\n",
10+
"This notebook is an example of how to use the `compute_transmission_map` function to visualize the effect of (sample) absorption on the intensity in the detector.\n",
1111
"\n",
12-
"- 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",
13-
"- There are also checkboxes to hide/show the different elements that make up the DREAM detectors.\n",
12+
"Note that the `compute_transmission_map` function only accounts for the effect of absorption. The measured intensity in the detector can also be impacted by other effects, such as the effect of the solid angle being different for different detector pixels.\n",
1413
"\n",
15-
"We begin with relevant imports.\n",
16-
"We will be using tutorial data downloaded with `pooch`.\n",
17-
"If you get an error about a missing module `pooch`, you can install it with `!pip install pooch`:"
14+
"For more details, see https://scipp.github.io/scippneutron/user-guide/absorption-correction.html."
1815
]
1916
},
2017
{
@@ -25,8 +22,16 @@
2522
"outputs": [],
2623
"source": [
2724
"import scipp as sc\n",
25+
"\n",
26+
"from plopp.graphics import Camera\n",
27+
"\n",
2828
"from ess import dream\n",
29-
"import ess.dream.data # noqa: F401"
29+
"import ess.dream.data # noqa: F401\n",
30+
"\n",
31+
"from scippneutron.absorption import compute_transmission_map\n",
32+
"from scippneutron.absorption.cylinder import Cylinder\n",
33+
"from scippneutron.absorption.material import Material\n",
34+
"from scippneutron.atoms import ScatteringParams"
3035
]
3136
},
3237
{
@@ -36,9 +41,7 @@
3641
"source": [
3742
"## Load the data\n",
3843
"\n",
39-
"We load a dataset from a Geant4 simulation (stored as a `.csv` file).\n",
40-
"In each detector bank, the data is organised by `wire`, `strip`, `module`, `segment`, and `counter`.\n",
41-
"The high resolution detector also has an additional `sector` dimension."
44+
"We load a dataset from a Geant4 simulation only to get access to the detector geometry."
4245
]
4346
},
4447
{
@@ -48,10 +51,7 @@
4851
"metadata": {},
4952
"outputs": [],
5053
"source": [
51-
"dg = dream.io.load_geant4_csv(dream.data.get_path(\"data_dream0_new_hkl_Si_pwd.csv.zip\"))\n",
52-
"dg = dg[\"instrument\"] # Extract the instrument data\n",
53-
"\n",
54-
"# Extract the events from nested data groups\n",
54+
"dg = dream.io.load_geant4_csv(dream.data.get_path(\"data_dream0_new_hkl_Si_pwd.csv.zip\"))[\"instrument\"]\n",
5555
"dg = sc.DataGroup({key: detector[\"events\"] for key, detector in dg.items()})\n",
5656
"dg"
5757
]
@@ -63,7 +63,7 @@
6363
"source": [
6464
"## Display inhomogeneity from absorption\n",
6565
"\n",
66-
"If the sample absorbs or scatters a large fraction of the incoming neutrons the intensity in the detector will vary even if the scattering is inhomogeneous.\n"
66+
"If the sample absorbs or scatters a large fraction of the incoming neutrons, the intensity in the detector will vary even if the scattering is inhomogeneous.\n"
6767
]
6868
},
6969
{
@@ -73,46 +73,77 @@
7373
"metadata": {},
7474
"outputs": [],
7575
"source": [
76-
"import scipp as sc\n",
77-
"\n",
78-
"from scippneutron.absorption import compute_transmission_map\n",
79-
"from scippneutron.absorption.cylinder import Cylinder\n",
80-
"from scippneutron.absorption.material import Material\n",
81-
"from scippneutron.atoms import ScatteringParams\n",
82-
"\n",
83-
"\n",
8476
"material = Material(\n",
8577
" scattering_params=ScatteringParams.for_isotope('V'),\n",
8678
" effective_sample_number_density=sc.scalar(0.07192, unit='1/angstrom**3')\n",
8779
")\n",
8880
"sample_shape = Cylinder(\n",
89-
" symmetry_line=sc.vector([0, 1, 0]),\n",
90-
" center_of_base=sc.vector([0, -2.5, 0], unit='cm'),\n",
9181
" radius=sc.scalar(1, unit='cm'),\n",
92-
" height=sc.scalar(5., unit='cm')\n",
93-
")\n",
94-
"\n",
95-
"transmission_fraction = compute_transmission_map(\n",
82+
" height=(height := sc.scalar(5., unit='cm')),\n",
83+
" # Cylinder is oriented along the x-axis\n",
84+
" symmetry_line=(symmetry_line := sc.vector([1, 0, 0])),\n",
85+
" center_of_base=-height * symmetry_line / 2,\n",
86+
")"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": null,
92+
"id": "6",
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"transmission_fraction_mantle = compute_transmission_map(\n",
9697
" sample_shape,\n",
9798
" material,\n",
9899
" beam_direction=sc.vector([0, 0, 1]),\n",
99100
" wavelength=sc.linspace('wavelength', 4, 8, 20, unit='angstrom'),\n",
101+
" # To make it faster, don't compute the transmission fraction for every detector pixel, it's not necessary for the visualization.\n",
100102
" detector_position=dg['mantle'].coords['position']['strip', ::4]['wire', ::2].copy(),\n",
101103
" quadrature_kind='cheap',\n",
102104
")\n",
103105
"\n",
104-
"transmission_fraction.coords['position'] = transmission_fraction.coords.pop('detector_position')\n",
105-
"dream.instrument_view(transmission_fraction.transpose((*set(transmission_fraction.dims) - {'wavelength'}, 'wavelength')), dim='wavelength')"
106+
"# The visualization expects the `position` coord to denote detector positions, and `wavelength` to be the last dimension.\n",
107+
"transmission_fraction_mantle.coords['position'] = transmission_fraction_mantle.coords.pop('detector_position')\n",
108+
"dream.instrument_view(transmission_fraction_mantle.transpose((*set(transmission_fraction_mantle.dims) - {'wavelength'}, 'wavelength')), dim='wavelength', camera=Camera(position=sc.vector((-1.5, 1.5, -1.5), unit='m'), look_at=sc.vector((1, -1/3, 1/2), unit='m')))"
106109
]
107110
},
108111
{
109112
"cell_type": "code",
110113
"execution_count": null,
111-
"id": "6",
114+
"id": "7",
115+
"metadata": {},
116+
"outputs": [],
117+
"source": [
118+
"transmission_fraction_mantle"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"id": "8",
112125
"metadata": {},
113126
"outputs": [],
114127
"source": [
115-
"transmission_fraction"
128+
"transmission_fraction_endcap = compute_transmission_map(\n",
129+
" sample_shape,\n",
130+
" material,\n",
131+
" beam_direction=sc.vector([0, 0, 1]),\n",
132+
" wavelength=sc.linspace('wavelength', 4, 8, 20, unit='angstrom'),\n",
133+
" detector_position=dg['endcap_backward'].coords['position']['strip', 0].copy(),\n",
134+
" quadrature_kind='cheap',\n",
135+
")\n",
136+
"\n",
137+
"transmission_fraction_endcap.coords['position'] = transmission_fraction_endcap.coords.pop('detector_position')\n",
138+
"dream.instrument_view(transmission_fraction_endcap.transpose((*set(transmission_fraction_endcap.dims) - {'wavelength'}, 'wavelength')), dim='wavelength', camera=Camera(position=sc.vector((-1, 1, -3), unit='m'), look_at=sc.vector((0.3, -0.3, 1), unit='m')))"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"id": "9",
144+
"metadata": {},
145+
"source": [
146+
"As expected the impact of absorption on the inhomgenity of the intensity is not nearly as large for the endcap detector as it is for the mantle detector."
116147
]
117148
}
118149
],

0 commit comments

Comments
 (0)