Skip to content

Commit f1c083c

Browse files
authored
Merge pull request #152 from scipp/update-example-files
docs: add more example files and change data fetching functions
2 parents 812298a + 94335f6 commit f1c083c

File tree

4 files changed

+49
-28
lines changed

4 files changed

+49
-28
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"workflow[Filename[ReferenceRun]] = amor.data.amor_reference_run()\n",
101+
"workflow[Filename[ReferenceRun]] = amor.data.amor_run(614)\n",
102102
"# The sample rotation value in the file is slightly off, so we set it manually\n",
103103
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
104104
"\n",
@@ -147,14 +147,14 @@
147147
"metadata": {},
148148
"outputs": [],
149149
"source": [
150-
"amor.data.amor_sample_run('608')"
150+
"amor.data.amor_run(608)"
151151
]
152152
},
153153
{
154154
"cell_type": "markdown",
155155
"metadata": {},
156156
"source": [
157-
"When you encounter `amor.data.amor_sample_run` you should imagining replacing that with a path to your own dataset."
157+
"When you encounter `amor.data.amor_run` you should imagining replacing that with a path to your own dataset."
158158
]
159159
},
160160
{
@@ -168,19 +168,19 @@
168168
" # The sample rotation values in the files are slightly off, so we replace\n",
169169
" # them with corrected values.\n",
170170
" SampleRotation[SampleRun]: sc.scalar(0.85, unit='deg'),\n",
171-
" Filename[SampleRun]: amor.data.amor_sample_run('608'),\n",
171+
" Filename[SampleRun]: amor.data.amor_run(608),\n",
172172
" },\n",
173173
" '609': {\n",
174174
" SampleRotation[SampleRun]: sc.scalar(2.25, unit='deg'),\n",
175-
" Filename[SampleRun]: amor.data.amor_sample_run('609'),\n",
175+
" Filename[SampleRun]: amor.data.amor_run(609),\n",
176176
" },\n",
177177
" '610': {\n",
178178
" SampleRotation[SampleRun]: sc.scalar(3.65, unit='deg'),\n",
179-
" Filename[SampleRun]: amor.data.amor_sample_run('610'),\n",
179+
" Filename[SampleRun]: amor.data.amor_run(610),\n",
180180
" },\n",
181181
" '611': {\n",
182182
" SampleRotation[SampleRun]: sc.scalar(5.05, unit='deg'),\n",
183-
" Filename[SampleRun]: amor.data.amor_sample_run('611'),\n",
183+
" Filename[SampleRun]: amor.data.amor_run(611),\n",
184184
" },\n",
185185
"}\n",
186186
"\n",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"workflow[ChopperPhase[ReferenceRun]] = sc.scalar(-7.5, unit='deg')\n",
9898
"# The sample rotation value in the file is slightly off, so we set it manually\n",
9999
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
100-
"workflow[Filename[ReferenceRun]] = amor.data.amor_reference_run()\n",
100+
"workflow[Filename[ReferenceRun]] = amor.data.amor_run(614)\n",
101101
"\n",
102102
"reference_result = workflow.compute(ReducedReference)\n",
103103
"# Set the result back onto the pipeline to cache it\n",
@@ -126,7 +126,7 @@
126126
"for key, angle in mu.items():\n",
127127
" print(key, '... ', end='')\n",
128128
" workflow[SampleRotation[SampleRun]] = sc.scalar(angle + 0.05, unit='deg')\n",
129-
" workflow[Filename[SampleRun]] = amor.data.amor_sample_run(key)\n",
129+
" workflow[Filename[SampleRun]] = amor.data.amor_run(key)\n",
130130
" da = workflow.compute(ReflectivityOverQ).hist()\n",
131131
" da.coords['Q'] = sc.midpoints(da.coords['Q'], dim='Q')\n",
132132
" results['ess'][key] = da\n",

src/ess/amor/data.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
3+
import re
34

45
from ..reflectometry.types import Filename, ReferenceRun, SampleRun
56

@@ -50,6 +51,24 @@ def _make_pooch():
5051
"611.Rqz.ort": "md5:0c51e8ac5c00041434417673be186151",
5152
"612.Rqz.ort": "md5:d785d27151e7f1edc05e86d35bef6a63",
5253
"613.Rqz.ort": "md5:e999c85f7a47665c4ddd1538b19d402d",
54+
"amor2024n001632.hdf": "md5:2253f0ec6d2e96a986a6aa35d43a7480",
55+
"amor2024n001634.hdf": "md5:7cdd87bbd96fb3fb1e046800a9b1d77e",
56+
"amor2024n001635.hdf": "md5:fb9eb0e7b803c13f1804d085b3b0058f",
57+
"amor2024n001636.hdf": "md5:f7deb51d22652d1f5d0e4b51927af5a3",
58+
"amor2024n001637.hdf": "md5:06e5957d34d82035cfece40cbbf47d7a",
59+
"amor2024n001638.hdf": "md5:1193fe808af2afeb0f48d3b0022fe40b",
60+
"amor2024n001639.hdf": "md5:ff24e31a07c4020927aaa6df9f2ee05f",
61+
"amor2024n001640.hdf": "md5:051335fea1c369322a2328d530dedb77",
62+
"amor2024n001641.hdf": "md5:d543b5890b63707cf8d7f6666e8830a4",
63+
"amor2024n001642.hdf": "md5:b1474e32cc64371e1005f44f2c5b6ae7",
64+
"amor2024n004079.hdf": "md5:5bf1dabc2ff902a57ed7593903c8e1a5",
65+
"amor2024n004080.hdf": "md5:7dcaa5da00b7eedc178b9e55209bfbce",
66+
"amor2024n004081.hdf": "md5:2f4f46f0e56ab75aad0c2933060df504",
67+
"amor2024n004083.hdf": "md5:ffd13420e44cbf966b94bd532e293c1c",
68+
"amor2024n004084.hdf": "md5:5041a9486b3cd6407a9b9f44104c9b54",
69+
"amor2024n004085.hdf": "md5:152ac63bad6f3b2b5cf1c4e4c7df5e30",
70+
"amor2024n004152.hdf": "md5:244459be7a3caeac523c289815c5b7dc",
71+
"amor2024n004154.hdf": "md5:6184553f795fd2b230baab9a421da9e4",
5372
},
5473
)
5574

