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
18 changes: 8 additions & 10 deletions src/ess/amor/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
import re

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

_version = "2"


Expand Down Expand Up @@ -76,27 +74,27 @@ 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()
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]))
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__ = [
Expand Down
8 changes: 7 additions & 1 deletion src/ess/reflectometry/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = (
Expand Down
40 changes: 34 additions & 6 deletions tests/amor/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
Loading