diff --git a/src/ess/amor/data.py b/src/ess/amor/data.py index 2129e383..34a614ac 100644 --- a/src/ess/amor/data.py +++ b/src/ess/amor/data.py @@ -2,8 +2,6 @@ # Copyright (c) 2025 Scipp contributors (https://github.com/scipp) import re -from ..reflectometry.types import Filename, ReferenceRun, SampleRun - _version = "2" @@ -76,15 +74,15 @@ def _make_pooch(): _pooch = _make_pooch() -def amor_old_sample_run() -> Filename[SampleRun]: - return Filename[SampleRun](_pooch.fetch("sample.nxs")) +def amor_old_sample_run() -> str: + return _pooch.fetch("sample.nxs") -def amor_old_reference_run() -> Filename[ReferenceRun]: - return Filename[ReferenceRun](_pooch.fetch("reference.nxs")) +def amor_old_reference_run() -> str: + return _pooch.fetch("reference.nxs") -def amor_run(number: int | str) -> Filename[SampleRun]: +def amor_run(number: int | str) -> str: fnames = [ name for name in _pooch.registry.keys() @@ -92,11 +90,11 @@ def amor_run(number: int | str) -> Filename[SampleRun]: ] if len(fnames) != 1: raise ValueError(f'Expected exactly one matching file, found {len(fnames)}') - return Filename[SampleRun](_pooch.fetch(fnames[0])) + return _pooch.fetch(fnames[0]) -def amor_psi_software_result(number: int | str) -> Filename[SampleRun]: - return Filename[SampleRun](_pooch.fetch(f"{int(number):03d}.Rqz.ort")) +def amor_psi_software_result(number: int | str) -> str: + return _pooch.fetch(f"{int(number):03d}.Rqz.ort") __all__ = [ diff --git a/src/ess/reflectometry/gui.py b/src/ess/reflectometry/gui.py index 7162e66a..bf282332 100644 --- a/src/ess/reflectometry/gui.py +++ b/src/ess/reflectometry/gui.py @@ -2,6 +2,7 @@ # Copyright (c) 2025 Scipp contributors (https://github.com/scipp) import glob import os +import re import uuid from collections.abc import Callable @@ -902,7 +903,12 @@ def toggle_line(name, value, figure): self.plot_log.children = (box, *self.plot_log.children) def get_filepath_from_run(self, run): - return os.path.join(self.path, f'amor2024n{run:0>6}.hdf') + fname = next( + name + for name in os.listdir(self.path) + if re.match(f'amor\\d{{4}}n{int(run):06d}.hdf', name) + ) + return os.path.join(self.path, fname) def get_row_key(self, row): reference_metadata = ( diff --git a/tests/amor/pipeline_test.py b/tests/amor/pipeline_test.py index 4f119eb5..c09ab2ce 100644 --- a/tests/amor/pipeline_test.py +++ b/tests/amor/pipeline_test.py @@ -10,8 +10,9 @@ from scipp.testing import assert_allclose from ess import amor -from ess.amor import data # noqa: F401 +from ess.amor import data from ess.reflectometry import orso +from ess.reflectometry.tools import scale_reflectivity_curves_to_overlap from ess.reflectometry.types import ( Filename, ProtonCurrent, @@ -105,13 +106,40 @@ def test_orso_pipeline(amor_pipeline: sciline.Pipeline): @pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation") @pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute") -def test_save_reduced_orso_file(amor_pipeline: sciline.Pipeline, output_folder: Path): +def test_save_reduced_orso_file(output_folder: Path): from orsopy import fileio - amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg") - 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') + wf = sciline.Pipeline(providers=amor.providers, params=amor.default_parameters()) + wf[SampleSize[SampleRun]] = sc.scalar(10.0, unit="mm") + wf[SampleSize[ReferenceRun]] = sc.scalar(10.0, unit="mm") + wf[YIndexLimits] = sc.scalar(11), sc.scalar(41) + wf[WavelengthBins] = sc.geomspace("wavelength", 3, 12.5, 2000, unit="angstrom") + wf[ZIndexLimits] = sc.scalar(170), sc.scalar(266) + wf = with_filenames( + wf, SampleRun, [data.amor_run(4079), data.amor_run(4080), data.amor_run(4081)] + ) + wf[Filename[ReferenceRun]] = data.amor_run(4152) + wf[QBins] = sc.geomspace(dim="Q", start=0.01, stop=0.06, num=201, unit="1/angstrom") + r = wf.compute(ReflectivityOverQ) + _, (s,) = scale_reflectivity_curves_to_overlap( + [r.hist()], + critical_edge_interval=( + sc.scalar(0.01, unit='1/angstrom'), + sc.scalar(0.014, unit='1/angstrom'), + ), + ) + wf[ReflectivityOverQ] = s * r + wf[orso.OrsoCreator] = orso.OrsoCreator( + fileio.base.Person( + name="Max Mustermann", + affiliation="European Spallation Source ERIC", + contact="max.mustermann@ess.eu", + ) + ) + fileio.orso.save_orso( + datasets=[wf.compute(orso.OrsoIofQDataset)], + fname=output_folder / 'amor_reduced_iofq.ort', + ) @pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")