From 9a259ff65c48bfac93210b1d2d81e28624b99a38 Mon Sep 17 00:00:00 2001 From: Neil Vaytet Date: Thu, 30 Jan 2025 11:31:18 +0100 Subject: [PATCH 1/2] update docs index --- docs/user-guide/dream/index.md | 1 + .../workflows/dream-proton-charge-norm.ipynb | 189 ++++++++++++++++++ docs/user-guide/dream/workflows/index.md | 9 + 3 files changed, 199 insertions(+) create mode 100644 docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb create mode 100644 docs/user-guide/dream/workflows/index.md diff --git a/docs/user-guide/dream/index.md b/docs/user-guide/dream/index.md index 5a5281fc..4411af06 100644 --- a/docs/user-guide/dream/index.md +++ b/docs/user-guide/dream/index.md @@ -5,6 +5,7 @@ maxdepth: 1 --- +workflows/index dream-data-reduction dream-instrument-view workflow-widget-dream diff --git a/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb b/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb new file mode 100644 index 00000000..32b9edb4 --- /dev/null +++ b/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb @@ -0,0 +1,189 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0", + "metadata": {}, + "source": [ + "# DREAM data reduction - Normalized by proton charge" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1", + "metadata": {}, + "outputs": [], + "source": [ + "import scipp as sc\n", + "\n", + "from ess import dream, powder\n", + "import ess.dream.data # noqa: F401\n", + "from ess.powder.types import *" + ] + }, + { + "cell_type": "markdown", + "id": "2", + "metadata": {}, + "source": [ + "## Create and configure the workflow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3", + "metadata": {}, + "outputs": [], + "source": [ + "workflow = dream.DreamGeant4Workflow(run_norm=powder.RunNormalization.proton_charge)" + ] + }, + { + "cell_type": "markdown", + "id": "4", + "metadata": {}, + "source": [ + "### Files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9f1994d-a646-41d6-9197-8c7f1d22d738", + "metadata": {}, + "outputs": [], + "source": [ + "workflow[Filename[SampleRun]] = dream.data.simulated_diamond_sample()\n", + "workflow[Filename[VanadiumRun]] = dream.data.simulated_vanadium_sample()\n", + "workflow[Filename[BackgroundRun]] = dream.data.simulated_empty_can()\n", + "workflow[CalibrationFilename] = None" + ] + }, + { + "cell_type": "markdown", + "id": "a8163eb6-a981-4463-b16c-85afdd5d8091", + "metadata": {}, + "source": [ + "### Masks" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76f070d3-35ff-473d-aebd-013cd254713b", + "metadata": {}, + "outputs": [], + "source": [ + "workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit=\"ns\")) | (\n", + " x > sc.scalar(86e6, unit=\"ns\")\n", + ")\n", + "workflow[TwoThetaMask] = None\n", + "workflow[WavelengthMask] = None\n", + "workflow = powder.with_pixel_mask_filenames(workflow, [])" + ] + }, + { + "cell_type": "markdown", + "id": "7a7ad64d-b124-49e2-b655-92ba8d5669c1", + "metadata": {}, + "source": [ + "### Other parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2b6b8d3b-d196-490f-b89f-762616958110", + "metadata": {}, + "outputs": [], + "source": [ + "workflow[NeXusDetectorName] = \"mantle\"\n", + "workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop\n", + "workflow[DspacingBins] = sc.linspace(\"dspacing\", 0.0, 2.3434, 201, unit=\"angstrom\")" + ] + }, + { + "cell_type": "markdown", + "id": "6", + "metadata": {}, + "source": [ + "## Use the workflow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9", + "metadata": {}, + "outputs": [], + "source": [ + "results = workflow.compute([IofTof, ReducedTofCIF])" + ] + }, + { + "cell_type": "markdown", + "id": "37d94b62-8068-4301-939d-01c97ce1cfed", + "metadata": {}, + "source": [ + "## Plot and save" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10", + "metadata": {}, + "outputs": [], + "source": [ + "results[IofTof].hist().plot()" + ] + }, + { + "cell_type": "markdown", + "id": "11", + "metadata": {}, + "source": [ + "We can now save the result to disk:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "12", + "metadata": {}, + "outputs": [], + "source": [ + "cif_data = results[ReducedTofCIF]\n", + "\n", + "cif_data.comment = \"\"\"This file was generated with the DREAM data reduction user guide\n", + "in the documentation of ESSdiffraction.\n", + "See https://scipp.github.io/essdiffraction/\n", + "\"\"\"\n", + "cif_data.save('reduced.cif')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/user-guide/dream/workflows/index.md b/docs/user-guide/dream/workflows/index.md new file mode 100644 index 00000000..aa0ea0a0 --- /dev/null +++ b/docs/user-guide/dream/workflows/index.md @@ -0,0 +1,9 @@ +# DREAM reduction workflows + +```{toctree} +--- +maxdepth: 1 +--- + +dream-proton-charge-norm +``` From f0cdc910155be6154ddafa84bacb59ae0a58f1be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Thu, 30 Jan 2025 10:32:45 +0000 Subject: [PATCH 2/2] Apply automatic formatting --- .../workflows/dream-proton-charge-norm.ipynb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb b/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb index 32b9edb4..0af60e31 100644 --- a/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb +++ b/docs/user-guide/dream/workflows/dream-proton-charge-norm.ipynb @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c9f1994d-a646-41d6-9197-8c7f1d22d738", + "id": "5", "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "markdown", - "id": "a8163eb6-a981-4463-b16c-85afdd5d8091", + "id": "6", "metadata": {}, "source": [ "### Masks" @@ -72,7 +72,7 @@ { "cell_type": "code", "execution_count": null, - "id": "76f070d3-35ff-473d-aebd-013cd254713b", + "id": "7", "metadata": {}, "outputs": [], "source": [ @@ -86,7 +86,7 @@ }, { "cell_type": "markdown", - "id": "7a7ad64d-b124-49e2-b655-92ba8d5669c1", + "id": "8", "metadata": {}, "source": [ "### Other parameters" @@ -95,7 +95,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2b6b8d3b-d196-490f-b89f-762616958110", + "id": "9", "metadata": {}, "outputs": [], "source": [ @@ -106,7 +106,7 @@ }, { "cell_type": "markdown", - "id": "6", + "id": "10", "metadata": {}, "source": [ "## Use the workflow" @@ -115,7 +115,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9", + "id": "11", "metadata": {}, "outputs": [], "source": [ @@ -124,7 +124,7 @@ }, { "cell_type": "markdown", - "id": "37d94b62-8068-4301-939d-01c97ce1cfed", + "id": "12", "metadata": {}, "source": [ "## Plot and save" @@ -133,7 +133,7 @@ { "cell_type": "code", "execution_count": null, - "id": "10", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -142,7 +142,7 @@ }, { "cell_type": "markdown", - "id": "11", + "id": "14", "metadata": {}, "source": [ "We can now save the result to disk:" @@ -151,7 +151,7 @@ { "cell_type": "code", "execution_count": null, - "id": "12", + "id": "15", "metadata": {}, "outputs": [], "source": [