-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite the Amor workflow using Sciline
- Loading branch information
1 parent
7058109
commit 59621bf
Showing
13 changed files
with
616 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Divergent data reduction for Amor\n", | ||
"\n", | ||
"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", | ||
"\n", | ||
"We will begin by importing the modules that are necessary for this notebook." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import scipp as sc\n", | ||
"import sciline\n", | ||
"from essreflectometry.amor import providers, default_parameters\n", | ||
"from essreflectometry.reflectometry.types import *\n", | ||
"from essreflectometry.amor.types import SampleRotation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"params={\n", | ||
" **default_parameters,\n", | ||
" QBins: sc.geomspace(dim='Q', start=0.008, stop=0.075, num=200, unit='1/angstrom'),\n", | ||
" SampleRotation[Sample]: sc.scalar(0.7989, unit='deg'),\n", | ||
" Filename[Sample]: \"sample.nxs\",\n", | ||
" SampleRotation[Reference]: sc.scalar(0.8389, unit='deg'),\n", | ||
" Filename[Reference]: \"reference.nxs\",\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pipeline = sciline.Pipeline(\n", | ||
" providers,\n", | ||
" params=params\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pipeline.visualize((NormalizedIOfQ, QStd), graph_attr={'rankdir': 'LR'})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Compute I over Q and the standard deviation of Q\n", | ||
"ioq, qstd = pipeline.compute((NormalizedIOfQ, QStd)).values()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"fig = plt.figure(figsize=(5, 7))\n", | ||
"ax1 = fig.add_axes([0, 0.55, 1.0, 0.45])\n", | ||
"ax2 = fig.add_axes([0, 0.0, 1.0, 0.45])\n", | ||
"cax = fig.add_axes([1.05, 0.55, 0.03, 0.45])\n", | ||
"fig1 = ioq.plot(norm='log', ax=ax1, cax=cax, grid=True)\n", | ||
"fig2 = ioq.mean('detector_number').plot(norm='log', ax=ax2, grid=True)\n", | ||
"fig1.canvas.xrange = fig2.canvas.xrange" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Make a $(\\lambda, \\theta)$ map\n", | ||
"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." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from essreflectometry.reflectometry.types import ThetaData\n", | ||
"pipeline.compute(ThetaData[Sample])\\\n", | ||
" .bins.concat('detector_number')\\\n", | ||
" .hist(\n", | ||
" theta=sc.linspace(dim='theta', start=0.0, stop=1.2, num=165, unit='deg').to(unit='rad'),\n", | ||
" wavelength=sc.linspace(dim='wavelength', start=0, stop=15.0, num=165, unit='angstrom'),\n", | ||
" )\\\n", | ||
" .plot()\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"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$." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "essreflectometry", | ||
"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.10.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) | ||
# flake8: noqa: F401 | ||
from . import calibrations, conversions, data, normalize, resolution, tools | ||
from .beamline import instrument_view_components, make_beamline | ||
from itertools import chain | ||
|
||
import scipp as sc | ||
from scipp.constants import g | ||
|
||
from ..reflectometry import providers as reflectometry_providers | ||
from ..reflectometry.types import Run | ||
from . import beamline, calibrations, conversions, load, normalize, resolution, tools | ||
|
||
# from .beamline import instrument_view_components | ||
from .instrument_view import instrument_view | ||
from .load import load | ||
from .types import * | ||
|
||
providers = list( | ||
chain( | ||
reflectometry_providers, | ||
load.providers, | ||
calibrations.providers, | ||
conversions.providers, | ||
normalize.providers, | ||
resolution.providers, | ||
beamline.providers, | ||
) | ||
) | ||
|
||
default_parameters = { | ||
Supermirror[MValue]: sc.scalar(5, unit=sc.units.dimensionless), | ||
Supermirror[CriticalEdge]: 0.022 * sc.Unit('1/angstrom'), | ||
Supermirror[Alpha]: sc.scalar(0.25 / 0.088, unit=sc.units.angstrom), | ||
BeamSize[Run]: 2.0 * sc.units.mm, | ||
SampleSize[Run]: 10.0 * sc.units.mm, | ||
DetectorSpatialResolution[Run]: 0.0025 * sc.units.m, | ||
Gravity: sc.vector(value=[0, -1, 0]) * g, | ||
ChopperFrequency[Run]: sc.scalar(20 / 3, unit='Hz'), | ||
ChopperPhase[Run]: sc.scalar(-8.0, unit='deg'), | ||
Chopper1Position[Run]: sc.vector(value=[0, 0, -15.5], unit='m'), | ||
Chopper2Position[Run]: sc.vector(value=[0, 0, -14.5], unit='m'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.