Skip to content

Commit 72b5296

Browse files
authored
Merge pull request #89 from scipp/resolution-refactor
refactor: rename ioq to reflectivity and add resolution as coord
2 parents ce78cb1 + 9c09b1f commit 72b5296

File tree

9 files changed

+49
-30
lines changed

9 files changed

+49
-30
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"metadata": {},
8686
"outputs": [],
8787
"source": [
88-
"workflow.visualize(NormalizedIofQ, graph_attr={'rankdir': 'LR'})"
88+
"workflow.visualize(ReflectivityOverQ, graph_attr={'rankdir': 'LR'})"
8989
]
9090
},
9191
{
@@ -128,7 +128,7 @@
128128
"metadata": {},
129129
"outputs": [],
130130
"source": [
131-
"workflow.visualize(NormalizedIofQ, graph_attr={'rankdir': 'LR'})"
131+
"workflow.visualize(ReflectivityOverQ, graph_attr={'rankdir': 'LR'})"
132132
]
133133
},
134134
{
@@ -158,7 +158,7 @@
158158
"for file, angle in runs.items():\n",
159159
" workflow[Filename[SampleRun]] = amor.data.amor_sample_run(file)\n",
160160
" workflow[SampleRotation[SampleRun]] = angle\n",
161-
" results[file] = workflow.compute(NormalizedIofQ).hist()\n",
161+
" results[file] = workflow.compute(ReflectivityOverQ).hist()\n",
162162
"\n",
163163
"sc.plot(results, norm='log', vmin=1e-4)"
164164
]
@@ -185,7 +185,8 @@
185185
"outputs": [],
186186
"source": [
187187
"from ess.reflectometry.tools import combine_curves\n",
188-
"combine_curves(results_scaled.values(), workflow.compute(QBins)).plot(norm='log')"
188+
"c = combine_curves(results_scaled.values(), workflow.compute(QBins))\n",
189+
"c.plot(norm='log')"
189190
]
190191
},
191192
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
" print(key, '... ', end='')\n",
124124
" workflow[SampleRotation[SampleRun]] = sc.scalar(angle + 0.05, unit='deg')\n",
125125
" workflow[Filename[SampleRun]] = amor.data.amor_sample_run(key)\n",
126-
" da = workflow.compute(NormalizedIofQ).hist()\n",
126+
" da = workflow.compute(ReflectivityOverQ).hist()\n",
127127
" da.coords['Q'] = sc.midpoints(da.coords['Q'], dim='Q')\n",
128128
" results['ess'][key] = da\n",
129129
" print('Done!')"

src/ess/amor/load.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
3+
import warnings
4+
from functools import wraps
5+
36
import scipp as sc
47

58
from ess.reduce import nexus
@@ -25,12 +28,33 @@
2528
)
2629

2730

31+
def ignore_amor_warnings(func):
32+
@wraps(func)
33+
def wrapped(*args, **kwargs):
34+
with warnings.catch_warnings():
35+
warnings.filterwarnings(
36+
'ignore',
37+
category=UserWarning,
38+
message=r'Failed to convert .* into a transformation',
39+
)
40+
warnings.filterwarnings(
41+
'ignore',
42+
category=UserWarning,
43+
message='Invalid transformation, missing attribute',
44+
)
45+
return func(*args, **kwargs)
46+
47+
return wrapped
48+
49+
50+
@ignore_amor_warnings
2851
def load_detector(
2952
file_path: Filename[RunType], detector_name: NeXusDetectorName[RunType]
3053
) -> LoadedNeXusDetector[RunType]:
3154
return nexus.load_detector(file_path=file_path, detector_name=detector_name)
3255

3356

