Skip to content

Commit 907219b

Browse files
authored
Merge branch 'main' into invert-yaxis
2 parents 7eaa01a + da8aaee commit 907219b

File tree

9 files changed

+83
-6
lines changed

9 files changed

+83
-6
lines changed

.github/workflows/nightly_at_main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ jobs:
3131
os-variant: ${{ matrix.os }}
3232
python-version: ${{ matrix.python.version }}
3333
tox-env: ${{ matrix.python.tox-env }}
34+
test-artifacts-name: 'essreflectometry-test-artifacts-latest'
3435
secrets: inherit

.github/workflows/nightly_at_release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ jobs:
3838
python-version: ${{ matrix.python.version }}
3939
tox-env: ${{ matrix.python.tox-env }}
4040
checkout_ref: ${{ needs.setup.outputs.release_tag }}
41+
test-artifacts-name: 'essreflectometry-test-artifacts-stable'
4142
secrets: inherit

.github/workflows/test.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ on:
2020
checkout_ref:
2121
default: ''
2222
type: string
23+
test-artifacts-name:
24+
default: ''
25+
type: string
2326
workflow_call:
2427
inputs:
2528
os-variant:
@@ -39,6 +42,9 @@ on:
3942
checkout_ref:
4043
default: ''
4144
type: string
45+
test-artifacts-name:
46+
default: ''
47+
type: string
4248

4349
jobs:
4450
package-test:
@@ -71,9 +77,14 @@ jobs:
7177
python-version: ${{ inputs.python-version }}
7278
- run: python -m pip install --upgrade pip
7379
- run: python -m pip install -r ${{ inputs.pip-recipe }}
74-
- run: tox -e ${{ inputs.tox-env }}
80+
- run: tox -e ${{ inputs.tox-env }} -- --file-output="tests_outputs"
7581
- uses: actions/upload-artifact@v4
7682
if: ${{ inputs.coverage-report }}
7783
with:
7884
name: CoverageReport
7985
path: coverage_html/
86+
- uses: actions/upload-artifact@v4
87+
if: ${{ inputs.test-artifacts-name != '' }}
88+
with:
89+
name: ${{ inputs.test-artifacts-name }}
90+
path: tests_outputs/

src/ess/amor/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
AngularResolution,
3131
ChopperFrequency,
3232
ChopperPhase,
33+
GravityToggle,
3334
QThetaFigure,
3435
ReflectivityDiagnosticsView,
3536
SampleSizeResolution,
@@ -76,6 +77,7 @@ def default_parameters() -> dict:
7677
sc.scalar(-0.75, unit='deg'),
7778
sc.scalar(0.75, unit='deg'),
7879
),
80+
GravityToggle: True,
7981
}
8082

8183

src/ess/amor/conversions.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ZIndexLimits,
1212
)
1313
from .geometry import Detector
14-
from .types import CoordTransformationGraph
14+
from .types import CoordTransformationGraph, GravityToggle
1515

1616

1717
def theta(wavelength, divergence_angle, L2, sample_rotation, detector_rotation):
@@ -68,6 +68,24 @@ def theta(wavelength, divergence_angle, L2, sample_rotation, detector_rotation):
6868
return out
6969

7070

