Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.6 #863

Merged
merged 137 commits into from
Sep 12, 2023
Merged

0.2.6 #863

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
d2c74f8
0.2.6
DominiqueMakowski Jul 9, 2023
1c1651d
Merge branch 'master' into dev
DominiqueMakowski Jul 9, 2023
ac08ef3
[FIX] KeyError in _eventrelated_addinfo
SimonLafran Jul 14, 2023
a802b57
Merge pull request #868 from SimonLafran/fix-addinfo-indexing
DominiqueMakowski Jul 17, 2023
0bd4ccf
ecg_process: improve documentation and readability
jchromik Jul 25, 2023
272402e
draft
DominiqueMakowski Aug 1, 2023
8e66b77
add xdf reader
DominiqueMakowski Aug 1, 2023
3b32801
add example data
DominiqueMakowski Aug 1, 2023
53bbbe9
minor
DominiqueMakowski Aug 1, 2023
38ab175
fix interpolation
DominiqueMakowski Aug 1, 2023
0a19164
fix
DominiqueMakowski Aug 1, 2023
7212faf
don't name index
DominiqueMakowski Aug 1, 2023
bfbf012
ecg_process: revert to keyword args instead of positional args
jchromik Aug 3, 2023
ed20882
add function to download zip files
danibene Aug 8, 2023
d068a88
change path to data to master branch
danibene Aug 8, 2023
8f57246
download zip if expected folder is not there
danibene Aug 8, 2023
61a3547
ensure that destination_directory is Path
danibene Aug 8, 2023
e8c0a0c
delete comments that seem to be copying mistake
danibene Aug 8, 2023
ec5ceb1
allow to specify zip filename
danibene Aug 9, 2023
91cd1ec
merge to avoid duplicates
DominiqueMakowski Aug 9, 2023
ba219c0
fix edgecase
DominiqueMakowski Aug 9, 2023
f870193
Merge pull request #871 from jchromik/improve_docs_ecg_process
danibene Aug 10, 2023
22323a7
add random_state to complexity_symbolize
danibene Aug 11, 2023
50340da
update init
danibene Aug 11, 2023
7427cf3
refactor for just one arg for destination path
danibene Aug 11, 2023
d353f9e
set database_path as variable
danibene Aug 11, 2023
2e34a64
Revert "refactor for just one arg for destination path"
danibene Aug 11, 2023
d6c2d58
use pathlib
danibene Aug 11, 2023
d14357d
correct download url
danibene Aug 11, 2023
41840d6
allow for destination_path as optional arg
danibene Aug 11, 2023
47810f7
Merge pull request #881 from danibene/feature/seed_complexity_symbolize
danibene Aug 11, 2023
e7d8320
remove whitespace
danibene Aug 11, 2023
2302082
rename extracted folder to the desired name
danibene Aug 11, 2023
7050137
rename output for consistency
danibene Aug 11, 2023
1c42eb6
fix renaming
danibene Aug 11, 2023
9f978c4
auto download for mit arrhythmia
danibene Aug 11, 2023
394e32d
wip auto download ludb (not tested)
danibene Aug 11, 2023
9bbdd2c
Revert "wip auto download ludb (not tested)"
danibene Aug 11, 2023
0a2e20f
import neurokit2 as nk
danibene Aug 11, 2023
5750b79
import neurokit2 as nk
danibene Aug 11, 2023
66724c5
add option to not unzip file
danibene Aug 11, 2023
437f219
import pathlib for iconoclasticism and consistency
danibene Aug 11, 2023
71a2516
make destination_path optional arg
danibene Aug 11, 2023
e8f2d78
add upsample and fillmissing argument
DominiqueMakowski Aug 13, 2023
4a20e15
Merge pull request #874 from neuropsychology/read_xdf
DominiqueMakowski Aug 13, 2023
81b3fb9
minor format
DominiqueMakowski Aug 13, 2023
3127dea
minor docs
DominiqueMakowski Aug 13, 2023
1f55653
Add ppg_peaks()
DominiqueMakowski Aug 13, 2023
0356dfc
replace by ppg_peaks in ppg_process
DominiqueMakowski Aug 13, 2023
0d4b48e
better ecg_segment() plot + ability to return plot
DominiqueMakowski Aug 13, 2023
fd4ae67
minor style
DominiqueMakowski Aug 13, 2023
39033c0
Add ppg_segment()
DominiqueMakowski Aug 13, 2023
8052937
style
DominiqueMakowski Aug 13, 2023
84c9f79
fix test
DominiqueMakowski Aug 13, 2023
8c90693
adaptable alpha
DominiqueMakowski Aug 13, 2023
2d93a92
Minor Update README.rst
ParthaPratimBanik Aug 15, 2023
69e62d8
refactor to add download_from_url()
danibene Aug 16, 2023
1f1d61a
make static ECG and PPG plots more modular
DominiqueMakowski Aug 16, 2023
9da1d9c
adjust segments window
DominiqueMakowski Aug 16, 2023
17fd1e7
Update README.rst
ParthaPratimBanik Aug 17, 2023
ed5e999
Merge pull request #886 from ParthaPratimBanik/readme_fix
danibene Aug 19, 2023
4f704ae
Merge branch 'dev' into feature/auto_download_data
DominiqueMakowski Aug 22, 2023
0f3457a
fix warnings
DominiqueMakowski Aug 22, 2023
0ec80b1
style
DominiqueMakowski Aug 22, 2023
68702bd
add RAV to intervalrelated
DominiqueMakowski Aug 22, 2023
ec4c058
Update neurokit2/data/database.py
DominiqueMakowski Aug 22, 2023
4b3ac76
Update neurokit2/data/database.py
DominiqueMakowski Aug 22, 2023
899ffa7
Merge pull request #882 from danibene/feature/auto_download_data
danibene Aug 22, 2023
0fa4781
style
DominiqueMakowski Aug 22, 2023
780d3ed
Update database.py
DominiqueMakowski Aug 22, 2023
0da7bdc
fix test
DominiqueMakowski Aug 22, 2023
6a7c382
improve plots
DominiqueMakowski Aug 22, 2023
3efa05f
return fixpeaks info
DominiqueMakowski Aug 22, 2023
f76c2e9
add test
DominiqueMakowski Aug 22, 2023
53a9239
new testing versions specification
DominiqueMakowski Aug 22, 2023
a04c5a8
revert
DominiqueMakowski Aug 22, 2023
5da5e8c
remove 3.12
DominiqueMakowski Aug 22, 2023
b36c24f
re-include 3.12
DominiqueMakowski Aug 22, 2023
6834e14
revert again
DominiqueMakowski Aug 22, 2023
942ceb5
Merge pull request #873 from neuropsychology/rsp_rav
DominiqueMakowski Aug 22, 2023
8932606
Merge pull request #883 from neuropsychology/ppg_peaks
DominiqueMakowski Aug 22, 2023
88558c4
Merge branch 'dev' into ppg_fixpeaks
DominiqueMakowski Aug 22, 2023
fd90537
make fixpeak kubios plot more generic
DominiqueMakowski Aug 22, 2023
c3d6d0c
fix bugs
DominiqueMakowski Aug 23, 2023
85f63a5
fixes
DominiqueMakowski Aug 23, 2023
11d7a4f
much cleaner ecg_plot code
DominiqueMakowski Aug 23, 2023
f435bb5
style
DominiqueMakowski Aug 23, 2023
48ec225
add systole and diastole on ecg_plot
DominiqueMakowski Aug 23, 2023
2b6f077
add QRS to ecg_plot
DominiqueMakowski Aug 23, 2023
ea3a709
do the same for ppg_plot
DominiqueMakowski Aug 23, 2023
06a2a22
color
DominiqueMakowski Aug 23, 2023
5c36de5
README fixes
DominiqueMakowski Aug 23, 2023
aded568
Breaking: info in eda_plot
DominiqueMakowski Aug 23, 2023
ba7c2df
update README
DominiqueMakowski Aug 23, 2023
e739f04
update README figs
DominiqueMakowski Aug 23, 2023
6493c6e
Update ecg_clean.py
DominiqueMakowski Aug 23, 2023
4e154ac
fix tests
DominiqueMakowski Aug 23, 2023
ac18b62
Merge branch 'dev' into ppg_fixpeaks
DominiqueMakowski Aug 23, 2023
5ee4830
style
DominiqueMakowski Aug 23, 2023
2c5c523
style
DominiqueMakowski Aug 23, 2023
a89f21c
fix tests
DominiqueMakowski Aug 23, 2023
e5d9d6e
docstrings
DominiqueMakowski Aug 23, 2023
b47335f
Update ppg_process.py
DominiqueMakowski Aug 23, 2023
4bf8071
Merge pull request #889 from neuropsychology/ppg_fixpeaks
DominiqueMakowski Aug 23, 2023
e0b4f69
add fixpeak to ppg_peaks
DominiqueMakowski Aug 23, 2023
781ebd6
fix examples
DominiqueMakowski Aug 23, 2023
29f666f
Merge pull request #890 from neuropsychology/ppg_fixpeaks
DominiqueMakowski Aug 23, 2023
045ae92
fix example
DominiqueMakowski Aug 23, 2023
60884fb
fix alpha specification for segment plots
DominiqueMakowski Aug 28, 2023
e7e0251
update names of features in docstring to match name in output
danibene Sep 1, 2023
42f3ca7
fix plural in docstring
danibene Sep 1, 2023
1ca1c5d
Update ppg_intervalrelated.py
DominiqueMakowski Sep 4, 2023
4fdc9df
bump checkout version to 4
DominiqueMakowski Sep 5, 2023
d84ea7e
fix typo in PULL_REQUEST_TEMPLATE.md
danibene Sep 6, 2023
d628415
address FutureWarning in indexing heartbeat
danibene Sep 6, 2023
4647be8
address FutureWarning in indexing heartbeat (see previous commit)
danibene Sep 6, 2023
0a4daf4
Revert "address FutureWarning in indexing heartbeat"
danibene Sep 6, 2023
143579e
Revert "fix typo in PULL_REQUEST_TEMPLATE.md"
danibene Sep 6, 2023
97b5a97
Revert "Revert "fix typo in PULL_REQUEST_TEMPLATE.md""
danibene Sep 6, 2023
619c8d6
Revert "address FutureWarning in indexing heartbeat (see previous com…
danibene Sep 6, 2023
d867214
Merge pull request #896 from danibene/docs/hrv_feature_names
DominiqueMakowski Sep 7, 2023
b1bc46f
use .loc to index heartbeat
danibene Sep 7, 2023
a71fa3c
replace fillna with ffill
danibene Sep 7, 2023
4d5d7e2
add missing parentheses
danibene Sep 7, 2023
f24637b
replace fillna with ffill in rsp_phase.py
danibene Sep 7, 2023
4b878ae
replace [0] with iloc[0] in fractal_psdslope.py?
danibene Sep 7, 2023
2a2c058
Update entropy_spectral.py
DominiqueMakowski Sep 11, 2023
432e992
Update ecg_quality.py
DominiqueMakowski Sep 11, 2023
1945e39
Update ecg_quality.py
DominiqueMakowski Sep 11, 2023
e38efbe
Update emg_plot.py
DominiqueMakowski Sep 11, 2023
6855dca
Update emg_activation.py
DominiqueMakowski Sep 11, 2023
ce6fc0b
Update emg_activation.py
DominiqueMakowski Sep 11, 2023
4deecdf
Update signal_binarize.py
DominiqueMakowski Sep 11, 2023
c45d27c
docs
DominiqueMakowski Sep 11, 2023
01ae274
docs
DominiqueMakowski Sep 11, 2023
65581dd
Update standardize.py
DominiqueMakowski Sep 12, 2023
ecb4752
Merge pull request #898 from danibene/fix/docs_build_warning
DominiqueMakowski Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
DominiqueMakowski committed Aug 22, 2023
commit f76c2e93fff1aea4b1e7b14b2bdf585a299815b9
2 changes: 1 addition & 1 deletion neurokit2/rsp/rsp_rav.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def rsp_rav(

rsp = nk.rsp_simulate(duration=45, respiratory_rate=15)
cleaned = nk.rsp_clean(rsp, sampling_rate=1000)
peak_signal, info = nk.rsp_peaks(cleaned)
peak_signal, info = nk.rsp_peaks(cleaned, sampling_rate=1000)

amplitude = nk.rsp_amplitude(cleaned, peaks=peak_signal)

Expand Down
96 changes: 63 additions & 33 deletions tests/tests_rsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,35 @@

import neurokit2 as nk


random.seed(a=13, version=2)


def test_rsp_simulate():
rsp1 = nk.rsp_simulate(duration=20, length=3000, random_state=42)
assert len(rsp1) == 3000

rsp2 = nk.rsp_simulate(duration=20, length=3000, respiratory_rate=80, random_state=42)
rsp2 = nk.rsp_simulate(
duration=20, length=3000, respiratory_rate=80, random_state=42
)
# pd.DataFrame({"RSP1":rsp1, "RSP2":rsp2}).plot()
# pd.DataFrame({"RSP1":rsp1, "RSP2":rsp2}).hist()
assert len(nk.signal_findpeaks(rsp1, height_min=0.2)["Peaks"]) < len(
nk.signal_findpeaks(rsp2, height_min=0.2)["Peaks"]
)

rsp3 = nk.rsp_simulate(duration=20, length=3000, method="sinusoidal", random_state=42)
rsp4 = nk.rsp_simulate(duration=20, length=3000, method="breathmetrics", random_state=42)
rsp3 = nk.rsp_simulate(
duration=20, length=3000, method="sinusoidal", random_state=42
)
rsp4 = nk.rsp_simulate(
duration=20, length=3000, method="breathmetrics", random_state=42
)
# pd.DataFrame({"RSP3":rsp3, "RSP4":rsp4}).plot()
assert len(nk.signal_findpeaks(rsp3, height_min=0.2)["Peaks"]) > len(
nk.signal_findpeaks(rsp4, height_min=0.2)["Peaks"]
)


def test_rsp_simulate_legacy_rng():

rsp = nk.rsp_simulate(
duration=10,
sampling_rate=100,
Expand Down Expand Up @@ -68,7 +72,6 @@ def test_rsp_simulate_legacy_rng():
],
)
def test_rsp_simulate_all_rng_types(random_state, random_state_distort):