57+
@ignore_amor_warnings
3458
def load_events(
3559
detector: LoadedNeXusDetector[RunType], detector_rotation: DetectorRotation[RunType]
3660
) -> RawDetectorData[RunType]:
@@ -108,6 +132,7 @@ def compute_tof(
108132
return ReducibleDetectorData[RunType](data)
109133

110134

135+
@ignore_amor_warnings
111136
def amor_chopper(f: Filename[RunType]) -> RawChopper[RunType]:
112137
return next(load_nx(f, "NXentry/NXinstrument/NXdisk_chopper"))
113138

@@ -140,6 +165,7 @@ def load_amor_ch_frequency(ch: RawChopper[RunType]) -> ChopperFrequency[RunType]
140165
raise ValueError("No unit was found for the chopper frequency")
141166

142167

168+
@ignore_amor_warnings
143169
def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
144170
(mu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/mu")
145171
# Jochens Amor code reads the first value of this log
@@ -148,6 +174,7 @@ def load_amor_sample_rotation(fp: Filename[RunType]) -> SampleRotation[RunType]:
148174
return sc.scalar(mu['value'].data['dim_1', 0]['time', 0].value, unit='deg')
149175

150176

177+
@ignore_amor_warnings
151178
def load_amor_detector_rotation(fp: Filename[RunType]) -> DetectorRotation[RunType]:
152179
(nu,) = load_nx(fp, "NXentry/NXinstrument/master_parameters/nu")
153180
# Jochens Amor code reads the first value of this log

src/ess/amor/orso.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
OrsoIofQDataset,
1515
OrsoReduction,
1616
)
17-
from ..reflectometry.types import NormalizedIofQ, QResolution
17+
from ..reflectometry.types import QResolution, ReflectivityOverQ
1818

1919

20-
def build_orso_instrument(events: NormalizedIofQ) -> OrsoInstrument:
20+
def build_orso_instrument(events: ReflectivityOverQ) -> OrsoInstrument:
2121
"""Build ORSO instrument metadata from intermediate reduction results for Amor.
2222
2323
This assumes specular reflection and sets the incident angle equal to the computed
@@ -33,7 +33,7 @@ def build_orso_instrument(events: NormalizedIofQ) -> OrsoInstrument:
3333

3434

3535
def build_orso_iofq_dataset(
36-
iofq: NormalizedIofQ,
36+
iofq: ReflectivityOverQ,
3737
sigma_q: QResolution,
3838
data_source: OrsoDataSource,
3939
reduction: OrsoReduction,

src/ess/amor/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from ess.reflectometry.types import (
44
DetectorRotation,
5-
NormalizedIofQ,
65
QBins,
76
ReflectivityData,
7+
ReflectivityOverQ,
88
RunType,
99
SampleRotation,
1010
SampleRun,
@@ -112,7 +112,7 @@ def diagnostic_view(
112112
lath: WavelengthThetaFigure,
113113
laz: WavelengthZIndexFigure,
114114
qth: QThetaFigure,
115-
ioq: NormalizedIofQ,
115+
ioq: ReflectivityOverQ,
116116
) -> ReflectivityDiagnosticsView:
117117
ioq = ioq.hist().plot(norm="log")
118118
return (ioq + laz) / (lath + qth)

src/ess/reflectometry/normalize.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
FootprintCorrectedData,
1010
IdealReferenceIntensity,
1111
NormalizationFactor,
12-
NormalizedIofQ,
1312
QBins,
13+
QResolution,
1414
ReflectivityData,
15+
ReflectivityOverQ,
1516
SampleRun,
1617
WavelengthBins,
1718
)
@@ -94,7 +95,8 @@ def reflectivity_over_q(
9495
da: FootprintCorrectedData[SampleRun],
9596
n: NormalizationFactor,
9697
qbins: QBins,
97-
) -> NormalizedIofQ:
98+
qres: QResolution,
99+
) -> ReflectivityOverQ:
98100
"""
99101
Normalize the sample measurement by the (ideally calibrated) supermirror.
100102
@@ -110,9 +112,9 @@ def reflectivity_over_q(
110112
:
111113
Reflectivity as a function of Q
112114
"""
113-
return NormalizedIofQ(
114-
da.bin(Q=qbins, dim=da.dims) / sc.values(n.hist(Q=qbins, dim=n.dims))
115-
)
115+
reflectivity = da.bin(Q=qbins, dim=da.dims) / sc.values(n.hist(Q=qbins, dim=n.dims))
116+
reflectivity.coords['Q_resolution'] = qres.data
117+
return ReflectivityOverQ(reflectivity)
116118

117119

118120
def reflectivity_per_event(

src/ess/reflectometry/reductions.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/ess/reflectometry/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FootprintCorrectedData(sciline.Scope[RunType, sc.DataArray], sc.DataArray)
6464
NormalizationFactor = NewType("NormalizationFactor", sc.DataArray)
6565
""":code`IdealReferenceIntensity` with added coordinate "sample"-Q"""
6666

67-
NormalizedIofQ = NewType("NormalizedIofQ", sc.DataArray)
67+
ReflectivityOverQ = NewType("ReflectivityOverQ", sc.DataArray)
6868
"""Intensity histogram over momentum transfer
6969
normalized by the calibrated reference measurement."""
7070

tests/amor/pipeline_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
from ess.reflectometry import orso
1414
from ess.reflectometry.types import (
1515
Filename,
16-
NormalizedIofQ,
1716
QBins,
1817
ReferenceRun,
18+
ReflectivityOverQ,
1919
SampleRotation,
2020
SampleRun,
2121
SampleSize,
@@ -57,8 +57,9 @@ def amor_pipeline() -> sciline.Pipeline:
5757

5858

5959
def test_run_data_pipeline(amor_pipeline: sciline.Pipeline):
60-
res = amor_pipeline.compute(NormalizedIofQ)
60+
res = amor_pipeline.compute(ReflectivityOverQ)
6161
assert "Q" in res.coords
62+
assert "Q_resolution" in res.coords
6263

6364

6465
def test_run_full_pipeline(amor_pipeline: sciline.Pipeline):

0 commit comments

Comments
 (0)