1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import numpy as np |
3
|
|
|
import pytest |
4
|
|
|
|
5
|
|
|
xr = pytest.importorskip( |
6
|
|
|
"xarray", |
7
|
|
|
reason="`xarray` is needed, it should be installed with the `models` extra." |
8
|
|
|
) |
9
|
|
|
aurmod = pytest.importorskip( |
10
|
|
|
"eppaurora.models", reason="Could not import the `models` submodule." |
11
|
|
|
) |
12
|
|
|
|
13
|
|
|
COEFF_DS = xr.Dataset( |
14
|
|
|
data_vars={ |
15
|
|
|
"beta": ( |
16
|
|
|
["altitude", "latitude", "mlt", "proxy"], |
17
|
|
|
[[[[1., 2., 3., 4., 5., 6.]]]], |
18
|
|
|
), |
19
|
|
|
"beta_std": ( |
20
|
|
|
["altitude", "latitude", "mlt", "proxy"], |
21
|
|
|
[[[[1., 2., 3., 4., 5., 6.]]]], |
22
|
|
|
), |
23
|
|
|
}, |
24
|
|
|
coords={ |
25
|
|
|
"altitude": [100.], |
26
|
|
|
"latitude": [70.2], |
27
|
|
|
"mlt": [3.0], |
28
|
|
|
"proxy": ["Kp", "PC", "Ap", "log_f107_81ctr_obs", "log_v_plasma", "offset"], |
29
|
|
|
}, |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
def test_ssusiq2023(): |
34
|
|
|
res = aurmod.ssusiq2023( |
35
|
|
|
70.2, 3, 100., [2.333, 1, 20, 2, 2], coeff_ds=COEFF_DS, |
36
|
|
|
) |
37
|
|
|
np.testing.assert_allclose(res, [2.333 + 2. + 60. + 8. + 10. + 6.]) |
38
|
|
|
res = aurmod.ssusiq2023( |
39
|
|
|
70.2, 3, 100., [2.333, 1, 20, 2, 2], coeff_ds=COEFF_DS, return_var=True, |
40
|
|
|
) |
41
|
|
|
np.testing.assert_allclose( |
42
|
|
|
res[1], [2.333**2 + 2.**2 + 60.**2 + 8.**2 + 10.**2 + 6.**2] |
43
|
|
|
) |
44
|
|
|
res = aurmod.ssusiq2023( |
45
|
|
|
70.2, 3, 100., |
46
|
|
|
[ |
47
|
|
|
[2.333, 1, 20, 2, 2], |
48
|
|
|
[3.333, 2, 50, 4, 3] |
49
|
|
|
], |
50
|
|
|
coeff_ds=COEFF_DS, |
51
|
|
|
return_var=True, |
52
|
|
|
) |
53
|
|
|
np.testing.assert_allclose( |
54
|
|
|
res[0], |
55
|
|
|
np.array([ |
56
|
|
|
2.333 + 2. + 60. + 8. + 10. + 6., |
57
|
|
|
3.333 + 4. + 150. + 16. + 15. + 6., |
58
|
|
|
]) |
59
|
|
|
) |
60
|
|
|
np.testing.assert_allclose( |
61
|
|
|
res[1], |
62
|
|
|
np.array([ |
63
|
|
|
2.333**2 + 2.**2 + 60.**2 + 8.**2 + 10.**2 + 6.**2, |
64
|
|
|
3.333**2 + 4.**2 + 150.**2 + 16.**2 + 15.**2 + 6.**2, |
65
|
|
|
]) |
66
|
|
|
) |
67
|
|
|
res = aurmod.ssusiq2023( |
68
|
|
|
70.2, 3, 100., |
69
|
|
|
[ |
70
|
|
|
[2.333, 3.333], [1, 2], [20, 50], [2, 4], [2, 3] |
71
|
|
|
], |
72
|
|
|
coeff_ds=COEFF_DS, |
73
|
|
|
return_var=True, |
74
|
|
|
) |
75
|
|
|
np.testing.assert_allclose( |
76
|
|
|
res[0], |
77
|
|
|
np.array([ |
78
|
|
|
2.333 + 2. + 60. + 8. + 10. + 6., |
79
|
|
|
3.333 + 4. + 150. + 16. + 15. + 6., |
80
|
|
|
]) |
81
|
|
|
) |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
def test_ssusiq2023_xrda_2d(): |
85
|
|
|
res = aurmod.ssusiq2023( |
86
|
|
|
70.2, 3, 100., |
87
|
|
|
xr.DataArray( |
88
|
|
|
[[2.333, 3.333], [1, 2], [20, 50], [2, 4], [2, 3]], |
89
|
|
|
dims=["proxy", "time"], |
90
|
|
|
coords={"proxy": ["Kp", "PC", "Ap", "log_f107_81ctr_obs", "log_v_plasma"]}, |
91
|
|
|
), |
92
|
|
|
return_var=True, |
93
|
|
|
) |
94
|
|
|
assert res[0].shape == (2,) |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
def test_ssusiq2023_xrda_3d(): |
98
|
|
|
res = aurmod.ssusiq2023( |
99
|
|
|
70.2, 3, 100., |
100
|
|
|
xr.DataArray( |
101
|
|
|
[[[2.333, 3.333], [1, 2], [20, 50], [2, 4], [2, 3]]], |
102
|
|
|
dims=["model", "proxy", "time"], |
103
|
|
|
coords={"proxy": ["Kp", "PC", "Ap", "log_f107_81ctr_obs", "log_v_plasma"]}, |
104
|
|
|
), |
105
|
|
|
return_var=True, |
106
|
|
|
) |
107
|
|
|
assert res[0].shape == (1, 2) |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
def test_ssusiq2023_vec(): |
111
|
|
|
res = aurmod.ssusiq2023( |
112
|
|
|
[66.6, 70.2], [3, 5, 7], [100., 105., 110., 115.], |
113
|
|
|
[[2.333], [1], [20], [2], [2]], |
114
|
|
|
return_var=True, |
115
|
|
|
) |
116
|
|
|
assert res[0].shape == (3, 2, 4, 1) |
117
|
|
|
|