|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Divergent data reduction for Amor\n", |
| 8 | + "\n", |
| 9 | + "In this notebook, we will look at how to use the `essreflectometry` package with Sciline, for reflectometry data collected from the PSI instrument [Amor](https://www.psi.ch/en/sinq/amor) in [divergent beam mode](https://www.psi.ch/en/sinq/amor/selene).\n", |
| 10 | + "\n", |
| 11 | + "We will begin by importing the modules that are necessary for this notebook." |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "import scipp as sc\n", |
| 21 | + "import sciline\n", |
| 22 | + "from essreflectometry.amor import providers, default_parameters\n", |
| 23 | + "from essreflectometry.types import *" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": null, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "params={\n", |
| 33 | + " **default_parameters,\n", |
| 34 | + " QBins: sc.geomspace(dim='Q', start=0.008, stop=0.075, num=200, unit='1/angstrom'),\n", |
| 35 | + " SampleRotation[Sample]: sc.scalar(0.7989, unit='deg'),\n", |
| 36 | + " Filename[Sample]: \"sample.nxs\",\n", |
| 37 | + " SampleRotation[Reference]: sc.scalar(0.8389, unit='deg'),\n", |
| 38 | + " Filename[Reference]: \"reference.nxs\",\n", |
| 39 | + "}" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "pipeline = sciline.Pipeline(\n", |
| 49 | + " providers,\n", |
| 50 | + " params=params\n", |
| 51 | + ")" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": null, |
| 57 | + "metadata": {}, |
| 58 | + "outputs": [], |
| 59 | + "source": [ |
| 60 | + "pipeline.visualize((NormalizedIofQ, QResolution), graph_attr={'rankdir': 'LR'})" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "code", |
| 65 | + "execution_count": null, |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [], |
| 68 | + "source": [ |
| 69 | + "# Compute I over Q and the standard deviation of Q\n", |
| 70 | + "ioq, qstd = pipeline.compute((NormalizedIofQ, QResolution)).values()" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": null, |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [], |
| 78 | + "source": [ |
| 79 | + "import matplotlib.pyplot as plt\n", |
| 80 | + "\n", |
| 81 | + "fig = plt.figure(figsize=(5, 7))\n", |
| 82 | + "ax1 = fig.add_axes([0, 0.55, 1.0, 0.45])\n", |
| 83 | + "ax2 = fig.add_axes([0, 0.0, 1.0, 0.45])\n", |
| 84 | + "cax = fig.add_axes([1.05, 0.55, 0.03, 0.45])\n", |
| 85 | + "fig1 = ioq.plot(norm='log', ax=ax1, cax=cax, grid=True)\n", |
| 86 | + "fig2 = ioq.mean('detector_number').plot(norm='log', ax=ax2, grid=True)\n", |
| 87 | + "fig1.canvas.xrange = fig2.canvas.xrange" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "markdown", |
| 92 | + "metadata": {}, |
| 93 | + "source": [ |
| 94 | + "## Make a $(\\lambda, \\theta)$ map\n", |
| 95 | + "A good sanity check is to create a two-dimensional map of the counts in $\\lambda$ and $\\theta$ bins. To achieve this, we request the `ThetaData` from the pipeline. In the graph above we can see that `WavelengthData` is required to compute `ThetaData`, therefore it is also present in `ThetaData` so we don't need to require it separately." |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": null, |
| 101 | + "metadata": {}, |
| 102 | + "outputs": [], |
| 103 | + "source": [ |
| 104 | + "from essreflectometry.types import ThetaData\n", |
| 105 | + "pipeline.compute(ThetaData[Sample])\\\n", |
| 106 | + " .bins.concat('detector_number')\\\n", |
| 107 | + " .hist(\n", |
| 108 | + " theta=sc.linspace(dim='theta', start=0.0, stop=1.2, num=165, unit='deg').to(unit='rad'),\n", |
| 109 | + " wavelength=sc.linspace(dim='wavelength', start=0, stop=15.0, num=165, unit='angstrom'),\n", |
| 110 | + " )\\\n", |
| 111 | + " .plot()\n" |
| 112 | + ] |
| 113 | + }, |
| 114 | + { |
| 115 | + "cell_type": "markdown", |
| 116 | + "metadata": {}, |
| 117 | + "source": [ |
| 118 | + "This plot can be used to check if the value of the sample rotation angle $\\omega$ is correct. The bright triangles should be pointing back to the origin $\\lambda = \\theta = 0$." |
| 119 | + ] |
| 120 | + } |
| 121 | + ], |
| 122 | + "metadata": { |
| 123 | + "kernelspec": { |
| 124 | + "display_name": "essreflectometry", |
| 125 | + "language": "python", |
| 126 | + "name": "python3" |
| 127 | + }, |
| 128 | + "language_info": { |
| 129 | + "codemirror_mode": { |
| 130 | + "name": "ipython", |
| 131 | + "version": 3 |
| 132 | + }, |
| 133 | + "file_extension": ".py", |
| 134 | + "mimetype": "text/x-python", |
| 135 | + "name": "python", |
| 136 | + "nbconvert_exporter": "python", |
| 137 | + "pygments_lexer": "ipython3", |
| 138 | + "version": "3.10.12" |
| 139 | + } |
| 140 | + }, |
| 141 | + "nbformat": 4, |
| 142 | + "nbformat_minor": 2 |
| 143 | +} |
0 commit comments