Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/user-guide/amor/amor-reduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"workflow[Filename[ReferenceRun]] = amor.data.amor_reference_run()\n",
"workflow[Filename[ReferenceRun]] = amor.data.amor_run(614)\n",
"# The sample rotation value in the file is slightly off, so we set it manually\n",
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
"\n",
Expand Down Expand Up @@ -147,14 +147,14 @@
"metadata": {},
"outputs": [],
"source": [
"amor.data.amor_sample_run('608')"
"amor.data.amor_run(608)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When you encounter `amor.data.amor_sample_run` you should imagining replacing that with a path to your own dataset."
"When you encounter `amor.data.amor_run` you should imagining replacing that with a path to your own dataset."
]
},
{
Expand All @@ -168,19 +168,19 @@
" # The sample rotation values in the files are slightly off, so we replace\n",
" # them with corrected values.\n",
" SampleRotation[SampleRun]: sc.scalar(0.85, unit='deg'),\n",
" Filename[SampleRun]: amor.data.amor_sample_run('608'),\n",
" Filename[SampleRun]: amor.data.amor_run(608),\n",
" },\n",
" '609': {\n",
" SampleRotation[SampleRun]: sc.scalar(2.25, unit='deg'),\n",
" Filename[SampleRun]: amor.data.amor_sample_run('609'),\n",
" Filename[SampleRun]: amor.data.amor_run(609),\n",
" },\n",
" '610': {\n",
" SampleRotation[SampleRun]: sc.scalar(3.65, unit='deg'),\n",
" Filename[SampleRun]: amor.data.amor_sample_run('610'),\n",
" Filename[SampleRun]: amor.data.amor_run(610),\n",
" },\n",
" '611': {\n",
" SampleRotation[SampleRun]: sc.scalar(5.05, unit='deg'),\n",
" Filename[SampleRun]: amor.data.amor_sample_run('611'),\n",
" Filename[SampleRun]: amor.data.amor_run(611),\n",
" },\n",
"}\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/amor/compare-to-eos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"workflow[ChopperPhase[ReferenceRun]] = sc.scalar(-7.5, unit='deg')\n",
"# The sample rotation value in the file is slightly off, so we set it manually\n",
"workflow[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit='deg')\n",
"workflow[Filename[ReferenceRun]] = amor.data.amor_reference_run()\n",
"workflow[Filename[ReferenceRun]] = amor.data.amor_run(614)\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above you passed runs as string, but an int here? Should it all be ints?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both work but I agree it's better to be consistent.

"\n",
"reference_result = workflow.compute(ReducedReference)\n",
"# Set the result back onto the pipeline to cache it\n",
Expand Down Expand Up @@ -126,7 +126,7 @@
"for key, angle in mu.items():\n",
" print(key, '... ', end='')\n",
" workflow[SampleRotation[SampleRun]] = sc.scalar(angle + 0.05, unit='deg')\n",
" workflow[Filename[SampleRun]] = amor.data.amor_sample_run(key)\n",
" workflow[Filename[SampleRun]] = amor.data.amor_run(key)\n",
" da = workflow.compute(ReflectivityOverQ).hist()\n",
" da.coords['Q'] = sc.midpoints(da.coords['Q'], dim='Q')\n",
" results['ess'][key] = da\n",
Expand Down
37 changes: 29 additions & 8 deletions src/ess/amor/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
import re

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

Expand Down Expand Up @@ -50,6 +51,24 @@ def _make_pooch():
"611.Rqz.ort": "md5:0c51e8ac5c00041434417673be186151",
"612.Rqz.ort": "md5:d785d27151e7f1edc05e86d35bef6a63",
"613.Rqz.ort": "md5:e999c85f7a47665c4ddd1538b19d402d",
"amor2024n001632.hdf": "md5:2253f0ec6d2e96a986a6aa35d43a7480",
"amor2024n001634.hdf": "md5:7cdd87bbd96fb3fb1e046800a9b1d77e",
"amor2024n001635.hdf": "md5:fb9eb0e7b803c13f1804d085b3b0058f",
"amor2024n001636.hdf": "md5:f7deb51d22652d1f5d0e4b51927af5a3",
"amor2024n001637.hdf": "md5:06e5957d34d82035cfece40cbbf47d7a",
"amor2024n001638.hdf": "md5:1193fe808af2afeb0f48d3b0022fe40b",
"amor2024n001639.hdf": "md5:ff24e31a07c4020927aaa6df9f2ee05f",
"amor2024n001640.hdf": "md5:051335fea1c369322a2328d530dedb77",
"amor2024n001641.hdf": "md5:d543b5890b63707cf8d7f6666e8830a4",
"amor2024n001642.hdf": "md5:b1474e32cc64371e1005f44f2c5b6ae7",
"amor2024n004079.hdf": "md5:5bf1dabc2ff902a57ed7593903c8e1a5",
"amor2024n004080.hdf": "md5:7dcaa5da00b7eedc178b9e55209bfbce",
"amor2024n004081.hdf": "md5:2f4f46f0e56ab75aad0c2933060df504",
"amor2024n004083.hdf": "md5:ffd13420e44cbf966b94bd532e293c1c",
"amor2024n004084.hdf": "md5:5041a9486b3cd6407a9b9f44104c9b54",
"amor2024n004085.hdf": "md5:152ac63bad6f3b2b5cf1c4e4c7df5e30",
"amor2024n004152.hdf": "md5:244459be7a3caeac523c289815c5b7dc",
"amor2024n004154.hdf": "md5:6184553f795fd2b230baab9a421da9e4",
},
)

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