@@ -65,12 +84,15 @@ def amor_old_reference_run() -> Filename[ReferenceRun]:
6584
return Filename[ReferenceRun](_pooch.fetch("reference.nxs"))
6685

6786

68-
def amor_reference_run() -> Filename[ReferenceRun]:
69-
return Filename[ReferenceRun](_pooch.fetch("amor2023n000614.hdf"))
70-
71-
72-
def amor_sample_run(number: int | str) -> Filename[SampleRun]:
73-
return Filename[SampleRun](_pooch.fetch(f"amor2023n{int(number):06d}.hdf"))
87+
def amor_run(number: int | str) -> Filename[SampleRun]:
88+
fnames = [
89+
name
90+
for name in _pooch.registry.keys()
91+
if re.match(f'amor\\d{{4}}n{int(number):06d}.hdf', name)
92+
]
93+
if len(fnames) != 1:
94+
raise ValueError(f'Expected exactly one matching file, found {len(fnames)}')
95+
return Filename[SampleRun](_pooch.fetch(fnames[0]))
7496

7597

7698
def amor_psi_software_result(number: int | str) -> Filename[SampleRun]:
@@ -79,6 +101,5 @@ def amor_psi_software_result(number: int | str) -> Filename[SampleRun]:
79101

80102
__all__ = [
81103
"amor_psi_software_result",
82-
"amor_reference_run",
83-
"amor_sample_run",
104+
"amor_run",
84105
]

tests/amor/pipeline_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def amor_pipeline() -> sciline.Pipeline:
4848
)
4949
# The sample rotation value in the file is slightly off, so we set it manually
5050
pl[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit="deg")
51-
pl[Filename[ReferenceRun]] = amor.data.amor_reference_run()
51+
pl[Filename[ReferenceRun]] = amor.data.amor_run(614)
5252

5353
pl[orso.OrsoCreator] = orso.OrsoCreator(
5454
fileio.base.Person(
@@ -65,7 +65,7 @@ def amor_pipeline() -> sciline.Pipeline:
6565
def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
6666
# The sample rotation value in the file is slightly off, so we set it manually
6767
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
68-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
68+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
6969
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
7070
assert "Q" in reflectivity_over_q.coords
7171
assert "Q_resolution" in reflectivity_over_q.coords
@@ -76,7 +76,7 @@ def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
7676
def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
7777
# The sample rotation value in the file is slightly off, so we set it manually
7878
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
79-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
79+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
8080
amor_pipeline[amor.types.GravityToggle] = False
8181
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
8282
assert "Q" in reflectivity_over_q.coords
@@ -88,7 +88,7 @@ def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
8888
def test_orso_pipeline(amor_pipeline: sciline.Pipeline):
8989
# The sample rotation value in the file is slightly off, so we set it manually
9090
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
91-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
91+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
9292
res = amor_pipeline.compute(orso.OrsoIofQDataset)
9393
assert res.info.data_source.experiment.instrument == "Amor"
9494
assert res.info.reduction.software.name == "ess.reflectometry"
@@ -109,7 +109,7 @@ def test_save_reduced_orso_file(amor_pipeline: sciline.Pipeline, output_folder:
109109
from orsopy import fileio
110110

111111
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
112-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
112+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
113113
res = amor_pipeline.compute(orso.OrsoIofQDataset)
114114
fileio.orso.save_orso(datasets=[res], fname=output_folder / 'amor_reduced_iofq.ort')
115115

@@ -120,8 +120,8 @@ def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs(
120120
amor_pipeline: sciline.Pipeline,
121121
):
122122
sample_runs = [
123-
amor.data.amor_sample_run(608),
124-
amor.data.amor_sample_run(609),
123+
amor.data.amor_run(608),
124+
amor.data.amor_run(609),
125125
]
126126
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
127127
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
@@ -135,16 +135,16 @@ def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs(
135135
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
136136
def test_pipeline_merging_events_result_unchanged(amor_pipeline: sciline.Pipeline):
137137
sample_runs = [
138-
amor.data.amor_sample_run(608),
138+
amor.data.amor_run(608),
139139
]
140140
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
141141
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
142142
SampleRotation[SampleRun]
143143
) + sc.scalar(0.05, unit="deg")
144144
result = pipeline.compute(ReflectivityOverQ).hist()
145145
sample_runs = [
146-
amor.data.amor_sample_run(608),
147-
amor.data.amor_sample_run(608),
146+
amor.data.amor_run(608),
147+
amor.data.amor_run(608),
148148
]
149149
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
150150
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
@@ -162,7 +162,7 @@ def test_pipeline_merging_events_result_unchanged(amor_pipeline: sciline.Pipelin
162162
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
163163
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
164164
def test_proton_current(amor_pipeline: sciline.Pipeline):
165-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(611)
165+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(611)
166166
da_without_proton_current = amor_pipeline.compute(ReducibleData[SampleRun])
167167

168168
proton_current = [1, 2, 0.1]

0 commit comments

Comments
 (0)