Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 166c783

Browse files
author
Jaquier Aurélien Tristan
committed
Add extra_features_utils tests with test data
1 parent d8a954b commit 166c783

File tree

3 files changed

+315
-0
lines changed

3 files changed

+315
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""Tests for ephys.extra_features_utils"""
2+
3+
import os
4+
5+
import numpy
6+
import pytest
7+
8+
from bluepyopt import ephys
9+
10+
11+
testdata_dir = os.path.join(
12+
os.path.dirname(os.path.abspath(__file__)), 'testdata'
13+
)
14+
waveforms_fpath = os.path.join(testdata_dir, 'mean_waveforms.dat')
15+
waveforms = numpy.loadtxt(waveforms_fpath)
16+
waveform = numpy.array([waveforms[0]])
17+
sampling_freq = 10000
18+
19+
def test_peak_to_valley():
20+
"""ephys.extra_features_utils: Test peak_to_valley"""
21+
ptv = ephys.extra_features_utils.peak_to_valley(waveform, sampling_freq)
22+
assert len(ptv) == 1
23+
assert ptv[0] == pytest.approx(0.0013)
24+
25+
26+
def test_peak_trough_ratio():
27+
"""ephys.extra_features_utils: Test peak_trough_ratio"""
28+
ptratio = ephys.extra_features_utils.peak_trough_ratio(waveform)
29+
assert len(ptratio) == 1
30+
print(ptratio)
31+
assert ptratio[0] == pytest.approx(0.53804035)
32+
33+
34+
def test_halfwidth():
35+
"""ephys.extra_features_utils: Test halfwidth"""
36+
ret = ephys.extra_features_utils.halfwidth(waveform, sampling_freq, True)
37+
assert len(ret) == 3
38+
39+
hw = ephys.extra_features_utils.halfwidth(waveform, sampling_freq)
40+
assert len(hw) == 1
41+
assert hw[0] == pytest.approx(0.0015)
42+
43+
44+
def test_repolarization_slope():
45+
"""ephys.extra_features_utils: Test repolarization_slope"""
46+
ret = ephys.extra_features_utils.repolarization_slope(waveform, sampling_freq, True)
47+
assert len(ret) == 2
48+
49+
rslope = ephys.extra_features_utils.repolarization_slope(waveform, sampling_freq)
50+
assert len(rslope) == 1
51+
assert rslope[0] == pytest.approx(73.12572131)
52+
53+
54+
def test_recovery_slope():
55+
"""ephys.extra_features_utils: Test recovery_slope"""
56+
window=0.7
57+
rslope = ephys.extra_features_utils.recovery_slope(waveform, sampling_freq, window=window)
58+
assert len(rslope) == 1
59+
assert rslope[0] == pytest.approx(-3.63355521)
60+
61+
62+
def test_peak_image():
63+
"""ephys.extra_features_utils: Test peak_image"""
64+
rel_peaks = ephys.extra_features_utils.peak_image(waveforms, sign="negative")
65+
assert len(rel_peaks) == 209
66+
assert rel_peaks[0] == pytest.approx(0.06084468)
67+
68+
rel_peaks = ephys.extra_features_utils.peak_image(waveforms, sign="positive")
69+
assert len(rel_peaks) == 209
70+
assert rel_peaks[0] == pytest.approx(0.10850117)
71+
72+
73+
def test_relative_amplitude():
74+
"""ephys.extra_features_utils: Test relative_amplitude"""
75+
rel_amp = ephys.extra_features_utils.relative_amplitude(waveforms, sign="negative")
76+
assert len(rel_amp) == 209
77+
assert rel_amp[0] == pytest.approx(0.09513392)
78+
79+
rel_amp = ephys.extra_features_utils.relative_amplitude(waveforms, sign="positive")
80+
assert len(rel_amp) == 209
81+
assert rel_amp[0] == pytest.approx(0.2135929)
82+
83+
84+
def test_peak_time_diff():
85+
"""ephys.extra_features_utils: Test peak_time_diff"""
86+
peak_t = ephys.extra_features_utils.peak_time_diff(waveforms, sampling_freq, sign="negative")
87+
assert len(peak_t) == 209
88+
assert peak_t[0] == pytest.approx(0.0009)
89+
90+
peak_t = ephys.extra_features_utils.peak_time_diff(waveforms, sampling_freq, sign="positive")
91+
assert len(peak_t) == 209
92+
assert peak_t[0] == pytest.approx(0.0007)
93+
94+
95+
def test__get_trough_and_peak_idx():
96+
"""ephys.extra_features_utils: Test _get_trough_and_peak_idx"""
97+
t_idx, p_idx = ephys.extra_features_utils._get_trough_and_peak_idx(waveform)
98+
assert t_idx == 102
99+
assert p_idx == 115
100+
101+
102+
def test_calculate_features():
103+
"""ephys.extra_features_utils: Test calculate_features"""
104+
feats = ephys.extra_features_utils.calculate_features(waveforms, sampling_freq)
105+
for feature_name in ephys.extra_features_utils.all_1D_features:
106+
assert feature_name in feats
19.9 MB
Binary file not shown.

0 commit comments

Comments
 (0)