|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# BEER thumbnails\n", |
| 9 | + "\n", |
| 10 | + "This notebook generates the thumbnails used in the BEER user guide." |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": null, |
| 16 | + "id": "1", |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "import matplotlib.pyplot as plt\n", |
| 21 | + "\n", |
| 22 | + "import scipp as sc\n", |
| 23 | + "\n", |
| 24 | + "from ess.beer import BeerModMcStasWorkflow\n", |
| 25 | + "from ess.beer.data import mcstas_duplex\n", |
| 26 | + "from ess.reduce.nexus.types import Filename, SampleRun\n", |
| 27 | + "from ess.beer.types import *\n" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": null, |
| 33 | + "id": "2", |
| 34 | + "metadata": {}, |
| 35 | + "outputs": [], |
| 36 | + "source": [ |
| 37 | + "wf = BeerModMcStasWorkflow()\n", |
| 38 | + "wf[Filename[SampleRun]] = mcstas_duplex(9)\n", |
| 39 | + "histogram = wf.compute(DetectorData[SampleRun])['bank1'].hist(two_theta=1000, event_time_offset=1000)" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "id": "3", |
| 46 | + "metadata": {}, |
| 47 | + "outputs": [], |
| 48 | + "source": [ |
| 49 | + "def basic_powder_plot(style: str):\n", |
| 50 | + " with plt.style.context(style):\n", |
| 51 | + " fig, ax = plt.subplots(layout='constrained', figsize=(3, 2.5))\n", |
| 52 | + " _ = histogram.plot(ax=ax, norm='log')\n", |
| 53 | + " ax.set_xlim((0.045,0.12))\n", |
| 54 | + " ax.set_xlabel(r'$t$ [µs]')\n", |
| 55 | + " ax.set_ylabel(r'$I(t)$')\n", |
| 56 | + " return fig" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "id": "4", |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [ |
| 66 | + "fig = basic_powder_plot('default')\n", |
| 67 | + "fig.savefig(\n", |
| 68 | + " \"../../docs/_static/thumbnails/beer_mcstas_light.svg\",\n", |
| 69 | + " transparent=True,\n", |
| 70 | + ")\n", |
| 71 | + "fig" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": null, |
| 77 | + "id": "5", |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "fig = basic_powder_plot('dark_background')\n", |
| 82 | + "fig.savefig(\n", |
| 83 | + " \"../../docs/_static/thumbnails/beer_mcstas_dark.svg\",\n", |
| 84 | + " transparent=True,\n", |
| 85 | + ")\n", |
| 86 | + "fig" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": null, |
| 92 | + "id": "6", |
| 93 | + "metadata": {}, |
| 94 | + "outputs": [], |
| 95 | + "source": [ |
| 96 | + "detector_names = [\"mantle\", \"endcap_forward\", \"endcap_backward\", \"high_resolution\"]\n", |
| 97 | + "two_theta_bins = [\n", |
| 98 | + " sc.linspace(dim=\"two_theta\", unit=\"rad\", start=0.77, stop=2.36, num=70),\n", |
| 99 | + " sc.linspace(dim=\"two_theta\", unit=\"rad\", start=0.24, stop=0.71, num=30),\n", |
| 100 | + " sc.linspace(dim=\"two_theta\", unit=\"rad\", start=2.42, stop=2.91, num=50),\n", |
| 101 | + " sc.linspace(dim=\"two_theta\", unit=\"rad\", start=2.91, stop=3.11, num=10),\n", |
| 102 | + "]\n", |
| 103 | + "parameter_table = pd.DataFrame(\n", |
| 104 | + " {NeXusDetectorName: detector_names,\n", |
| 105 | + " TwoThetaBins: two_theta_bins,\n", |
| 106 | + " },\n", |
| 107 | + " index=detector_names\n", |
| 108 | + ").rename_axis(index='detector')\n", |
| 109 | + "\n", |
| 110 | + "all_detector_workflow = workflow.copy()\n", |
| 111 | + "mapped = all_detector_workflow[IofDspacingTwoTheta].map(parameter_table)\n", |
| 112 | + "all_detector_workflow[IofDspacingTwoTheta] = mapped.reduce(func=powder.grouping.collect_detectors)\n", |
| 113 | + "\n", |
| 114 | + "result = all_detector_workflow.compute(IofDspacingTwoTheta)" |
| 115 | + ] |
| 116 | + }, |
| 117 | + { |
| 118 | + "cell_type": "code", |
| 119 | + "execution_count": null, |
| 120 | + "id": "7", |
| 121 | + "metadata": {}, |
| 122 | + "outputs": [], |
| 123 | + "source": [ |
| 124 | + "histogram = result.bin(dspacing=80).hist()" |
| 125 | + ] |
| 126 | + }, |
| 127 | + { |
| 128 | + "cell_type": "code", |
| 129 | + "execution_count": null, |
| 130 | + "id": "8", |
| 131 | + "metadata": {}, |
| 132 | + "outputs": [], |
| 133 | + "source": [ |
| 134 | + "def advanced_powder_plot(style: str):\n", |
| 135 | + " with plt.style.context(style):\n", |
| 136 | + " fig, ax = plt.subplots(layout='constrained', figsize=(3, 2.5))\n", |
| 137 | + " pf = pp.imagefigure(*(pp.Node(da) for da in histogram.values()), norm='log', cbar=True, ax=ax)\n", |
| 138 | + " pf.view.colormapper.ylabel = None\n", |
| 139 | + " ax.set_xlabel(r'$d$ [Å]')\n", |
| 140 | + " ax.set_ylabel(r'$2\\theta$ [rad]')\n", |
| 141 | + " return fig" |
| 142 | + ] |
| 143 | + }, |
| 144 | + { |
| 145 | + "cell_type": "code", |
| 146 | + "execution_count": null, |
| 147 | + "id": "9", |
| 148 | + "metadata": {}, |
| 149 | + "outputs": [], |
| 150 | + "source": [ |
| 151 | + "fig = advanced_powder_plot('default')\n", |
| 152 | + "fig.savefig(\n", |
| 153 | + " \"../../docs/_static/thumbnails/dream_advanced_powder_reduction_light.svg\",\n", |
| 154 | + " transparent=True,\n", |
| 155 | + ")\n", |
| 156 | + "fig" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": null, |
| 162 | + "id": "10", |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [], |
| 165 | + "source": [ |
| 166 | + "fig = advanced_powder_plot('dark_background')\n", |
| 167 | + "fig.savefig(\n", |
| 168 | + " \"../../docs/_static/thumbnails/dream_advanced_powder_reduction_dark.svg\",\n", |
| 169 | + " transparent=True,\n", |
| 170 | + ")\n", |
| 171 | + "fig" |
| 172 | + ] |
| 173 | + } |
| 174 | + ], |
| 175 | + "metadata": { |
| 176 | + "kernelspec": { |
| 177 | + "display_name": "Python 3 (ipykernel)", |
| 178 | + "language": "python", |
| 179 | + "name": "python3" |
| 180 | + }, |
| 181 | + "language_info": { |
| 182 | + "codemirror_mode": { |
| 183 | + "name": "ipython", |
| 184 | + "version": 3 |
| 185 | + }, |
| 186 | + "file_extension": ".py", |
| 187 | + "mimetype": "text/x-python", |
| 188 | + "name": "python", |
| 189 | + "nbconvert_exporter": "python", |
| 190 | + "pygments_lexer": "ipython3", |
| 191 | + "version": "3.11.13" |
| 192 | + } |
| 193 | + }, |
| 194 | + "nbformat": 4, |
| 195 | + "nbformat_minor": 5 |
| 196 | +} |
0 commit comments