|
1 | 1 | import numpy as np
|
| 2 | +import pytest |
2 | 3 | import scipp as sc
|
| 4 | +from scipp.testing import assert_allclose |
| 5 | + |
| 6 | +from ess.estia.calibration import solve_for_calibration_parameters |
3 | 7 |
|
4 | 8 |
|
5 | 9 | def generate_valid_calibration_parameters():
|
@@ -44,3 +48,22 @@ def intensity_from_parameters(I0, Pp, Pa, Ap, Aa, Rpp, Rpa, Rap, Raa):
|
44 | 48 | + Raa * (1 - Aa) * (1 - Pa)
|
45 | 49 | ),
|
46 | 50 | )
|
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.parametrize("seed", range(10)) |
| 54 | +def test_calibration_solve_recovers_input(seed): |
| 55 | + np.random.seed(seed) |
| 56 | + I0, Pp, Pa, Ap, Aa, Rspp, Rsaa = generate_valid_calibration_parameters() |
| 57 | + Io = intensity_from_parameters( |
| 58 | + I0, Pp, Pa, Ap, Aa, sc.scalar(1), sc.scalar(0), sc.scalar(0), sc.scalar(1) |
| 59 | + ) |
| 60 | + Is = intensity_from_parameters( |
| 61 | + I0, Pp, Pa, Ap, Aa, Rspp, sc.scalar(0), sc.scalar(0), Rsaa |
| 62 | + ) |
| 63 | + tuple( |
| 64 | + map( |
| 65 | + assert_allclose, |
| 66 | + solve_for_calibration_parameters(Io, Is), |
| 67 | + (I0, Pp, Pa, Ap, Aa, Rspp, Rsaa), |
| 68 | + ) |
| 69 | + ) |
0 commit comments