71+
def theta_no_gravity(wavelength, divergence_angle, sample_rotation, detector_rotation):
72+
'''
73+
Angle of reflection.
74+
75+
Computes the angle between the scattering direction of
76+
the neutron and the sample surface while disregarding the
77+
effect of gravity.
78+
'''
79+
theta = (
80+
divergence_angle.to(unit='rad', copy=False)
81+
+ detector_rotation.to(unit='rad')
82+
- sample_rotation.to(unit='rad')
83+
)
84+
if wavelength.bins:
85+
return sc.bins_like(wavelength, theta)
86+
return theta
87+
88+
7189
def angle_of_divergence(theta, sample_rotation, angle_to_center_of_beam):
7290
"""
7391
Difference between the incident angle and the center of the incident beam.
@@ -113,11 +131,11 @@ def wavelength(
113131
return out.to(unit='angstrom', copy=False)
114132

115133

116-
def coordinate_transformation_graph() -> CoordTransformationGraph:
134+
def coordinate_transformation_graph(gravity: GravityToggle) -> CoordTransformationGraph:
117135
return {
118136
"divergence_angle": "pixel_divergence_angle",
119137
"wavelength": wavelength,
120-
"theta": theta,
138+
"theta": theta if gravity else theta_no_gravity,
121139
"angle_of_divergence": angle_of_divergence,
122140
"Q": reflectometry_q,
123141
"L1": lambda chopper_distance: sc.abs(chopper_distance),

src/ess/amor/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _make_pooch():
1212
return pooch.create(
1313
path=pooch.os_cache("ess/amor"),
1414
env="ESS_AMOR_DATA_DIR",
15-
base_url="https://fileserver-cache.johanneskasimir.workers.dev/groups/scipp/ess/amor/{version}/",
15+
base_url="https://public.esss.dk/groups/scipp/ess/amor/{version}/",
1616
version=_version,
1717
registry={
1818
"reference.nxs": "md5:56d493c8051e1c5c86fb7a95f8ec643b",

src/ess/amor/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ class AngleCenterOfIncomingToHorizon(
4747
WavelengthZIndexFigure = NewType("WavelengthZIndexFigure", Any)
4848
QThetaFigure = NewType("QThetaFigure", Any)
4949
ReflectivityDiagnosticsView = NewType("ReflectivityDiagnosticsView", Any)
50+
51+
GravityToggle = NewType("GravityToggle", bool)

tests/amor/pipeline_test.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
3-
# flake8: noqa: F403, F405
3+
from pathlib import Path
44

55
import numpy as np
66
import pytest
@@ -71,6 +71,18 @@ def test_has_expected_coordinates(amor_pipeline: sciline.Pipeline):
7171
assert "Q_resolution" in reflectivity_over_q.coords
7272

7373

74+
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
75+
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
76+
def test_pipeline_no_gravity_correction(amor_pipeline: sciline.Pipeline):
77+
# The sample rotation value in the file is slightly off, so we set it manually
78+
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
79+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
80+
amor_pipeline[amor.types.GravityToggle] = False
81+
reflectivity_over_q = amor_pipeline.compute(ReflectivityOverQ)
82+
assert "Q" in reflectivity_over_q.coords
83+
assert "Q_resolution" in reflectivity_over_q.coords
84+
85+
7486
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
7587
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
7688
def test_orso_pipeline(amor_pipeline: sciline.Pipeline):
@@ -91,6 +103,17 @@ def test_orso_pipeline(amor_pipeline: sciline.Pipeline):
91103
assert np.isfinite(res.data).all()
92104

93105

106+
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
107+
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
108+
def test_save_reduced_orso_file(amor_pipeline: sciline.Pipeline, output_folder: Path):
109+
from orsopy import fileio
110+
111+
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
112+
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
113+
res = amor_pipeline.compute(orso.OrsoIofQDataset)
114+
fileio.orso.save_orso(datasets=[res], fname=output_folder / 'amor_reduced_iofq.ort')
115+
116+
94117
@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
95118
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
96119
def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs(

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: BSD-3-Clause
2+
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)
3+
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
9+
def pytest_addoption(parser: pytest.Parser) -> None:
10+
parser.addoption("--file-output", help='Output folder for reduced data')
11+
12+
13+
@pytest.fixture
14+
def output_folder(request: pytest.FixtureRequest) -> Path:
15+
if (path := request.config.getoption("--file-output")) is not None:
16+
out = Path(path)
17+
out.mkdir(parents=True, exist_ok=True)
18+
return out
19+
return request.getfixturevalue("tmp_path")

0 commit comments

Comments
 (0)