From 45d862734404a347c647d151d2daf1cb0769aae6 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Thu, 29 Aug 2024 10:13:40 +0200 Subject: [PATCH 1/2] Small fix for QENS instrument. --- 3-mcstas/make_QENS_instrument.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3-mcstas/make_QENS_instrument.py b/3-mcstas/make_QENS_instrument.py index 7ca028b1..c7e3ef5f 100644 --- a/3-mcstas/make_QENS_instrument.py +++ b/3-mcstas/make_QENS_instrument.py @@ -25,7 +25,7 @@ def make(**kwargs): instrument.add_declare_var("double", "backscattering_wavelength") instrument.append_initialize( - "backscattering_wavelength = 2*analyzer_d*sin(DEG2RAD*0.5*(180-2.0*analyzer_angle));" + "backscattering_wavelength = 2.0*analyzer_d*sin(DEG2RAD*0.5*(180-2.0*analyzer_angle));" ) instrument.add_declare_var("double", "backscattering_energy") instrument.append_initialize( From ca3da742a1f24e2d24362bf102fffddf0105ad8b Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Thu, 29 Aug 2024 10:15:43 +0200 Subject: [PATCH 2/2] Last changes to McStas notebooks, including suggestions from run through meeting. --- 3-mcstas/Simulation.ipynb | 45 +++- 3-mcstas/Talk.ipynb | 437 +++++++++++++++++++++++++++------- 3-mcstas/mcstas-qens.ipynb | 2 +- 3-mcstas/mcstas-sans.ipynb | 36 +-- 3-mcstas/quizlib/QENS_quiz.py | 9 +- 3-mcstas/quizlib/SANS_quiz.py | 28 ++- 6 files changed, 425 insertions(+), 132 deletions(-) diff --git a/3-mcstas/Simulation.ipynb b/3-mcstas/Simulation.ipynb index 973d5295..061f08b7 100644 --- a/3-mcstas/Simulation.ipynb +++ b/3-mcstas/Simulation.ipynb @@ -3,7 +3,13 @@ { "cell_type": "markdown", "id": "polyphonic-waste", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "source": [ "# Simulation\n", "At the ESS we have used simulations extensively to design and optimize the facility.\n", @@ -30,10 +36,16 @@ { "cell_type": "markdown", "id": "adequate-delay", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "source": [ "### Ray-tracing\n", - "The ray-tracing part of the simulation deals with the paths of the neutrons through space. Thus the geometric effects in the optics can be understood, as they path of the neutrons are traced through the known guide system.\n", + "The ray-tracing part of the simulation deals with the paths of the neutrons through space. Thus the geometric effects in the optics can be understood, as the path of the neutrons are traced through the known guide system.\n", "\n", "## Monte Carlo ray-tracing\n", "Combining these techniques one can start the rays with random velocities drawn from a distribution that resembles the real source, trace the path of the neutrons through the instrument, and at each interaction, random numbers will be used to sample the behavior using the known probability distributions. Repeating this with many rays allow us to estimate for example the flux at the detector, or even the distribution of flux on the detector.\n", @@ -53,9 +65,8 @@ "### Simulation\n", "Often the simulation will run to estimate a intensity, meaning neutrons per second, and will give this result with an error. This error can be reduced by using more rays for the simulation, corresponding to more Monte Carlo samples. To get the expected count from an experiment, one would have to multiply the intensity with the experiment time. It is also important to understand that the error reported by McStas has nothing to do with the expected error in an experiment, that would be calculated from the square root of the number of counts, the McStas error instead measures the quality of the intensity estimate.\n", "\n", - "\n", "## Quick tutorial\n", - "Thorough Python McStas tutorials can be found with the documentation for McStasScript [https://mads-bertelsen.github.io](https://mads-bertelsen.github.io), and for examples in the C syntax one can look in the McStas package or on [https://www.mcstas.org](https://www.mcstas.org).\n", + "Thorough Python McStas tutorials can be found with the documentation for McStasScript [here](https://mads-bertelsen.github.io), and for examples in the C syntax one can look in the McStas package or on the package [website](https://www.mcstas.org).\n", "\n", "### Import the package\n", "First the package needs to be installed, then it can be imported. McStasScript also needs to be configured to access the local McStas installation, this is covered in the documentation. It is common to define a shorter name when importing to save some keystrokes, here ms is chosen." @@ -65,7 +76,13 @@ "cell_type": "code", "execution_count": null, "id": "foster-union", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import mcstasscript as ms" @@ -418,7 +435,13 @@ { "cell_type": "markdown", "id": "portuguese-supervision", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "source": [ "And we an see how that modified the value by calling *show_parameters* again" ] @@ -486,9 +509,7 @@ "cell_type": "code", "execution_count": null, "id": "mediterranean-pricing", - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "ms.make_sub_plot(data)" @@ -547,7 +568,7 @@ "metadata": { "celltoolbar": "Tags", "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -561,7 +582,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/3-mcstas/Talk.ipynb b/3-mcstas/Talk.ipynb index 5e8098c0..f3a7f512 100644 --- a/3-mcstas/Talk.ipynb +++ b/3-mcstas/Talk.ipynb @@ -4,9 +4,11 @@ "cell_type": "markdown", "id": "polyphonic-waste", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "# Simulation session\n", @@ -19,9 +21,11 @@ "cell_type": "markdown", "id": "numeric-situation", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## Monte Carlo" @@ -32,9 +36,11 @@ "execution_count": null, "id": "violent-hearing", "metadata": { + "editable": true, "slideshow": { "slide_type": "-" - } + }, + "tags": [] }, "outputs": [], "source": [ @@ -43,37 +49,18 @@ "monte_carlo.example_interactive(square_side_length=1.0)" ] }, - { - "cell_type": "markdown", - "id": "commercial-uzbekistan", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## Monte Carlo ray-tracing" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "departmental-executive", - "metadata": {}, - "outputs": [], - "source": [ - "monte_carlo.example_interactive(square_side_length=1.1)" - ] - }, { "cell_type": "markdown", "id": "infinite-retreat", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ + "## Monte Carlo ray-tracing\n", "### Random starting position and direction" ] }, @@ -81,7 +68,13 @@ "cell_type": "code", "execution_count": null, "id": "institutional-trial", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import simple_simulator\n", @@ -97,9 +90,11 @@ "cell_type": "markdown", "id": "enormous-latino", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Example with guide" @@ -109,7 +104,13 @@ "cell_type": "code", "execution_count": null, "id": "peaceful-raleigh", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import ray_tracer_examples\n", @@ -123,9 +124,11 @@ "cell_type": "markdown", "id": "welsh-medium", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Complex example" @@ -135,7 +138,13 @@ "cell_type": "code", "execution_count": null, "id": "unlimited-procedure", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import ray_tracer_examples\n", @@ -149,9 +158,11 @@ "cell_type": "markdown", "id": "searching-uniform", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## Monte Carlo ray-tracing in Neutron Scattering\n", @@ -171,9 +182,11 @@ "cell_type": "markdown", "id": "caring-latest", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## McStas\n", @@ -192,9 +205,11 @@ "cell_type": "markdown", "id": "adequate-delay", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Coordiante system\n", @@ -207,7 +222,13 @@ "cell_type": "code", "execution_count": null, "id": "boring-residence", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import simple_simulator\n", @@ -224,9 +245,11 @@ "execution_count": null, "id": "stunning-photograph", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "outputs": [], "source": [ @@ -247,9 +270,11 @@ "execution_count": null, "id": "impressed-shark", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "outputs": [], "source": [ @@ -263,9 +288,11 @@ "cell_type": "markdown", "id": "hazardous-hacker", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Units in McStas\n", @@ -278,9 +305,11 @@ "cell_type": "markdown", "id": "expanded-nepal", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## McStasScript Python API\n", @@ -291,9 +320,11 @@ "cell_type": "markdown", "id": "retired-adrian", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Import the McStasScript package" @@ -303,7 +334,13 @@ "cell_type": "code", "execution_count": null, "id": "mexican-nelson", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "import mcstasscript as ms" @@ -313,9 +350,11 @@ "cell_type": "markdown", "id": "administrative-smoke", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Create instrument object" @@ -325,7 +364,13 @@ "cell_type": "code", "execution_count": null, "id": "material-publicity", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument = ms.McStas_instr(\"python_tutorial\")" @@ -335,9 +380,11 @@ "cell_type": "markdown", "id": "ordinary-bumper", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### See available components" @@ -347,7 +394,13 @@ "cell_type": "code", "execution_count": null, "id": "animal-slovakia", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.available_components()" @@ -357,7 +410,13 @@ "cell_type": "code", "execution_count": null, "id": "compliant-disclaimer", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.available_components(\"sources\")" @@ -367,9 +426,11 @@ "cell_type": "markdown", "id": "representative-trinidad", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Get help for any component" @@ -379,7 +440,13 @@ "cell_type": "code", "execution_count": null, "id": "liberal-composition", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.component_help(\"Source_div\")" @@ -389,9 +456,11 @@ "cell_type": "markdown", "id": "prerequisite-beauty", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Add a component to the instrument" @@ -401,7 +470,13 @@ "cell_type": "code", "execution_count": null, "id": "spiritual-volleyball", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "src = instrument.add_component(\"source\", \"Source_div\")\n", @@ -412,7 +487,13 @@ "cell_type": "code", "execution_count": null, "id": "prostate-bullet", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "print(src)" @@ -422,9 +503,11 @@ "cell_type": "markdown", "id": "underlying-exception", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Set component parameters" @@ -434,7 +517,13 @@ "cell_type": "code", "execution_count": null, "id": "hybrid-vegetation", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "src.set_parameters(xwidth=0.1, yheight=0.05,\n", @@ -446,9 +535,11 @@ "cell_type": "markdown", "id": "plain-worcester", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### See all parameters" @@ -458,7 +549,13 @@ "cell_type": "code", "execution_count": null, "id": "musical-dominant", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "src.show_parameters()" @@ -468,9 +565,11 @@ "cell_type": "markdown", "id": "coated-covering", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Add instrument parameters" @@ -480,7 +579,13 @@ "cell_type": "code", "execution_count": null, "id": "selective-appeal", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "wavelength_par = instrument.add_parameter(\"wavelength\", value=5.0,\n", @@ -494,7 +599,13 @@ "cell_type": "code", "execution_count": null, "id": "dominican-notebook", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "src.set_parameters(lambda0=wavelength_par, dlambda=\"wavelength_spread\")\n", @@ -505,9 +616,11 @@ "cell_type": "markdown", "id": "written-database", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Place components in space" @@ -517,7 +630,13 @@ "cell_type": "code", "execution_count": null, "id": "functional-courage", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "guide_A = instrument.add_component(\"guide_A\", \"Guide_gravity\")\n", @@ -529,7 +648,13 @@ "cell_type": "code", "execution_count": null, "id": "aware-frequency", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "guide_B = instrument.add_component(\"guide_B\", \"Guide_gravity\")\n", @@ -541,9 +666,11 @@ "cell_type": "markdown", "id": "closed-bidding", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Place a monitor component" @@ -553,7 +680,13 @@ "cell_type": "code", "execution_count": null, "id": "canadian-hamburg", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "mon = instrument.add_component(\"monitor\", \"PSD_monitor\")\n", @@ -566,9 +699,11 @@ "cell_type": "markdown", "id": "pressing-radar", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### See geometry" @@ -578,7 +713,13 @@ "cell_type": "code", "execution_count": null, "id": "immune-teaching", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.show_instrument()" @@ -588,9 +729,11 @@ "cell_type": "markdown", "id": "behind-might", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Get overview of component sequence" @@ -600,7 +743,13 @@ "cell_type": "code", "execution_count": null, "id": "legitimate-liberia", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.show_components()" @@ -610,9 +759,11 @@ "cell_type": "markdown", "id": "classified-spank", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Place a component earlier in the sequence" @@ -622,7 +773,13 @@ "cell_type": "code", "execution_count": null, "id": "pending-alert", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "mon = instrument.add_component(\"monitor_in_guide\", \"PSD_monitor\", after=\"guide_A\")\n", @@ -635,9 +792,11 @@ "cell_type": "markdown", "id": "appointed-compiler", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### See diagram of instrument sequence" @@ -648,7 +807,12 @@ "execution_count": null, "id": "unsigned-washer", "metadata": { - "scrolled": true + "editable": true, + "scrolled": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] }, "outputs": [], "source": [ @@ -659,9 +823,11 @@ "cell_type": "markdown", "id": "neither-pharmacology", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## Executing the simulation\n", @@ -672,7 +838,13 @@ "cell_type": "code", "execution_count": null, "id": "continental-matrix", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.show_parameters()" @@ -681,7 +853,13 @@ { "cell_type": "markdown", "id": "fixed-sydney", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "source": [ "### Set parameters" ] @@ -690,7 +868,13 @@ "cell_type": "code", "execution_count": null, "id": "latin-blond", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.set_parameters(wavelength=2.8)\n", @@ -701,9 +885,11 @@ "cell_type": "markdown", "id": "eleven-venue", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### McStas settings" @@ -713,7 +899,13 @@ "cell_type": "code", "execution_count": null, "id": "colonial-daniel", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "instrument.settings(ncount=5E6, output_path=\"mcstas_data_set\", suppress_output=True)\n", @@ -724,9 +916,11 @@ "cell_type": "markdown", "id": "outer-telling", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Execute the simulation" @@ -737,6 +931,10 @@ "execution_count": null, "id": "legal-cancellation", "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, "tags": [ "hide-output" ] @@ -750,9 +948,11 @@ "cell_type": "markdown", "id": "amended-cholesterol", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Plot the data" @@ -762,7 +962,13 @@ "cell_type": "code", "execution_count": null, "id": "manual-excuse", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "ms.make_sub_plot(data, figsize=(10, 4))" @@ -772,9 +978,11 @@ "cell_type": "markdown", "id": "national-latest", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "### Run with different parameters" @@ -785,6 +993,10 @@ "execution_count": null, "id": "delayed-threshold", "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, "tags": [ "hide-output" ] @@ -800,19 +1012,74 @@ "cell_type": "code", "execution_count": null, "id": "binding-stewart", - "metadata": {}, + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, "outputs": [], "source": [ "ms.make_sub_plot(data, figsize=(10, 4))" ] }, + { + "cell_type": "markdown", + "id": "472b92fb-fa56-4ade-81ab-cd0a896d76f6", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "source": [ + "### Use interactive interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "322f8e39-817c-4b7c-9d61-7e3184289edc", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "%matplotlib widget" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "736755f6-e219-4cea-baff-0f552a158647", + "metadata": { + "editable": true, + "slideshow": { + "slide_type": "" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "from mcstasscript.jb_interface import show\n", + "show(instrument)" + ] + }, { "cell_type": "markdown", "id": "figured-hundred", "metadata": { + "editable": true, "slideshow": { "slide_type": "slide" - } + }, + "tags": [] }, "source": [ "## Exercises\n", @@ -830,7 +1097,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "sixth-individual", "metadata": {}, "outputs": [], @@ -867,7 +1134,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.14" }, "orphan": true }, diff --git a/3-mcstas/mcstas-qens.ipynb b/3-mcstas/mcstas-qens.ipynb index e13be8f1..3c373ed0 100644 --- a/3-mcstas/mcstas-qens.ipynb +++ b/3-mcstas/mcstas-qens.ipynb @@ -1489,7 +1489,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/3-mcstas/mcstas-sans.ipynb b/3-mcstas/mcstas-sans.ipynb index 3ef31b23..15b449b5 100644 --- a/3-mcstas/mcstas-sans.ipynb +++ b/3-mcstas/mcstas-sans.ipynb @@ -393,7 +393,7 @@ }, "outputs": [], "source": [ - "ms.make_plot(data, figsize=(7, 5), log=True, orders_of_mag=5)" + "ms.make_sub_plot(data, log=True, orders_of_mag=5)" ] }, { @@ -847,16 +847,7 @@ "source": [ "## Run improved instrument\n", "\n", - "Run the improved instrument with the following parameters:\n", - "\n", - "- `sample_distance`: 150 m\n", - "- `d_wavelength`: 1.5 Å\n", - "- `enable_sample`: 0\n", - "- `n_pulses`: 1\n", - "- `integration_time`: 5E4 s\n", - "- `detector_distance`: 3 m\n", - "\n", - "We set a long integration time as this corresponds to a calibration run done just once, and by running this for a longer time the statistical error will be smaller.\n", + "Its time to run the improved instrument. We will use the same parameters as earlier, but now also set `integration_time` to $5\\times 10^4$, corresponding to 13.8 hours. This is suposed to emulate a long measurement of the instrument background only done rarely. We use the integration time in the continued workflow to estimate the error on the measured signal.\n", "\n", "Store the returned data in a variable called `background_data`. Name the generated data folder \"SANS_without_sample_1_pulse\" using the *output_path* argument in the `settings` method of the instrument." ] @@ -876,8 +867,7 @@ }, "outputs": [], "source": [ - "instrument.set_parameters(enable_sample=0, d_wavelength=1.5, n_pulses=1,\n", - " detector_distance=3, integration_time=5e4)\n", + "instrument.set_parameters(integration_time=5e4)\n", "instrument.settings(output_path=\"SANS_without_sample_1_pulse\")\n", "\n", "background_data = instrument.backengine()\n", @@ -913,7 +903,7 @@ }, "outputs": [], "source": [ - "ms.make_plot(background_data, figsize=(7, 5), log=True, orders_of_mag=5)" + "ms.make_sub_plot(background_data, log=True, orders_of_mag=5)" ] }, { @@ -1033,7 +1023,7 @@ }, "outputs": [], "source": [ - "ms.make_plot(sample_data, figsize=(7, 5), log=True, orders_of_mag=5)" + "ms.make_sub_plot(sample_data, log=True, orders_of_mag=5)" ] }, { @@ -1215,20 +1205,6 @@ "source": [ "compare_monitors(\"signal_tof\")" ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d722a296-ecbd-4407-b990-d0df5e8f0b3a", - "metadata": { - "editable": true, - "slideshow": { - "slide_type": "" - }, - "tags": [] - }, - "outputs": [], - "source": [] } ], "metadata": { @@ -1248,7 +1224,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.14" } }, "nbformat": 4, diff --git a/3-mcstas/quizlib/QENS_quiz.py b/3-mcstas/quizlib/QENS_quiz.py index b44b7759..dfba4fcb 100644 --- a/3-mcstas/quizlib/QENS_quiz.py +++ b/3-mcstas/quizlib/QENS_quiz.py @@ -175,7 +175,7 @@ def question_7(self, answer=None): print_box("The DiskChopper was inserted after the sample position, this is not quite right", False) return - msg = "The DiskChopper was added at the right point in the component sequence!" + msg = "The DiskChopper was added at the right point in the component sequence and with correct parameters!" required_pars = dict(yheight=0.05, radius=0.7, nu="chopper_frequency", nslit=1.0, delay="chopper_delay", theta_0="chopper_theta") self.last_component_in_instr_check(answer=answer, comp_type_str="DiskChopper", @@ -228,7 +228,12 @@ def question_8(self, answer=None): print_box("The DiskChopper was inserted after the sample position, this is not quite right", False) return - msg = "The DiskChopper was added at the right point in the component sequence!" + chopper_component = answer.get_component(chopper_name) + if chopper_component.AT_data[2] == 6.5: + print_box("The distance to the chopper was set directly as a number, use the variable name instead. It is the right value though!", False) + return + + msg = "The DiskChopper was added at the right point in the space!" required_pars = dict(yheight=0.05, radius=0.7, nu="chopper_frequency", nslit=1.0, delay="chopper_delay", theta_0="chopper_theta") self.last_component_in_instr_check(answer=answer, comp_type_str="DiskChopper", diff --git a/3-mcstas/quizlib/SANS_quiz.py b/3-mcstas/quizlib/SANS_quiz.py index d3cc480a..382516ed 100644 --- a/3-mcstas/quizlib/SANS_quiz.py +++ b/3-mcstas/quizlib/SANS_quiz.py @@ -202,7 +202,7 @@ def question_7(self, answer=None): ) return - msg = "The beamstop was added at the right point in the component sequence!" + msg = "The beamstop was added at the right point in the component sequence and with right parameters!" required_pars = dict(xwidth=0.1, yheight=0.02) self.last_component_in_instr_check( answer=answer, @@ -256,13 +256,37 @@ def question_8(self, answer=None): ) return + beamstop_component = answer.get_component(beamstop_name) + if beamstop_component.AT_data[2] == 2.7: + print_box("The distance to the beamstop was set directly as a number, use the variable name instead. It is the right value though!", False) + return + + alternate_answers = [[0, 0, "0.9*detector_distance"], + [0, 0, "0.90*detector_distance"], + [0, 0, "detector_distance*0.9"], + [0, 0, "detector_distance*0.90"], + [0, 0, "9*detector_distance/10"], + [0, 0, "detector_distance/10*9"], + [0, 0, "detector_distance/10*9.0"], + [0, 0, "detector_distance/10.0*9"], + [0, 0, "detector_distance/10.0*9.0"], + [0, 0, "90/100*detector_distance"], + [0, 0, "90.0/100.0*detector_distance"], + [0, 0, "90/100.0*detector_distance"], + [0, 0, "90.0/100*detector_distance"], + ] + if beamstop_component.AT_data in alternate_answers: + check_AT_answer = beamstop_component.AT_data + else: + check_AT_answer = [0, 0, "0.9*detector_distance"] + msg = "The beamstop was added at the right point in the component sequence and space!" required_pars = dict(xwidth=0.1, yheight=0.02) self.last_component_in_instr_check( answer=answer, comp_type_str="Beamstop", required_AT_relative="sample_position", - required_AT_data=[0, 0, "0.9*detector_distance"], + required_AT_data=check_AT_answer, success_msg=msg, comp_name=beamstop_name, print_output=True,