1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import datetime as dt |
3
|
|
|
import numpy as np |
4
|
|
|
import pytest |
5
|
|
|
|
6
|
|
|
import eppaurora as aur |
7
|
|
|
|
8
|
|
|
EDISS_FUNCS_EXPECTED = [ |
9
|
|
|
(aur.rr1987, 4.51517584e-07), |
10
|
|
|
(aur.rr1987_mod, 4.75296602e-07), |
11
|
|
|
(aur.fang2008, 4.44256875e-07), |
12
|
|
|
(aur.fang2010_mono, 1.96516057e-007), |
13
|
|
|
(aur.fang2010_maxw_int, 4.41340659e-07), |
14
|
|
|
(aur.fang2013_protons, 4.09444686e-22), |
15
|
|
|
(aur.berger1974, 2.37365609e-03), |
16
|
|
|
] |
17
|
|
|
|
18
|
|
|
|
19
|
|
View Code Duplication |
@pytest.mark.parametrize( |
|
|
|
|
20
|
|
|
"edissfunc, expected", |
21
|
|
|
EDISS_FUNCS_EXPECTED, |
22
|
|
|
) |
23
|
|
|
def test_endiss(edissfunc, expected): |
24
|
|
|
energies = np.logspace(-1, 2, 4) |
25
|
|
|
fluxes = np.ones_like(energies) |
26
|
|
|
# ca. 100, 150, 200 km |
27
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
28
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
29
|
|
|
# energy dissipation "profiles" |
30
|
|
|
ediss = edissfunc( |
31
|
|
|
energies[None, :], fluxes[None, :], |
32
|
|
|
scale_heights[:, None], rhos[:, None] |
33
|
|
|
) |
34
|
|
|
assert ediss.shape == (3, 4) |
35
|
|
|
np.testing.assert_allclose(ediss[0, 2], expected) |
36
|
|
|
return |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
@pytest.mark.parametrize( |
40
|
|
|
"edissfunc, expected", |
41
|
|
|
EDISS_FUNCS_EXPECTED, |
42
|
|
|
) |
43
|
|
|
def test_endiss_scalar(edissfunc, expected): |
44
|
|
|
energies = 10. |
45
|
|
|
fluxes = 1. |
46
|
|
|
# ca. 100, 150, 200 km |
47
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
48
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
49
|
|
|
# energy dissipation "profiles" |
50
|
|
|
ediss = edissfunc( |
51
|
|
|
energies, fluxes, |
52
|
|
|
scale_heights[:, None], rhos[:, None] |
53
|
|
|
) |
54
|
|
|
assert ediss.shape == (3, 1) |
55
|
|
|
np.testing.assert_allclose(ediss[0, 0], expected) |
56
|
|
|
return |
57
|
|
|
|
58
|
|
|
|
59
|
|
View Code Duplication |
@pytest.mark.parametrize( |
|
|
|
|
60
|
|
|
"edissfunc, expected", |
61
|
|
|
# exclude bremsstrahlung for now, |
62
|
|
|
# scipy's rbf interpolation uses np.meshgrid |
63
|
|
|
# which messes with the order of the dimensions |
64
|
|
|
# and doesn't work for higher-dimensional arrays |
65
|
|
|
EDISS_FUNCS_EXPECTED[:-1], |
66
|
|
|
) |
67
|
|
|
def test_endiss_transposed(edissfunc, expected): |
68
|
|
|
energies = np.logspace(-1, 2, 4) |
69
|
|
|
fluxes = np.ones_like(energies) |
70
|
|
|
# ca. 100, 150, 200 km |
71
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
72
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
73
|
|
|
ediss = edissfunc( |
74
|
|
|
energies[:, None], fluxes[:, None], |
75
|
|
|
scale_heights[None, :], rhos[None, :] |
76
|
|
|
) |
77
|
|
|
assert ediss.shape == (4, 3) |
78
|
|
|
np.testing.assert_allclose(ediss[2, 0], expected) |
79
|
|
|
return |
80
|
|
|
|
81
|
|
|
|
82
|
|
View Code Duplication |
@pytest.mark.parametrize( |
|
|
|
|
83
|
|
|
"edissfunc, expected", |
84
|
|
|
# exclude bremsstrahlung for now, |
85
|
|
|
# scipy's rbf interpolation uses np.meshgrid |
86
|
|
|
# which messes with the order of the dimensions |
87
|
|
|
# and doesn't work for higher-dimensional arrays |
88
|
|
|
EDISS_FUNCS_EXPECTED[:-1], |
89
|
|
|
) |
90
|
|
|
def test_endiss_3d(edissfunc, expected): |
91
|
|
|
energies = np.logspace(-1, 2, 4) |
92
|
|
|
fluxes = np.ones_like(energies) |
93
|
|
|
# ca. 100, 150, 200 km |
94
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
95
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
96
|
|
|
ediss = edissfunc( |
97
|
|
|
energies[None, None, :], fluxes[None, None, :], |
98
|
|
|
scale_heights[:, None, None], rhos[:, None, None] |
99
|
|
|
) |
100
|
|
|
assert ediss.shape == (3, 1, 4) |
101
|
|
|
np.testing.assert_allclose(ediss[0, 0, 2], expected) |
102
|
|
|
return |
103
|
|
|
|
104
|
|
|
|
105
|
|
View Code Duplication |
@pytest.mark.parametrize( |
|
|
|
|
106
|
|
|
"edissfunc, expected", |
107
|
|
|
# exclude bremsstrahlung for now, |
108
|
|
|
# scipy's rbf interpolation uses np.meshgrid |
109
|
|
|
# which messes with the order of the dimensions |
110
|
|
|
# and doesn't work for higher-dimensional arrays |
111
|
|
|
EDISS_FUNCS_EXPECTED[:-1], |
112
|
|
|
) |
113
|
|
|
def test_endiss_3d_transposed(edissfunc, expected): |
114
|
|
|
energies = np.logspace(-1, 2, 4) |
115
|
|
|
fluxes = np.ones_like(energies) |
116
|
|
|
# ca. 100, 150, 200 km |
117
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
118
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
119
|
|
|
ediss = edissfunc( |
120
|
|
|
energies[None, :, None], fluxes[None, :, None], |
121
|
|
|
scale_heights[:, None, None], rhos[:, None, None] |
122
|
|
|
) |
123
|
|
|
assert ediss.shape == (3, 4, 1) |
124
|
|
|
np.testing.assert_allclose(ediss[0, 2, 0], expected) |
125
|
|
|
return |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
def test_ssusi_ioniz(): |
129
|
|
|
energies = np.logspace(-1, 2, 4) |
130
|
|
|
fluxes = np.ones_like(energies) |
131
|
|
|
z = np.array([100, 120, 150]) |
132
|
|
|
# energy dissipation "profiles" |
133
|
|
|
ediss = aur.ssusi_ioniz( |
134
|
|
|
z[:, None], |
135
|
|
|
energies[None, :], fluxes[None, :], |
136
|
|
|
) |
137
|
|
|
assert ediss.shape == (3, 4) |
138
|
|
|
return |
139
|
|
|
|