-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_edc.py
More file actions
99 lines (80 loc) · 3.92 KB
/
test_edc.py
File metadata and controls
99 lines (80 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for edc related things."""
import numpy as np
from numpy import array
import numpy.testing as npt
import pyfar as pf
import pytest
import pyrato as ra
@pytest.mark.parametrize("is_energy", [True, False])
def test_schroeder_integration(is_energy):
"""Simple impulse response."""
factor = 2 if is_energy else np.sqrt(2)
data = pf.Signal(np.ones((1, 10))*factor, sampling_rate=10)
energy_decay_curve = ra.edc.schroeder_integration(
data, is_energy=is_energy)
# test if the shape is correct
npt.assert_array_equal(energy_decay_curve.time.shape, data.time.shape)
# test if the values are correct
truth = (np.arange(10, dtype=float)[::-1] + 1) * 2
npt.assert_almost_equal(energy_decay_curve.time[0], truth)
@pytest.mark.parametrize("is_energy", [True, False])
def test_schroeder_integration_multi_cdim(is_energy):
"""Simple impulse response."""
factor = 2 if is_energy else np.sqrt(2)
data = pf.Signal(np.ones((2, 1, 10))*factor, sampling_rate=10)
energy_decay_curve = ra.edc.schroeder_integration(
data, is_energy=is_energy)
# test if the shape is correct
npt.assert_array_equal(energy_decay_curve.time.shape, data.time.shape)
# test if the values are correct
truth = (np.arange(10, dtype=float)[::-1] + 1) * 2
npt.assert_almost_equal(energy_decay_curve.time[0, 0], truth)
npt.assert_almost_equal(energy_decay_curve.time[1, 0], truth)
def test_edc_eyring():
alphas = [0.9, 0.1]
surfaces = [2, 5*2]
volume = 2*2*2
times = np.linspace(0, 0.25, 50)
edc = ra.parametric.energy_decay_curve_analytic(
surfaces, alphas, volume, times, method='eyring', air_absorption=False)
truth = array([
1.00000000e+00, 8.39817186e-01, 7.05292906e-01, 5.92317103e-01,
4.97438083e-01, 4.17757051e-01, 3.50839551e-01, 2.94641084e-01,
2.47444646e-01, 2.07808266e-01, 1.74520953e-01, 1.46565696e-01,
1.23088390e-01, 1.03371746e-01, 8.68133684e-02, 7.29073588e-02,
6.12288529e-02, 5.14210429e-02, 4.31842755e-02, 3.62668968e-02,
3.04575632e-02, 2.55787850e-02, 2.14815032e-02, 1.80405356e-02,
1.51507518e-02, 1.27238618e-02, 1.06857178e-02, 8.97404943e-03,
7.53656094e-03, 6.32933340e-03, 5.31548296e-03, 4.46403394e-03,
3.74897242e-03, 3.14845147e-03, 2.64412365e-03, 2.22058049e-03,
1.86488165e-03, 1.56615966e-03, 1.31528780e-03, 1.10460130e-03,
9.27663155e-04, 7.79067460e-04, 6.54274242e-04, 5.49470753e-04,
4.61454981e-04, 3.87537824e-04, 3.25460924e-04, 2.73327678e-04,
2.29545281e-04, 1.92776072e-04,
])
npt.assert_almost_equal(edc, truth)
def test_edc_sabine():
alphas = [0.9, 0.1]
surfaces = [2, 5*2]
volume = 2*2*2
times = np.linspace(0, 0.25, 50)
edc = ra.parametric.energy_decay_curve_analytic(
surfaces, alphas, volume, times, method='sabine', air_absorption=False)
truth = array([
1.00000000e+00, 8.57869258e-01, 7.35939663e-01, 6.31340013e-01,
5.41607188e-01, 4.64628156e-01, 3.98590212e-01, 3.41938289e-01,
2.93338346e-01, 2.51645949e-01, 2.15879324e-01, 1.85196235e-01,
1.58874157e-01, 1.36293255e-01, 1.16921793e-01, 1.00303612e-01,
8.60473853e-02, 7.38174065e-02, 6.33256837e-02, 5.43251573e-02,
4.66038824e-02, 3.99800380e-02, 3.42976455e-02, 2.94228957e-02,
2.52409977e-02, 2.16534759e-02, 1.85758513e-02, 1.59356518e-02,
1.36707058e-02, 1.17276782e-02, 1.00608146e-02, 8.63086356e-03,
7.40415251e-03, 6.35179482e-03, 5.44900951e-03, 4.67453774e-03,
4.01014222e-03, 3.44017773e-03, 2.95122272e-03, 2.53176324e-03,
2.17192185e-03, 1.86322499e-03, 1.59840344e-03, 1.37122117e-03,
1.17632849e-03, 1.00913605e-03, 8.65706791e-04, 7.42663242e-04,
6.37107964e-04, 5.46555336e-04,
])
npt.assert_almost_equal(edc, truth)