Passed
Push — master ( 01234e...e0a97d )
by Stefan
01:10
created

test_spectra.test_ediss_spec_int()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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