Skip to content

Commit 129aabc

Browse files
authored
docs: some fixes after comments from celine (#137)
1 parent 74ff15b commit 129aabc

File tree

3 files changed

+38
-56
lines changed

3 files changed

+38
-56
lines changed

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

+12-56
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
"id": "2",
3838
"metadata": {},
3939
"source": [
40-
"## Load the data\n",
40+
"## Load the detector geometry\n",
4141
"\n",
42-
"We load a dataset from a Geant4 simulation only to get access to the detector geometry."
42+
"We load a dataset from a Geant4 simulation **only** to get access to the detector geometry.\n",
43+
"The neutron intensity distribution is not used in this visualization.\n",
44+
"This visualization only displays the absorption correction at each pixel in the detector."
4345
]
4446
},
4547
{
@@ -69,7 +71,7 @@
6971
"id": "5",
7072
"metadata": {},
7173
"source": [
72-
"### Rod-like sample oriented along x-axis"
74+
"### Rod-like sample oriented along y-axis"
7375
]
7476
},
7577
{
@@ -87,9 +89,9 @@
8789
"# The shape determines the shape and the orientation of the sample\n",
8890
"rod_shape = Cylinder(\n",
8991
" radius=sc.scalar(1, unit='cm'),\n",
90-
" height=(height := sc.scalar(5., unit='cm')),\n",
91-
" # Cylinder is oriented along the x-axis\n",
92-
" symmetry_line=(symmetry_line := sc.vector([1, 0, 0])),\n",
92+
" height=(height := sc.scalar(10., unit='cm')),\n",
93+
" # Cylinder is oriented along the y-axis\n",
94+
" symmetry_line=(symmetry_line := sc.vector([0, 1, 0])),\n",
9395
" center_of_base=-height * symmetry_line / 2,\n",
9496
")"
9597
]
@@ -105,13 +107,13 @@
105107
" rod_shape,\n",
106108
" vanadium,\n",
107109
" beam_direction=sc.vector([0, 0, 1]),\n",
108-
" wavelength=sc.linspace('wavelength', 4, 8, 20, unit='angstrom'),\n",
110+
" wavelength=sc.geomspace('wavelength', 0.5, 4, 20, unit='angstrom'),\n",
109111
" # To make it faster, don't compute the transmission fraction for every detector pixel, it's not necessary for the visualization.\n",
110112
" detector_position=dg['mantle'].coords['position']['strip', ::4]['wire', ::2].copy(),\n",
111113
" quadrature_kind='cheap',\n",
112114
")\n",
113115
"\n",
114-
"# The visualization expects the `position` coord to denote detector positions, and `wavelength` to be the last dimension.\n",
116+
"# The visualization expects the `position` coord to denote detector positions\n",
115117
"transmission_fraction_mantle.coords['position'] = transmission_fraction_mantle.coords.pop('detector_position')\n",
116118
"dream.instrument_view(transmission_fraction_mantle, dim='wavelength', pixel_size=20.0)"
117119
]
@@ -130,75 +132,29 @@
130132
"cell_type": "markdown",
131133
"id": "9",
132134
"metadata": {},
133-
"source": [
134-
"## Disk-like sample oriented along x-axis"
135-
]
136-
},
137-
{
138-
"cell_type": "code",
139-
"execution_count": null,
140-
"id": "10",
141-
"metadata": {},
142-
"outputs": [],
143-
"source": [
144-
"disk_shape = Cylinder(\n",
145-
" radius=sc.scalar(5, unit='cm'),\n",
146-
" height=(height := sc.scalar(1., unit='cm')),\n",
147-
" # Cylinder is oriented along the x-axis\n",
148-
" symmetry_line=(symmetry_line := sc.vector([1, 0, 0])),\n",
149-
" center_of_base=-height * symmetry_line / 2,\n",
150-
")\n",
151-
"\n",
152-
"transmission_fraction_mantle = compute_transmission_map(\n",
153-
" disk_shape,\n",
154-
" vanadium,\n",
155-
" beam_direction=sc.vector([0, 0, 1]),\n",
156-
" wavelength=sc.linspace('wavelength', 4, 8, 20, unit='angstrom'),\n",
157-
" # To make it faster, don't compute the transmission fraction for every detector pixel, it's not necessary for the visualization.\n",
158-
" detector_position=dg['mantle'].coords['position']['strip', ::4]['wire', ::2].copy(),\n",
159-
" quadrature_kind='cheap',\n",
160-
")\n",
161-
"\n",
162-
"# The visualization expects the `position` coord to denote detector positions, and `wavelength` to be the last dimension.\n",
163-
"transmission_fraction_mantle.coords['position'] = transmission_fraction_mantle.coords.pop('detector_position')\n",
164-
"dream.instrument_view(transmission_fraction_mantle, dim='wavelength', pixel_size=20.0)"
165-
]
166-
},
167-
{
168-
"cell_type": "markdown",
169-
"id": "11",
170-
"metadata": {},
171135
"source": [
172136
"## Does absorption influence the intensity in the endcap detector?"
173137
]
174138
},
175139
{
176140
"cell_type": "code",
177141
"execution_count": null,
178-
"id": "12",
142+
"id": "10",
179143
"metadata": {},
180144
"outputs": [],
181145
"source": [
182146
"transmission_fraction_endcap = compute_transmission_map(\n",
183147
" rod_shape,\n",
184148
" vanadium,\n",
185149
" beam_direction=sc.vector([0, 0, 1]),\n",
186-
" wavelength=sc.linspace('wavelength', 4, 8, 20, unit='angstrom'),\n",
150+
" wavelength=sc.geomspace('wavelength', 0.5, 4, 20, unit='angstrom'),\n",
187151
" detector_position=dg['endcap_backward'].coords['position']['strip', 0].copy(),\n",
188152
" quadrature_kind='cheap',\n",
189153
")\n",
190154
"\n",
191155
"transmission_fraction_endcap.coords['position'] = transmission_fraction_endcap.coords.pop('detector_position')\n",
192156
"dream.instrument_view(transmission_fraction_endcap, dim='wavelength', pixel_size=20.0)"
193157
]
194-
},
195-
{
196-
"cell_type": "markdown",
197-
"id": "13",
198-
"metadata": {},
199-
"source": [
200-
"As expected the impact of absorption on on the intensity in the endcap detector is close to uniform."
201-
]
202158
}
203159
],
204160
"metadata": {

src/ess/dream/instrument_view.py

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def instrument_view(
4949
"""
5050
from plopp.widgets import Box
5151

52+
if dim and isinstance(data, sc.DataArray) and dim in data.dims[:-1]:
53+
data = data.transpose([d for d in data.dims if d != dim] + [dim])
54+
55+
if dim and isinstance(data, sc.DataGroup):
56+
data = data.copy(deep=False)
57+
for k, v in data.items():
58+
if dim in v.dims[:-1]:
59+
data[k] = v.transpose([d for d in v.dims if d != dim] + [dim])
60+
5261
view = InstrumentView(
5362
data, dim=dim, pixel_size=pixel_size, autoscale=autoscale, **kwargs
5463
)

tests/dream/instrument_view_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ def test_instrument_view_one_module(fake_instrument_data):
4848
assert hasattr(view, 'slider')
4949

5050

51+
def test_instrument_view_slider_not_last_dim_dataarray(fake_instrument_data):
52+
da = fake_instrument_data['bank1']
53+
da = da.transpose(('tof', *(set(da.dims) - {'tof'})))
54+
InstrumentView(da, dim='tof')
55+
56+
57+
def test_instrument_view_slider_not_last_dim_datagroup(fake_instrument_data):
58+
da = fake_instrument_data
59+
# Add extra dim so that not all entries in the group have the same set of dimensions
60+
da['bank2'] = da['bank2'].broadcast(
61+
dims=[*da['bank2'].dims, 'extra_dimension'], shape=[*da['bank2'].shape, 1]
62+
)
63+
for k, v in da.items():
64+
da[k] = v.transpose(('tof', *(set(v.dims) - {'tof'})))
65+
InstrumentView(da, dim='tof')
66+
67+
5168
def test_instrument_view_no_tof_slider(fake_instrument_data):
5269
view = InstrumentView(fake_instrument_data.sum('tof'))
5370
assert hasattr(view, 'checkboxes')

0 commit comments

Comments
 (0)