-
-
Notifications
You must be signed in to change notification settings - Fork 437
/
Copy pathtests_bio.py
65 lines (52 loc) · 2.1 KB
/
tests_bio.py
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
import numpy as np
import neurokit2 as nk
def test_bio_process():
sampling_rate = 1000
# Create data
ecg = nk.ecg_simulate(duration=30, sampling_rate=sampling_rate)
rsp = nk.rsp_simulate(duration=30, sampling_rate=sampling_rate)
eda = nk.eda_simulate(duration=30, sampling_rate=sampling_rate, scr_number=3)
emg = nk.emg_simulate(duration=30, sampling_rate=sampling_rate, burst_number=3)
bio_df, bio_info = nk.bio_process(
ecg=ecg, rsp=rsp, eda=eda, emg=emg, sampling_rate=sampling_rate
)
# SCR components
scr = [val for key, val in bio_info.items() if "SCR" in key]
assert all(len(elem) == len(scr[0]) for elem in scr)
assert all(bio_info["SCR_Onsets"] < bio_info["SCR_Peaks"])
assert all(bio_info["SCR_Peaks"] < bio_info["SCR_Recovery"])
# RSP
assert all(bio_info["RSP_Peaks"] > bio_info["RSP_Troughs"])
assert len(bio_info["RSP_Peaks"]) == len(bio_info["RSP_Troughs"])
# EMG
assert all(bio_info["EMG_Offsets"] > bio_info["EMG_Onsets"])
assert len(bio_info["EMG_Offsets"] == len(bio_info["EMG_Onsets"]))
def test_bio_analyze():
# Example with event-related analysis
data = nk.data("bio_eventrelated_100hz")
df, info = nk.bio_process(
ecg=data["ECG"],
rsp=data["RSP"],
eda=data["EDA"],
keep=data["Photosensor"],
sampling_rate=100,
)
events = nk.events_find(
data["Photosensor"],
threshold_keep="below",
event_conditions=["Negative", "Neutral", "Neutral", "Negative"],
)
epochs = nk.epochs_create(
df, events, sampling_rate=100, epochs_start=-0.1, epochs_end=1.9
)
event_related = nk.bio_analyze(epochs)
assert len(event_related) == len(epochs)
labels = [int(i) for i in event_related["Label"]]
assert labels == list(np.arange(1, len(epochs) + 1))
# Example with interval-related analysis
data = nk.data("bio_resting_8min_100hz")
df, info = nk.bio_process(
ecg=data["ECG"], rsp=data["RSP"], eda=data["EDA"], sampling_rate=100
)
interval_related = nk.bio_analyze(df)
assert len(interval_related) == 1