Skip to content

Commit e43cfaf

Browse files
jokasimrjl-wynen
andauthored
Simplify AMOR/reflectometry workflow (#107)
* simplify the amor workflow --------- Co-authored-by: Jan-Lukas Wynen <[email protected]>
1 parent a9c044e commit e43cfaf

28 files changed

+732
-892
lines changed

docs/user-guide/amor/amor-reduction.ipynb

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,7 @@
4444
"## Create and configure the workflow\n",
4545
"\n",
4646
"We begin by creating the Amor workflow object which is a skeleton for reducing Amor data,\n",
47-
"with pre-configured steps."
48-
]
49-
},
50-
{
51-
"cell_type": "code",
52-
"execution_count": null,
53-
"metadata": {},
54-
"outputs": [],
55-
"source": [
56-
"workflow = amor.AmorWorkflow()"
57-
]
58-
},
59-
{
60-
"cell_type": "markdown",
61-
"metadata": {},
62-
"source": [
63-
"We then need to set the missing parameters which are specific to each experiment:"
47+
"with pre-configured steps, and then set the missing parameters which are specific to each experiment:"
6448
]
6549
},
6650
{
@@ -69,20 +53,22 @@
6953
"metadata": {},
7054
"outputs": [],
7155
"source": [
56+
"workflow = amor.AmorWorkflow()\n",
7257
"workflow[SampleSize[SampleRun]] = sc.scalar(10.0, unit='mm')\n",
7358
"workflow[SampleSize[ReferenceRun]] = sc.scalar(10.0, unit='mm')\n",
7459
"\n",
7560
"workflow[ChopperPhase[ReferenceRun]] = sc.scalar(-7.5, unit='deg')\n",
7661
"workflow[ChopperPhase[SampleRun]] = sc.scalar(-7.5, unit='deg')\n",
7762
"\n",
7863
"workflow[QBins] = sc.geomspace(dim='Q', start=0.005, stop=0.3, num=391, unit='1/angstrom')\n",
79-
"workflow[WavelengthBins] = sc.geomspace('wavelength', 2.8, 12, 301, unit='angstrom')\n",
64+
"workflow[WavelengthBins] = sc.geomspace('wavelength', 2.8, 12.5, 2001, unit='angstrom')\n",
8065
"\n",
8166
"# The YIndexLimits and ZIndexLimits define ranges on the detector where\n",
8267
"# data is considered to be valid signal.\n",
8368
"# They represent the lower and upper boundaries of a range of pixel indices.\n",
84-
"workflow[YIndexLimits] = sc.scalar(11, unit=None), sc.scalar(41, unit=None)\n",
85-
"workflow[ZIndexLimits] = sc.scalar(80, unit=None), sc.scalar(370, unit=None)"
69+
"workflow[YIndexLimits] = sc.scalar(11), sc.scalar(41)\n",
70+
"workflow[ZIndexLimits] = sc.scalar(80), sc.scalar(370)\n",
71+
"workflow[BeamDivergenceLimits] = sc.scalar(-0.75, unit='deg'), sc.scalar(0.75, unit='deg')"
8672
]
8773
},
8874
{
@@ -116,9 +102,9 @@
116102
"# The sample rotation value in the file is slightly off, so we set it manually\n",
117103
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
118104
"\n",
119-
"reference_result = workflow.compute(IdealReferenceIntensity)\n",
105+
"reference_result = workflow.compute(ReducedReference)\n",
120106
"# Set the result back onto the pipeline to cache it\n",
121-
"workflow[IdealReferenceIntensity] = reference_result"
107+
"workflow[ReducedReference] = reference_result"
122108
]
123109
},
124110
{
@@ -198,6 +184,7 @@
198184
" },\n",
199185
"}\n",
200186
"\n",
187+
"\n",
201188
"reflectivity = {}\n",
202189
"for run_number, params in runs.items():\n",
203190
" workflow[Filename[SampleRun]] = params[Filename[SampleRun]]\n",
@@ -282,11 +269,20 @@
282269
"for run_number, params in runs.items():\n",
283270
" workflow[Filename[SampleRun]] = params[Filename[SampleRun]]\n",
284271
" workflow[SampleRotation[SampleRun]] = params[SampleRotation[SampleRun]]\n",
285-
" diagnostics[run_number] = workflow.compute((ReflectivityData, ThetaBins[SampleRun]))\n",
272+
" diagnostics[run_number] = workflow.compute((ReflectivityOverZW, ThetaBins[SampleRun]))\n",
286273
"\n",
287274
"# Scale the results using the scale factors computed earlier\n",
288275
"for run_number, scale_factor in zip(reflectivity.keys(), scale_factors, strict=True):\n",
289-
" diagnostics[run_number][ReflectivityData] *= scale_factor"
276+
" diagnostics[run_number][ReflectivityOverZW] *= scale_factor"
277+
]
278+
},
279+
{
280+
"cell_type": "code",
281+
"execution_count": null,
282+
"metadata": {},
283+
"outputs": [],
284+
"source": [
285+
"diagnostics['608'][ReflectivityOverZW].hist().flatten(('blade', 'wire'), to='z').plot(norm='log')"
290286
]
291287
},
292288
{
@@ -306,7 +302,7 @@
306302
"from ess.amor.figures import wavelength_theta_figure\n",
307303
"\n",
308304
"wavelength_theta_figure(\n",
309-
" [result[ReflectivityData] for result in diagnostics.values()],\n",
305+
" [result[ReflectivityOverZW] for result in diagnostics.values()],\n",
310306
" theta_bins=[result[ThetaBins[SampleRun]] for result in diagnostics.values()],\n",
311307
" q_edges_to_display=(sc.scalar(0.018, unit='1/angstrom'), sc.scalar(0.113, unit='1/angstrom'))\n",
312308
")"
@@ -336,7 +332,7 @@
336332
"from ess.amor.figures import q_theta_figure\n",
337333
"\n",
338334
"q_theta_figure(\n",
339-
" [res[ReflectivityData] for res in diagnostics.values()],\n",
335+
" [res[ReflectivityOverZW] for res in diagnostics.values()],\n",
340336
" theta_bins=[res[ThetaBins[SampleRun]] for res in diagnostics.values()],\n",
341337
" q_bins=workflow.compute(QBins)\n",
342338
")"
@@ -364,11 +360,11 @@
364360
"workflow[Filename[SampleRun]] = runs['608'][Filename[SampleRun]]\n",
365361
"workflow[SampleRotation[SampleRun]] = runs['608'][SampleRotation[SampleRun]]\n",
366362
"wavelength_z_figure(\n",
367-
" workflow.compute(FootprintCorrectedData[SampleRun]),\n",
363+
" workflow.compute(Sample),\n",
368364
" wavelength_bins=workflow.compute(WavelengthBins),\n",
369365
" grid=False\n",
370366
") + wavelength_z_figure(\n",
371-
" reference_result,\n",
367+
" workflow.compute(Reference),\n",
372368
" grid=False\n",
373369
")"
374370
]
@@ -455,24 +451,6 @@
455451
")"
456452
]
457453
},
458-
{
459-
"cell_type": "markdown",
460-
"metadata": {},
461-
"source": [
462-
"To support tracking provenance, we also list the corrections that were done by the workflow and store them in the dataset:"
463-
]
464-
},
465-
{
466-
"cell_type": "code",
467-
"execution_count": null,
468-
"metadata": {},
469-
"outputs": [],
470-
"source": [
471-
"iofq_dataset.info.reduction.corrections = orso.find_corrections(\n",
472-
" workflow.get(orso.OrsoIofQDataset)\n",
473-
")"
474-
]
475-
},
476454
{
477455
"cell_type": "markdown",
478456
"metadata": {},

docs/user-guide/amor/compare-to-eos.ipynb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,22 @@
8585
"workflow[SampleSize[ReferenceRun]] = sc.scalar(10.0, unit='mm')\n",
8686
"workflow[ChopperPhase[SampleRun]] = sc.scalar(-7.5, unit='deg')\n",
8787
"\n",
88-
"# In Jochens workflow:\n",
89-
"# * divergence mask: [-0.7, 0.7]\n",
90-
"# * note, divergence relative to beam center\n",
9188
"workflow[WavelengthBins] = sc.geomspace('wavelength', 2.8, 12.5, 301, unit='angstrom')\n",
9289
"workflow[QBins] = sc.geomspace(\n",
9390
" dim='Q', start=0.00505, stop=2.93164766e-01, num=391, unit='1/angstrom'\n",
9491
")\n",
95-
"workflow[YIndexLimits] = sc.scalar(11, unit=None), sc.scalar(41, unit=None)\n",
96-
"workflow[ZIndexLimits] = sc.scalar(80, unit=None), sc.scalar(370, unit=None)\n",
92+
"workflow[YIndexLimits] = sc.scalar(11), sc.scalar(41)\n",
93+
"workflow[ZIndexLimits] = sc.scalar(80), sc.scalar(370)\n",
9794
"\n",
9895
"# Chopper phase value in the file is wrong, so we set it manually\n",
9996
"workflow[ChopperPhase[ReferenceRun]] = sc.scalar(-7.5, unit='deg')\n",
10097
"# The sample rotation value in the file is slightly off, so we set it manually\n",
10198
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
10299
"workflow[Filename[ReferenceRun]] = amor.data.amor_reference_run()\n",
103100
"\n",
104-
"reference_result = workflow.compute(IdealReferenceIntensity)\n",
101+
"reference_result = workflow.compute(ReducedReference)\n",
105102
"# Set the result back onto the pipeline to cache it\n",
106-
"workflow[IdealReferenceIntensity] = reference_result"
103+
"workflow[ReducedReference] = reference_result"
107104
]
108105
},
109106
{

src/ess/amor/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@
55
import sciline
66
import scipp as sc
77

8+
89
from ..reflectometry import providers as reflectometry_providers
910
from ..reflectometry import supermirror
1011
from ..reflectometry.types import (
1112
BeamSize,
1213
DetectorSpatialResolution,
13-
Gravity,
1414
NeXusDetectorName,
1515
RunType,
1616
SamplePosition,
1717
BeamDivergenceLimits,
1818
)
19-
from . import conversions, load, orso, resolution, utils, figures
19+
from . import (
20+
conversions,
21+
load,
22+
orso,
23+
resolution,
24+
utils,
25+
figures,
26+
normalization,
27+
workflow,
28+
)
2029
from .instrument_view import instrument_view
2130
from .types import (
2231
AngularResolution,
23-
Chopper1Position,
24-
Chopper2Position,
2532
ChopperFrequency,
2633
ChopperPhase,
2734
QThetaFigure,
@@ -42,10 +49,11 @@
4249
*reflectometry_providers,
4350
*load.providers,
4451
*conversions.providers,
45-
*resolution.providers,
52+
*normalization.providers,
4653
*utils.providers,
4754
*figures.providers,
4855
*orso.providers,
56+
*workflow.providers,
4957
)
5058
"""
5159
List of providers for setting up a Sciline pipeline.
@@ -61,12 +69,14 @@ def default_parameters() -> dict:
6169
supermirror.Alpha: sc.scalar(0.25 / 0.088, unit=sc.units.angstrom),
6270
BeamSize[RunType]: 2.0 * sc.units.mm,
6371
DetectorSpatialResolution[RunType]: 0.0025 * sc.units.m,
64-
Gravity: sc.vector(value=[0, -1, 0]) * sc.constants.g,
6572
SamplePosition[RunType]: sc.vector([0, 0, 0], unit="m"),
6673
NeXusDetectorName[RunType]: "detector",
6774
ChopperPhase[RunType]: sc.scalar(7.0, unit="deg"),
6875
ChopperFrequency[RunType]: sc.scalar(8.333, unit="Hz"),
69-
BeamDivergenceLimits: (sc.scalar(-0.7, unit='deg'), sc.scalar(0.7, unit='deg')),
76+
BeamDivergenceLimits: (
77+
sc.scalar(-0.75, unit='deg'),
78+
sc.scalar(0.75, unit='deg'),
79+
),
7080
}
7181

7282

0 commit comments

Comments
 (0)