Skip to content

Commit dba5d79

Browse files
authored
Merge pull request #153 from scipp/better-testcase
Better testcase
2 parents 5457dbf + 0d0706e commit dba5d79

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/ess/amor/data.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
33
import re
44

5-
from ..reflectometry.types import Filename, ReferenceRun, SampleRun
6-
75
_version = "2"
86

97

@@ -76,27 +74,27 @@ def _make_pooch():
7674
_pooch = _make_pooch()
7775

7876

79-
def amor_old_sample_run() -> Filename[SampleRun]:
80-
return Filename[SampleRun](_pooch.fetch("sample.nxs"))
77+
def amor_old_sample_run() -> str:
78+
return _pooch.fetch("sample.nxs")
8179

8280

83-
def amor_old_reference_run() -> Filename[ReferenceRun]:
84-
return Filename[ReferenceRun](_pooch.fetch("reference.nxs"))
81+
def amor_old_reference_run() -> str:
82+
return _pooch.fetch("reference.nxs")
8583

8684

87-
def amor_run(number: int | str) -> Filename[SampleRun]:
85+
def amor_run(number: int | str) -> str:
8886
fnames = [
8987
name
9088
for name in _pooch.registry.keys()
9189
if re.match(f'amor\\d{{4}}n{int(number):06d}.hdf', name)
9290
]
9391
if len(fnames) != 1:
9492
raise ValueError(f'Expected exactly one matching file, found {len(fnames)}')
95-
return Filename[SampleRun](_pooch.fetch(fnames[0]))
93+
return _pooch.fetch(fnames[0])
9694

9795

98-
def amor_psi_software_result(number: int | str) -> Filename[SampleRun]:
99-
return Filename[SampleRun](_pooch.fetch(f"{int(number):03d}.Rqz.ort"))
96+
def amor_psi_software_result(number: int | str) -> str:
97+
return _pooch.fetch(f"{int(number):03d}.Rqz.ort")
10098

10199

102100
__all__ = [

src/ess/reflectometry/gui.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
33
import glob
44
import os
5+
import re
56
import uuid
67
from collections.abc import Callable
78

@@ -902,7 +903,12 @@ def toggle_line(name, value, figure):
902903
self.plot_log.children = (box, *self.plot_log.children)
903904

904905
def get_filepath_from_run(self, run):
905-
return os.path.join(self.path, f'amor2024n{run:0>6}.hdf')
906+
fname = next(
907+
name
908+
for name in os.listdir(self.path)
909+
if re.match(f'amor\\d{{4}}n{int(run):06d}.hdf', name)
910+
)
911+
return os.path.join(self.path, fname)
906912

907913
def get_row_key(self, row):
908914
reference_metadata = (

tests/amor/pipeline_test.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
from scipp.testing import assert_allclose
1111

1212
from ess import amor
13-
from ess.amor import data # noqa: F401
13+
from ess.amor import data
1414
from ess.reflectometry import orso
15+
from ess.reflectometry.tools import scale_reflectivity_curves_to_overlap
1516
from ess.reflectometry.types import (
1617
Filename,
1718
ProtonCurrent,
@@ -105,13 +106,40 @@ def test_orso_pipeline(amor_pipeline: sciline.Pipeline):
105106

106107
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
107108
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
108-
def test_save_reduced_orso_file(amor_pipeline: sciline.Pipeline, output_folder: Path):
109+
def test_save_reduced_orso_file(output_folder: Path):
109110
from orsopy import fileio
110111

111-
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
112-
amor_pipeline[Filename[SampleRun]] = amor.data.amor_run(608)
113-
res = amor_pipeline.compute(orso.OrsoIofQDataset)
114-
fileio.orso.save_orso(datasets=[res], fname=output_folder / 'amor_reduced_iofq.ort')
112+
wf = sciline.Pipeline(providers=amor.providers, params=amor.default_parameters())
113+
wf[SampleSize[SampleRun]] = sc.scalar(10.0, unit="mm")
114+
wf[SampleSize[ReferenceRun]] = sc.scalar(10.0, unit="mm")
115+
wf[YIndexLimits] = sc.scalar(11), sc.scalar(41)
116+
wf[WavelengthBins] = sc.geomspace("wavelength", 3, 12.5, 2000, unit="angstrom")
117+
wf[ZIndexLimits] = sc.scalar(170), sc.scalar(266)
118+
wf = with_filenames(
119+
wf, SampleRun, [data.amor_run(4079), data.amor_run(4080), data.amor_run(4081)]
120+
)
121+
wf[Filename[ReferenceRun]] = data.amor_run(4152)
122+
wf[QBins] = sc.geomspace(dim="Q", start=0.01, stop=0.06, num=201, unit="1/angstrom")
123+
r = wf.compute(ReflectivityOverQ)
124+
_, (s,) = scale_reflectivity_curves_to_overlap(
125+
[r.hist()],
126+
critical_edge_interval=(
127+
sc.scalar(0.01, unit='1/angstrom'),
128+
sc.scalar(0.014, unit='1/angstrom'),
129+
),
130+
)
131+
wf[ReflectivityOverQ] = s * r
132+
wf[orso.OrsoCreator] = orso.OrsoCreator(
133+
fileio.base.Person(
134+
name="Max Mustermann",
135+
affiliation="European Spallation Source ERIC",
136+
contact="[email protected]",
137+
)
138+
)
139+
fileio.orso.save_orso(
140+
datasets=[wf.compute(orso.OrsoIofQDataset)],
141+
fname=output_folder / 'amor_reduced_iofq.ort',
142+
)
115143

116144

117145
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")

0 commit comments

Comments
 (0)