1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import numpy as np |
3
|
|
|
import pytest |
4
|
|
|
|
5
|
|
|
import eppaurora as aur |
6
|
|
|
|
7
|
|
|
COND1_FUNCS_EXPECTED = [ |
8
|
|
|
(aur.pedersen, [1.50700987e-05, 9.03908593e-06, 8.54346201e-07]), |
9
|
|
|
(aur.hall, [4.59146798e-04, 1.05810738e-06, 1.30470569e-08]), |
10
|
|
|
] |
11
|
|
|
|
12
|
|
|
COND2_FUNCS_EXPECTED = [ |
13
|
|
|
(aur.SigmaP_robinson1987, [0.24984385, 2.35294118, 3.44827586, 0.39936102]), |
14
|
|
|
(aur.SigmaH_robinson1987, [0.01588112, 1.05882353, 10.98536562, 9.00695907]), |
15
|
|
|
] |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
@pytest.mark.parametrize( |
19
|
|
|
"condfunc, expected", |
20
|
|
|
COND1_FUNCS_EXPECTED, |
21
|
|
|
) |
22
|
|
|
def test_conductivity(condfunc, expected): |
23
|
|
|
_eV_J = 1.602176634e-19 # eV in J in new SI units |
24
|
|
|
_erg_J = 1e-7 # 1 erg = 100 nJ |
25
|
|
|
_erg_keV = _erg_J / _eV_J * 1e-3 |
26
|
|
|
_bmag = 50000. # nT |
27
|
|
|
energies = np.logspace(-1, 2, 4) # keV |
28
|
|
|
fluxes = np.ones_like(energies) # ergs / cm² / s = 100 nW / cm² |
29
|
|
|
# convert to keV / cm² / s |
30
|
|
|
fluxes = fluxes * _erg_keV |
31
|
|
|
# ca. 100, 150, 200 km |
32
|
|
|
alts = np.array([100, 150, 200]) |
33
|
|
|
scale_heights = np.array([6e5, 27e5, 40e5]) |
34
|
|
|
rhos = np.array([5e-10, 1.7e-12, 2.6e-13]) |
35
|
|
|
nds = np.array([12173395869016.26, 46771522616.48675, 6101757504.939191]) |
36
|
|
|
# ionization rates |
37
|
|
|
qs = 1 / 0.035 * aur.fang2010_maxw_int( |
38
|
|
|
energies[None, :], fluxes[None, :], |
39
|
|
|
scale_heights[:, None], rhos[:, None], |
40
|
|
|
) |
41
|
|
|
# electron densities |
42
|
|
|
nes = np.sqrt(qs / aur.recombination.alpha_gledhill1986_aurora(alts)[:, None]) |
43
|
|
|
# gyro frequency |
44
|
|
|
omega = aur.conductivity.ion_gyro(_bmag * 1e-9) |
45
|
|
|
# collision frequency |
46
|
|
|
nu = aur.conductivity.ion_coll(nds) |
47
|
|
|
# conductances |
48
|
|
|
cond = condfunc(nes * 1e6, _bmag * 1e-9, omega, nu[:, None]) |
49
|
|
|
assert cond.shape == (3, 4) |
50
|
|
|
np.testing.assert_allclose(cond[:, 2], expected) |
51
|
|
|
return |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
@pytest.mark.parametrize( |
55
|
|
|
"condfunc, expected", |
56
|
|
|
COND2_FUNCS_EXPECTED, |
57
|
|
|
) |
58
|
|
|
def test_conductance(condfunc, expected): |
59
|
|
|
energies = np.logspace(-1, 2, 4) # keV |
60
|
|
|
fluxes = np.ones_like(energies) # ergs / cm² / s |
61
|
|
|
# conductances |
62
|
|
|
cond = condfunc(energies, fluxes) |
63
|
|
|
assert cond.shape == (4,) |
64
|
|
|
np.testing.assert_allclose(cond, expected, atol=1e-9) |
65
|
|
|
return |
66
|
|
|
|