|
6 | 6 | "source": [ |
7 | 7 | "# Histogram Mode Detector\n", |
8 | 8 | "\n", |
| 9 | + "## TL;DR - Get normalized sample images averaged along the rotation angle." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "from ess.imaging.data import get_ymir_images_path\n", |
| 19 | + "from ess.imaging.io import FilePath\n", |
| 20 | + "from ess.imaging.normalize import NormalizedSampleImages\n", |
| 21 | + "from ess.imaging.workflow import (\n", |
| 22 | + " YmirImageNormalizationWorkflow,\n", |
| 23 | + " ImageDetectorName,\n", |
| 24 | + " RotationMotionSensorName,\n", |
| 25 | + ")\n", |
| 26 | + "\n", |
| 27 | + "wf = YmirImageNormalizationWorkflow()\n", |
| 28 | + "wf[FilePath] = (\n", |
| 29 | + " get_ymir_images_path()\n", |
| 30 | + ") # Replace with the path to your images in nexus file.\n", |
| 31 | + "wf[ImageDetectorName] = 'orca'\n", |
| 32 | + "wf[RotationMotionSensorName] = 'motion_cabinet_2'\n", |
| 33 | + "normalized = wf.compute(NormalizedSampleImages)\n", |
| 34 | + "normalized" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": null, |
| 40 | + "metadata": {}, |
| 41 | + "outputs": [], |
| 42 | + "source": [ |
| 43 | + "normalized['time', 0].plot(\n", |
| 44 | + " title=f'Normalized Sample Image at Rotation Angle of {normalized.coords[\"rotation_angle\"].values[0]:.3f}'\n", |
| 45 | + ")" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "markdown", |
| 50 | + "metadata": {}, |
| 51 | + "source": [ |
| 52 | + "You can use a slicer to browse images along the rotation angle.\n", |
| 53 | + "\n", |
| 54 | + "```python\n", |
| 55 | + "%matplotlib widget\n", |
| 56 | + "from plopp import slicer\n", |
| 57 | + "\n", |
| 58 | + "slicer(normalized)\n", |
| 59 | + "```\n", |
| 60 | + "\n", |
| 61 | + "If you want to bin the images by linear steps of angles,\n", |
| 62 | + "you can use ``sc.groupby`` like below.\n", |
| 63 | + "\n", |
| 64 | + "```python\n", |
| 65 | + "%matplotlib widget\n", |
| 66 | + "import scipp as sc\n", |
| 67 | + "from plopp import slicer\n", |
| 68 | + "\n", |
| 69 | + "slicer(normalized.groupby(\n", |
| 70 | + " 'rotation_angle',\n", |
| 71 | + " bins=sc.linspace(dim='rotation_angle', start=-0.5, stop=4.5, num=5, unit='deg'),\n", |
| 72 | + ").mean('rotation_angle'))\n", |
| 73 | + "```" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "markdown", |
| 78 | + "metadata": {}, |
| 79 | + "source": [ |
9 | 80 | "## IO\n", |
10 | 81 | "\n", |
11 | 82 | "I/O providers can load white beam images and slice them according to the image key.\n", |
|
14 | 85 | "\n", |
15 | 86 | "Instead, we slice the data according to the ``image_key`` and separate image stacks earlier due to performance limitation of 3-dimensional data binning.\n", |
16 | 87 | "\n", |
17 | | - "> For example, for 400 images of 2_048 x 2_048 pixels couldn't be done in the regular laptop." |
| 88 | + "> For example, for 400 images of 2_048 x 2_048 pixels couldn't be done in the regular laptop.\n", |
| 89 | + "\n", |
| 90 | + "### Load the data as a stack of images" |
18 | 91 | ] |
19 | 92 | }, |
20 | 93 | { |
|
26 | 99 | "from ess.imaging.data import get_ymir_images_path\n", |
27 | 100 | "from ess.imaging.io import (\n", |
28 | 101 | " FilePath,\n", |
29 | | - " SampleImageStacks,\n", |
| 102 | + " SampleImageStacksWithLogs,\n", |
30 | 103 | " RawSampleImageStacks,\n", |
31 | 104 | " OpenBeamImageStacks,\n", |
32 | 105 | " DarkCurrentImageStacks,\n", |
33 | 106 | " AllImageStacks,\n", |
34 | 107 | ")\n", |
35 | 108 | "from ess.imaging.workflow import (\n", |
36 | | - " YmirWorkflow,\n", |
| 109 | + " YmirImageNormalizationWorkflow,\n", |
37 | 110 | " ImageDetectorName,\n", |
38 | 111 | " RotationMotionSensorName,\n", |
39 | 112 | ")\n", |
40 | 113 | "\n", |
41 | | - "wf = YmirWorkflow()\n", |
| 114 | + "wf = YmirImageNormalizationWorkflow()\n", |
42 | 115 | "wf[FilePath] = get_ymir_images_path()\n", |
43 | 116 | "wf[ImageDetectorName] = 'orca'\n", |
44 | 117 | "wf[RotationMotionSensorName] = 'motion_cabinet_2'" |
|
55 | 128 | " RawSampleImageStacks,\n", |
56 | 129 | " OpenBeamImageStacks,\n", |
57 | 130 | " DarkCurrentImageStacks,\n", |
58 | | - " SampleImageStacks,\n", |
| 131 | + " SampleImageStacksWithLogs,\n", |
59 | 132 | ")\n", |
60 | 133 | "wf.visualize(image_stack_types)" |
61 | 134 | ] |
|
67 | 140 | "outputs": [], |
68 | 141 | "source": [ |
69 | 142 | "results = wf.compute(image_stack_types)\n", |
70 | | - "results[SampleImageStacks]" |
| 143 | + "results[SampleImageStacksWithLogs]" |
71 | 144 | ] |
72 | 145 | }, |
73 | 146 | { |
74 | 147 | "cell_type": "markdown", |
75 | 148 | "metadata": {}, |
76 | 149 | "source": [ |
77 | | - "## Save Individual Frame" |
| 150 | + "### Save Individual Frame" |
78 | 151 | ] |
79 | 152 | }, |
80 | 153 | { |
|
117 | 190 | "cell_type": "markdown", |
118 | 191 | "metadata": {}, |
119 | 192 | "source": [ |
120 | | - "## Save All Frames in One File" |
| 193 | + "### Save All Frames in One File" |
121 | 194 | ] |
122 | 195 | }, |
123 | 196 | { |
|
167 | 240 | "source": [ |
168 | 241 | "!rm -rf images" |
169 | 242 | ] |
| 243 | + }, |
| 244 | + { |
| 245 | + "cell_type": "markdown", |
| 246 | + "metadata": {}, |
| 247 | + "source": [ |
| 248 | + "## Normalization\n", |
| 249 | + "\n", |
| 250 | + "See :attr:ess.imaging.normalize.normalize_sample_images for more details." |
| 251 | + ] |
| 252 | + }, |
| 253 | + { |
| 254 | + "cell_type": "code", |
| 255 | + "execution_count": null, |
| 256 | + "metadata": {}, |
| 257 | + "outputs": [], |
| 258 | + "source": [ |
| 259 | + "from ess.imaging.normalize import NormalizedSampleImages\n", |
| 260 | + "\n", |
| 261 | + "wf[OpenBeamImageStacks] = results[OpenBeamImageStacks]\n", |
| 262 | + "wf[DarkCurrentImageStacks] = results[DarkCurrentImageStacks]\n", |
| 263 | + "wf[SampleImageStacksWithLogs] = results[SampleImageStacksWithLogs]\n", |
| 264 | + "wf.visualize(NormalizedSampleImages)" |
| 265 | + ] |
| 266 | + }, |
| 267 | + { |
| 268 | + "cell_type": "code", |
| 269 | + "execution_count": null, |
| 270 | + "metadata": {}, |
| 271 | + "outputs": [], |
| 272 | + "source": [ |
| 273 | + "wf.compute(NormalizedSampleImages)" |
| 274 | + ] |
170 | 275 | } |
171 | 276 | ], |
172 | 277 | "metadata": { |
173 | 278 | "kernelspec": { |
174 | | - "display_name": "img-dev-310", |
| 279 | + "display_name": "Python 3 (ipykernel)", |
175 | 280 | "language": "python", |
176 | 281 | "name": "python3" |
177 | 282 | }, |
|
189 | 294 | } |
190 | 295 | }, |
191 | 296 | "nbformat": 4, |
192 | | - "nbformat_minor": 2 |
| 297 | + "nbformat_minor": 4 |
193 | 298 | } |
0 commit comments