1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import numpy as np |
3
|
|
|
import pytest |
4
|
|
|
from scipy.integrate import quad |
5
|
|
|
|
6
|
|
|
import eppaurora.spectra as spec |
7
|
|
|
from eppaurora.electrons import fang2010_mono |
8
|
|
|
|
9
|
|
|
# unit particle flux |
10
|
|
|
PFLUX_NNORM = [ |
11
|
|
|
spec.exp_general, |
12
|
|
|
spec.gaussian_general, |
13
|
|
|
spec.maxwell_general, |
14
|
|
|
spec.pow_general, |
15
|
|
|
] |
16
|
|
|
|
17
|
|
|
# unit energy flux |
18
|
|
|
PFLUX_ENORM = [ |
19
|
|
|
spec.pflux_exp, |
20
|
|
|
spec.pflux_gaussian, |
21
|
|
|
spec.pflux_maxwell, |
22
|
|
|
spec.pflux_pow, |
23
|
|
|
] |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
@pytest.mark.parametrize( |
27
|
|
|
"pflux_func", |
28
|
|
|
PFLUX_NNORM, |
29
|
|
|
) |
30
|
|
|
def test_nflux_norm(pflux_func): |
31
|
|
|
norm = quad(pflux_func, 0., np.inf)[0] |
32
|
|
|
np.testing.assert_allclose(norm, 1., rtol=1e-9) |
33
|
|
|
return |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
@pytest.mark.parametrize( |
37
|
|
|
"pflux_func", |
38
|
|
|
PFLUX_ENORM, |
39
|
|
|
) |
40
|
|
|
def test_pflux_norm(pflux_func): |
41
|
|
|
norm = quad(lambda x: x * pflux_func(x), 0., np.inf)[0] |
42
|
|
|
np.testing.assert_allclose(norm, 1., rtol=1e-9) |
43
|
|
|
return |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
@pytest.mark.parametrize( |
47
|
|
|
"pflux_func", |
48
|
|
|
PFLUX_ENORM, |
49
|
|
|
) |
50
|
|
|
def test_ediss_spec_int(pflux_func): |
51
|
|
|
energies = np.logspace(-2, 4, 257) |
52
|
|
|
dfluxes = pflux_func(energies) |
53
|
|
|
ediss = spec.ediss_spec_int( |
54
|
|
|
energies, dfluxes, |
55
|
|
|
6e5, 5e-10, |
56
|
|
|
fang2010_mono, |
57
|
|
|
) |
58
|
|
|
assert ediss.shape == (1, 1) |
59
|
|
|
return |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
@pytest.mark.parametrize( |
63
|
|
|
"pflux_func", |
64
|
|
|
PFLUX_ENORM, |
65
|
|
|
) |
66
|
|
|
def test_ediss_specfun_int(pflux_func): |
67
|
|
|
energies = np.logspace(-1, 2, 4) |
68
|
|
|
fluxes = 1 |
69
|
|
|
# ca. 100 km |
70
|
|
|
scale_height = 6e5 |
71
|
|
|
rho = 5e-10 |
72
|
|
|
ediss = spec.ediss_specfun_int( |
73
|
|
|
energies, fluxes, |
74
|
|
|
scale_height, rho, |
75
|
|
|
fang2010_mono, |
76
|
|
|
spec_fun=pflux_func, |
77
|
|
|
) |
78
|
|
|
assert ediss.shape == (1, 4) |
79
|
|
|
return |
80
|
|
|
|