|
14 | 14 | from ess.reflectometry import orso |
15 | 15 | from ess.reflectometry.types import ( |
16 | 16 | Filename, |
| 17 | + ProtonCurrent, |
17 | 18 | QBins, |
| 19 | + ReducibleData, |
18 | 20 | ReferenceRun, |
19 | 21 | ReflectivityOverQ, |
20 | 22 | SampleRotation, |
@@ -127,3 +129,44 @@ def test_pipeline_merging_events_result_unchanged(amor_pipeline: sciline.Pipelin |
127 | 129 | assert_allclose( |
128 | 130 | 2 * sc.variances(result.data), sc.variances(result2.data), rtol=sc.scalar(1e-6) |
129 | 131 | ) |
| 132 | + |
| 133 | + |
| 134 | +@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation") |
| 135 | +@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute") |
| 136 | +def test_proton_current(amor_pipeline: sciline.Pipeline): |
| 137 | + amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(611) |
| 138 | + da_without_proton_current = amor_pipeline.compute(ReducibleData[SampleRun]) |
| 139 | + |
| 140 | + proton_current = [1, 2, 0.1] |
| 141 | + timestamps = [1699883542349602112, 1699883542349602112, 1699886864071691036] |
| 142 | + amor_pipeline[ProtonCurrent[SampleRun]] = sc.DataArray( |
| 143 | + sc.array(dims=['time'], values=proton_current), |
| 144 | + coords={ |
| 145 | + 'time': sc.array( |
| 146 | + dims=['time'], |
| 147 | + values=timestamps, |
| 148 | + dtype='datetime64', |
| 149 | + unit='ns', |
| 150 | + ) |
| 151 | + }, |
| 152 | + ) |
| 153 | + da_with_proton_current = amor_pipeline.compute(ReducibleData[SampleRun]) |
| 154 | + |
| 155 | + assert "proton_current" in da_with_proton_current.bins.coords |
| 156 | + assert "proton_current_too_low" in da_with_proton_current.bins.masks |
| 157 | + assert da_with_proton_current.bins.masks["proton_current_too_low"].any() |
| 158 | + assert not da_with_proton_current.bins.masks["proton_current_too_low"].all() |
| 159 | + |
| 160 | + assert "proton_current" not in da_without_proton_current.bins.coords |
| 161 | + assert "proton_current_too_low" not in da_without_proton_current.bins.masks |
| 162 | + |
| 163 | + t = ( |
| 164 | + da_with_proton_current.bins.constituents['data'] |
| 165 | + .coords['event_time_zero'][0] |
| 166 | + .value.astype('uint64') |
| 167 | + ) |
| 168 | + w_with = da_with_proton_current.bins.constituents['data'].data[0].value |
| 169 | + w_without = da_without_proton_current.bins.constituents['data'].data[0].value |
| 170 | + np.testing.assert_allclose( |
| 171 | + proton_current[np.searchsorted(timestamps, t) - 1], w_without / w_with |
| 172 | + ) |
0 commit comments