77import sciline
88import scipp as sc
99from orsopy import fileio
10+ from scipp .testing import assert_allclose
1011
1112from ess import amor
1213from ess .amor import data # noqa: F401
2324 YIndexLimits ,
2425 ZIndexLimits ,
2526)
27+ from ess .reflectometry .workflow import with_filenames
2628
2729
2830@pytest .fixture
@@ -34,6 +36,9 @@ def amor_pipeline() -> sciline.Pipeline:
3436 pl [WavelengthBins ] = sc .geomspace ("wavelength" , 2.8 , 12 , 300 , unit = "angstrom" )
3537 pl [YIndexLimits ] = sc .scalar (11 , unit = None ), sc .scalar (41 , unit = None )
3638 pl [ZIndexLimits ] = sc .scalar (80 , unit = None ), sc .scalar (370 , unit = None )
39+ pl [QBins ] = sc .geomspace (
40+ dim = "Q" , start = 0.005 , stop = 0.115 , num = 391 , unit = "1/angstrom"
41+ )
3742
3843 # The sample rotation value in the file is slightly off, so we set it manually
3944 pl [SampleRotation [ReferenceRun ]] = sc .scalar (0.65 , unit = "deg" )
@@ -46,19 +51,15 @@ def amor_pipeline() -> sciline.Pipeline:
46514752 )
4853 )
49-
50- # The sample rotation value in the file is slightly off, so we set it manually
51- pl [SampleRotation [SampleRun ]] = sc .scalar (0.85 , unit = "deg" )
52- pl [Filename [SampleRun ]] = amor .data .amor_sample_run (608 )
53- pl [QBins ] = sc .geomspace (
54- dim = "Q" , start = 0.005 , stop = 0.115 , num = 391 , unit = "1/angstrom"
55- )
5654 return pl
5755
5856
5957@pytest .mark .filterwarnings ("ignore:Failed to convert .* into a transformation" )
6058@pytest .mark .filterwarnings ("ignore:Invalid transformation, missing attribute" )
6159def test_run_data_pipeline (amor_pipeline : sciline .Pipeline ):
60+ # The sample rotation value in the file is slightly off, so we set it manually
61+ amor_pipeline [SampleRotation [SampleRun ]] = sc .scalar (0.85 , unit = "deg" )
62+ amor_pipeline [Filename [SampleRun ]] = amor .data .amor_sample_run (608 )
6263 res = amor_pipeline .compute (ReflectivityOverQ )
6364 assert "Q" in res .coords
6465 assert "Q_resolution" in res .coords
@@ -67,6 +68,8 @@ def test_run_data_pipeline(amor_pipeline: sciline.Pipeline):
6768@pytest .mark .filterwarnings ("ignore:Failed to convert .* into a transformation" )
6869@pytest .mark .filterwarnings ("ignore:Invalid transformation, missing attribute" )
6970def test_run_full_pipeline (amor_pipeline : sciline .Pipeline ):
71+ amor_pipeline [SampleRotation [SampleRun ]] = sc .scalar (0.85 , unit = "deg" )
72+ amor_pipeline [Filename [SampleRun ]] = amor .data .amor_sample_run (608 )
7073 res = amor_pipeline .compute (orso .OrsoIofQDataset )
7174 assert res .info .data_source .experiment .instrument == "Amor"
7275 assert res .info .reduction .software .name == "ess.reflectometry"
@@ -75,7 +78,53 @@ def test_run_full_pipeline(amor_pipeline: sciline.Pipeline):
7578 assert np .all (res .data [:, 1 ] >= 0 )
7679
7780
81+ @pytest .mark .filterwarnings ("ignore:Failed to convert .* into a transformation" )
82+ @pytest .mark .filterwarnings ("ignore:Invalid transformation, missing attribute" )
83+ def test_pipeline_can_compute_reflectivity_merging_events_from_multiple_runs (
84+ amor_pipeline : sciline .Pipeline ,
85+ ):
86+ sample_runs = [
87+ amor .data .amor_sample_run (608 ),
88+ amor .data .amor_sample_run (609 ),
89+ ]
90+ pipeline = with_filenames (amor_pipeline , SampleRun , sample_runs )
91+ pipeline [SampleRotation [SampleRun ]] = pipeline .compute (
92+ SampleRotation [SampleRun ]
93+ ) + sc .scalar (0.05 , unit = "deg" )
94+ result = pipeline .compute (ReflectivityOverQ )
95+ assert result .dims == ('Q' ,)
96+
97+
98+ @pytest .mark .filterwarnings ("ignore:Failed to convert .* into a transformation" )
99+ @pytest .mark .filterwarnings ("ignore:Invalid transformation, missing attribute" )
100+ def test_pipeline_merging_events_result_unchanged (amor_pipeline : sciline .Pipeline ):
101+ sample_runs = [
102+ amor .data .amor_sample_run (608 ),
103+ ]
104+ pipeline = with_filenames (amor_pipeline , SampleRun , sample_runs )
105+ pipeline [SampleRotation [SampleRun ]] = pipeline .compute (
106+ SampleRotation [SampleRun ]
107+ ) + sc .scalar (0.05 , unit = "deg" )
108+ result = pipeline .compute (ReflectivityOverQ ).hist ()
109+ sample_runs = [
110+ amor .data .amor_sample_run (608 ),
111+ amor .data .amor_sample_run (608 ),
112+ ]
113+ pipeline = with_filenames (amor_pipeline , SampleRun , sample_runs )
114+ pipeline [SampleRotation [SampleRun ]] = pipeline .compute (
115+ SampleRotation [SampleRun ]
116+ ) + sc .scalar (0.05 , unit = "deg" )
117+ result2 = pipeline .compute (ReflectivityOverQ ).hist ()
118+ assert_allclose (
119+ 2 * sc .values (result .data ), sc .values (result2 .data ), rtol = sc .scalar (1e-6 )
120+ )
121+ assert_allclose (
122+ 2 * sc .variances (result .data ), sc .variances (result2 .data ), rtol = sc .scalar (1e-6 )
123+ )
124+
125+
78126def test_find_corrections (amor_pipeline : sciline .Pipeline ):
127+ amor_pipeline [Filename [SampleRun ]] = amor .data .amor_sample_run (608 )
79128 graph = amor_pipeline .get (orso .OrsoIofQDataset )
80129 # In topological order
81130 assert orso .find_corrections (graph ) == [
0 commit comments