# Run rsp_simulate to test for errors (e.g. using methods like randint that are only
# implemented for RandomState but not Generator, or vice versa)
rsp = nk.rsp_simulate(
Expand All @@ -87,7 +90,6 @@ def test_rsp_simulate_all_rng_types(random_state, random_state_distort):


def test_rsp_clean():

sampling_rate = 100
duration = 120
rsp = nk.rsp_simulate(
Expand All @@ -98,7 +100,9 @@ def test_rsp_clean():
random_state=42,
)
# Add linear drift (to test baseline removal).
rsp += nk.signal_distort(rsp, sampling_rate=sampling_rate, linear_drift=True, random_state=42)
rsp += nk.signal_distort(
rsp, sampling_rate=sampling_rate, linear_drift=True, random_state=42
)

for method in ["khodadad2018", "biosppy", "hampel"]:
cleaned = nk.rsp_clean(rsp, sampling_rate=sampling_rate, method=method)
Expand Down Expand Up @@ -146,16 +150,20 @@ def test_rsp_clean():
distorted_sample[distort_locations] = 100
assert np.allclose(
nk.rsp_clean(
distorted_sample, sampling_rate=hampel_sampling_rate, method="hampel", window_length=1
distorted_sample,
sampling_rate=hampel_sampling_rate,
method="hampel",
window_length=1,
),
hampel_sample,
atol=1,
)


def test_rsp_peaks():

rsp = nk.rsp_simulate(duration=120, sampling_rate=1000, respiratory_rate=15, random_state=42)
rsp = nk.rsp_simulate(
duration=120, sampling_rate=1000, respiratory_rate=15, random_state=42
)
rsp_cleaned = nk.rsp_clean(rsp, sampling_rate=1000)
for method in ["khodadad2018", "biosppy", "scipy"]:
signals, info = nk.rsp_peaks(rsp_cleaned, method=method)
Expand All @@ -171,7 +179,6 @@ def test_rsp_peaks():


def test_rsp_amplitude():

rsp = nk.rsp_simulate(
duration=120,
sampling_rate=1000,
Expand All @@ -194,9 +201,22 @@ def test_rsp_amplitude():
assert np.abs(amplitude.mean() - 1) < 0.01


def test_rsp_process():
def test_rsp_rav():
rsp = nk.rsp_simulate(
duration=45, sampling_rate=50, respiratory_rate=15, random_state=42
)
peak_signal, _ = nk.rsp_peaks(rsp, sampling_rate=50)
amplitude = nk.rsp_amplitude(rsp, peaks=peak_signal)

rav = nk.rsp_rav(amplitude, peaks=peak_signal)
assert rav.shape[0] == 1 # Number of rows
assert np.isclose(rav["RAV_RMSSD"][0], 0.065551)

rsp = nk.rsp_simulate(duration=120, sampling_rate=1000, respiratory_rate=15, random_state=2)

def test_rsp_process():
rsp = nk.rsp_simulate(
duration=120, sampling_rate=1000, respiratory_rate=15, random_state=2
)
signals, _ = nk.rsp_process(rsp, sampling_rate=1000)

# Only check array dimensions since functions called by rsp_process have
Expand All @@ -220,32 +240,36 @@ def test_rsp_process():


def test_rsp_plot():

rsp = nk.rsp_simulate(duration=120, sampling_rate=1000, respiratory_rate=15, random_state=3)
rsp = nk.rsp_simulate(
duration=120, sampling_rate=1000, respiratory_rate=15, random_state=3
)
rsp_summary, _ = nk.rsp_process(rsp, sampling_rate=1000)
nk.rsp_plot(rsp_summary)
# This will identify the latest figure.
fig = plt.gcf()
assert len(fig.axes) == 5
titles = ["Raw and Cleaned Signal", "Breathing Rate", "Breathing Amplitude"]
for (ax, title) in zip(fig.get_axes(), titles):
for ax, title in zip(fig.get_axes(), titles):
assert ax.get_title() == title
plt.close(fig)


def test_rsp_eventrelated():

rsp, _ = nk.rsp_process(nk.rsp_simulate(duration=30, random_state=42))
epochs = nk.epochs_create(rsp, events=[5000, 10000, 15000], epochs_start=-0.1, epochs_end=1.9)
epochs = nk.epochs_create(
rsp, events=[5000, 10000, 15000], epochs_start=-0.1, epochs_end=1.9
)
rsp_eventrelated = nk.rsp_eventrelated(epochs)

# Test rate features
assert np.alltrue(
np.array(rsp_eventrelated["RSP_Rate_Min"]) < np.array(rsp_eventrelated["RSP_Rate_Mean"])
np.array(rsp_eventrelated["RSP_Rate_Min"])
< np.array(rsp_eventrelated["RSP_Rate_Mean"])
)

assert np.alltrue(
np.array(rsp_eventrelated["RSP_Rate_Mean"]) < np.array(rsp_eventrelated["RSP_Rate_Max"])
np.array(rsp_eventrelated["RSP_Rate_Mean"])
< np.array(rsp_eventrelated["RSP_Rate_Max"])
)

# Test amplitude features
Expand All @@ -262,23 +286,30 @@ def test_rsp_eventrelated():
assert len(rsp_eventrelated["Label"]) == 3

# Test warning on missing columns
with pytest.warns(nk.misc.NeuroKitWarning, match=r".*does not have an `RSP_Amplitude`.*"):
with pytest.warns(
nk.misc.NeuroKitWarning, match=r".*does not have an `RSP_Amplitude`.*"
):
first_epoch_key = list(epochs.keys())[0]
first_epoch_copy = epochs[first_epoch_key].copy()
del first_epoch_copy["RSP_Amplitude"]
nk.rsp_eventrelated({**epochs, first_epoch_key: first_epoch_copy})

with pytest.warns(nk.misc.NeuroKitWarning, match=r".*does not have an `RSP_Phase`.*"):
with pytest.warns(
nk.misc.NeuroKitWarning, match=r".*does not have an `RSP_Phase`.*"
):
first_epoch_key = list(epochs.keys())[0]
first_epoch_copy = epochs[first_epoch_key].copy()
del first_epoch_copy["RSP_Phase"]
nk.rsp_eventrelated({**epochs, first_epoch_key: first_epoch_copy})


def test_rsp_rrv():

rsp90 = nk.rsp_simulate(duration=60, sampling_rate=1000, respiratory_rate=90, random_state=42)
rsp110 = nk.rsp_simulate(duration=60, sampling_rate=1000, respiratory_rate=110, random_state=42)
rsp90 = nk.rsp_simulate(
duration=60, sampling_rate=1000, respiratory_rate=90, random_state=42
)
rsp110 = nk.rsp_simulate(
duration=60, sampling_rate=1000, respiratory_rate=110, random_state=42
)

cleaned90 = nk.rsp_clean(rsp90, sampling_rate=1000)
_, peaks90 = nk.rsp_peaks(cleaned90)
Expand Down Expand Up @@ -311,7 +342,6 @@ def test_rsp_rrv():


def test_rsp_intervalrelated():

data = nk.data("bio_resting_5min_100hz")
df, _ = nk.rsp_process(data["RSP"], sampling_rate=100)

Expand Down Expand Up @@ -346,14 +376,14 @@ def test_rsp_rvt():

@pytest.mark.parametrize(
"method_cleaning, method_peaks, method_rvt",
[("none", "scipy", "power2020"),
("biosppy", "biosppy", "power2020"),
("khodadad2018", "khodadad2018", "birn2006"),
("power2020", "scipy", "harrison2021"),
],
[
("none", "scipy", "power2020"),
("biosppy", "biosppy", "power2020"),
("khodadad2018", "khodadad2018", "birn2006"),
("power2020", "scipy", "harrison2021"),
],
)
def test_rsp_report(tmp_path, method_cleaning, method_peaks, method_rvt):

sampling_rate = 100

rsp = nk.rsp_simulate(
Expand Down