def amor_reference_run() -> Filename[ReferenceRun]:
return Filename[ReferenceRun](_pooch.fetch("amor2023n000614.hdf"))


def amor_sample_run(number: int | str) -> Filename[SampleRun]:
return Filename[SampleRun](_pooch.fetch(f"amor2023n{int(number):06d}.hdf"))
def amor_run(number: int | str) -> Filename[SampleRun]:
fnames = [
name
for name in _pooch.registry.keys()
if re.match(f'amor\\d{{4}}n{int(number):06d}.hdf', name)
]
if len(fnames) != 1:
raise ValueError(f'Expected exactly one matching file, found {len(fnames)}')
return Filename[SampleRun](_pooch.fetch(fnames[0]))


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

__all__ = [
"amor_psi_software_result",
"amor_reference_run",
"amor_sample_run",
"amor_run",
]
22 changes: 11 additions & 11 deletions tests/amor/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def amor_pipeline() -> sciline.Pipeline:
)
# The sample rotation value in the file is slightly off, so we set it manually
pl[SampleRotation[ReferenceRun]] = sc.scalar(0.65, unit="deg")
pl[Filename[ReferenceRun]] = amor.data.amor_reference_run()
pl[Filename[ReferenceRun]] = amor.data.amor_run(614)

pl[orso.OrsoCreator] = orso.OrsoCreator(
fileio.base.Person(
Expand All @@ -65,7 +65,7 @@ def amor_pipeline() -> sciline.Pipeline:
def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
# The sample rotation value in the file is slightly off, so we set it manually
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
assert "Q" in reflectivity_over_q.coords
assert "Q_resolution" in reflectivity_over_q.coords
Expand All @@ -76,7 +76,7 @@ def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
# The sample rotation value in the file is slightly off, so we set it manually
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
amor_pipeline[amor.types.GravityToggle] = False
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
assert "Q" in reflectivity_over_q.coords
Expand All @@ -88,7 +88,7 @@ def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
def test_orso_pipeline(amor_pipeline: sciline.Pipeline):
# The sample rotation value in the file is slightly off, so we set it manually
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
res = amor_pipeline.compute(orso.OrsoIofQDataset)
assert res.info.data_source.experiment.instrument == "Amor"
assert res.info.reduction.software.name == "ess.reflectometry"
Expand All @@ -109,7 +109,7 @@ def test_save_reduced_orso_file(amor_pipeline: sciline.Pipeline, output_folder:
from orsopy import fileio

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

Expand All @@ -120,8 +120,8 @@ def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs(
amor_pipeline: sciline.Pipeline,
):
sample_runs = [
amor.data.amor_sample_run(608),
amor.data.amor_sample_run(609),
amor.data.amor_run(608),
amor.data.amor_run(609),
]
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
Expand All @@ -135,16 +135,16 @@ def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs(
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
def test_pipeline_merging_events_result_unchanged(amor_pipeline: sciline.Pipeline):
sample_runs = [
amor.data.amor_sample_run(608),
amor.data.amor_run(608),
]
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
SampleRotation[SampleRun]
) + sc.scalar(0.05, unit="deg")
result = pipeline.compute(ReflectivityOverQ).hist()
sample_runs = [
amor.data.amor_sample_run(608),
amor.data.amor_sample_run(608),
amor.data.amor_run(608),
amor.data.amor_run(608),
]
pipeline = with_filenames(amor_pipeline, SampleRun, sample_runs)
pipeline[SampleRotation[SampleRun]] = pipeline.compute(
Expand All @@ -162,7 +162,7 @@ def test_pipeline_merging_events_result_unchanged(amor_pipeline: sciline.Pipelin
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
def test_proton_current(amor_pipeline: sciline.Pipeline):
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(611)
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(611)
da_without_proton_current = amor_pipeline.compute(ReducibleData[SampleRun])

proton_current = [1, 2, 0.1]
Expand Down
Loading