Passed
Push — master ( bf11f1...1c518b )
by Stefan
06:58
created

test_ionization.test_endiss_3d()   A

Complexity

Conditions 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 14
dl 21
loc 21
rs 9.7
c 0
b 0
f 0
cc 1
nop 2
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(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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 View Code Duplication
@pytest.mark.parametrize(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
	"edissfunc, expected",
41
	# exclude bremsstrahlung for now,
42
	# scipy's rbf interpolation uses np.meshgrid
43
	# which messes with the order of the dimensions
44
	# and doesn't work for higher-dimensional arrays
45
	EDISS_FUNCS_EXPECTED[:-1],
46
)
47
def test_endiss_transposed(edissfunc, expected):
48
	energies = np.logspace(-1, 2, 4)
49
	fluxes = np.ones_like(energies)
50
	# ca. 100, 150, 200 km
51
	scale_heights = np.array([6e5, 27e5, 40e5])
52
	rhos = np.array([5e-10, 1.7e-12, 2.6e-13])
53
	ediss = edissfunc(
54
		energies[:, None], fluxes[:, None],
55
		scale_heights[None, :], rhos[None, :]
56
	)
57
	assert ediss.shape == (4, 3)
58
	np.testing.assert_allclose(ediss[2, 0], expected)
59
	return
60
61
62 View Code Duplication
@pytest.mark.parametrize(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
63
	"edissfunc, expected",
64
	# exclude bremsstrahlung for now,
65
	# scipy's rbf interpolation uses np.meshgrid
66
	# which messes with the order of the dimensions
67
	# and doesn't work for higher-dimensional arrays
68
	EDISS_FUNCS_EXPECTED[:-1],
69
)
70
def test_endiss_3d(edissfunc, expected):
71
	energies = np.logspace(-1, 2, 4)
72
	fluxes = np.ones_like(energies)
73
	# ca. 100, 150, 200 km
74
	scale_heights = np.array([6e5, 27e5, 40e5])
75
	rhos = np.array([5e-10, 1.7e-12, 2.6e-13])
76
	ediss = edissfunc(
77
		energies[None, None, :], fluxes[None, None, :],
78
		scale_heights[:, None, None], rhos[:, None, None]
79
	)
80
	assert ediss.shape == (3, 1, 4)
81
	np.testing.assert_allclose(ediss[0, 0, 2], expected)
82
	return
83
84
85 View Code Duplication
@pytest.mark.parametrize(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
86
	"edissfunc, expected",
87
	# exclude bremsstrahlung for now,
88
	# scipy's rbf interpolation uses np.meshgrid
89
	# which messes with the order of the dimensions
90
	# and doesn't work for higher-dimensional arrays
91
	EDISS_FUNCS_EXPECTED[:-1],
92
)
93
def test_endiss_3d_transposed(edissfunc, expected):
94
	energies = np.logspace(-1, 2, 4)
95
	fluxes = np.ones_like(energies)
96
	# ca. 100, 150, 200 km
97
	scale_heights = np.array([6e5, 27e5, 40e5])
98
	rhos = np.array([5e-10, 1.7e-12, 2.6e-13])
99
	ediss = edissfunc(
100
		energies[None, :, None], fluxes[None, :, None],
101
		scale_heights[:, None, None], rhos[:, None, None]
102
	)
103
	assert ediss.shape == (3, 4, 1)
104
	np.testing.assert_allclose(ediss[0, 2, 0], expected)
105
	return
106
107
108
def test_ssusi_ioniz():
109
	energies = np.logspace(-1, 2, 4)
110
	fluxes = np.ones_like(energies)
111
	z = np.array([100, 120, 150])
112
	# energy dissipation "profiles"
113
	ediss = aur.ssusi_ioniz(
114
		z[:, None],
115
		energies[None, :], fluxes[None, :],
116
	)
117
	assert ediss.shape == (3, 4)
118
	return
119