| Total Complexity | 2 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | import numpy as np |
||
| 3 | import pytest |
||
| 4 | |||
| 5 | import eppaurora.spectra as spec |
||
| 6 | |||
| 7 | # unit particle flux |
||
| 8 | PFLUX_NNORM = [ |
||
| 9 | spec.exp_general, |
||
| 10 | spec.gaussian_general, |
||
| 11 | spec.maxwell_general, |
||
| 12 | ] |
||
| 13 | |||
| 14 | # unit energy flux |
||
| 15 | PFLUX_ENORM = [ |
||
| 16 | spec.pflux_exp, |
||
| 17 | spec.pflux_gaussian, |
||
| 18 | spec.pflux_maxwell, |
||
| 19 | ] |
||
| 20 | |||
| 21 | |||
| 22 | @pytest.mark.parametrize( |
||
| 23 | "pflux_func", |
||
| 24 | PFLUX_NNORM, |
||
| 25 | ) |
||
| 26 | def test_nflux_norm(pflux_func): |
||
| 27 | energies = np.logspace(-2, 4, 257) |
||
| 28 | spec = pflux_func(energies) |
||
| 29 | norm = np.trapz(spec, energies) |
||
| 30 | np.testing.assert_allclose(norm, 1., rtol=1e-3) |
||
| 31 | return |
||
| 32 | |||
| 33 | |||
| 34 | @pytest.mark.parametrize( |
||
| 35 | "pflux_func", |
||
| 36 | PFLUX_ENORM, |
||
| 37 | ) |
||
| 38 | def test_pflux_norm(pflux_func): |
||
| 39 | energies = np.logspace(-2, 4, 257) |
||
| 40 | spec = pflux_func(energies) |
||
| 41 | norm = np.trapz(spec * energies, energies) |
||
| 42 | np.testing.assert_allclose(norm, 1., rtol=1e-3) |
||
| 43 | return |
||
| 44 |