Skip to content

Commit

Permalink
Merge pull request #258 from neuropsychology/dev
Browse files Browse the repository at this point in the history
0.0.38
  • Loading branch information
DominiqueMakowski authored Jun 28, 2020
2 parents 6514760 + b973289 commit cb37d83
Show file tree
Hide file tree
Showing 194 changed files with 8,638 additions and 1,294 deletions.
3 changes: 2 additions & 1 deletion .binder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ neurokit2
pandas
matplotlib
seaborn
numpy
numpy
pywt
4 changes: 2 additions & 2 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ engines:
E303:
enabled: false


checks:
argument-count:
enabled: false
Expand All @@ -32,11 +31,12 @@ checks:
similar-code:
enabled: false
identical-code:
enabled: true
enabled: false

exclude_patterns:
- "tests/"
- "scripts/"
- "benchmarks/"
- "data/"
- "docs/img/"
- "docs/readme/"
23 changes: 12 additions & 11 deletions .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ Now, navigate to the folder where your script is by typing ``cd C:\the\folder\of
isort myfile.py -l 120 --balanced --multi-line 3 --lines-between-types 1 --lines-after-imports 2 --trailing-comma
black myfile.py --line-length 120
docformatter myfile.py --wrap-summaries 120 --wrap-descriptions 113 --blank --make-summary-multi-line --in-place
docformatter myfile.py --wrap-summaries 120 --wrap-descriptions 113 --blank --in-place
flake8 myfile.py --max-line-length=127 --max-complexity=10 --ignore E303,C901,E203,W503
pylint myfile.py --max-line-length=127 --load-plugins=pylint.extensions.docparams --load-plugins=pylint.extensions.docstyle --variable-naming-style=any --argument-naming-style=any --reports=n --suggestion-mode=y --disable=E303 --disable=R0913 --disable=R0801 --disable=C0114 --disable=E203 --disable=E0401 --disable=W9006 --disable=C0330 --disable=R0914 --disable=R0912 --disable=R0915 --disable=W0102 --disable=W0511 --disable=C1801 --disable=C0111 --disable=R1705 --disable=R1720 --disable=C0301 --disable=C0415 --disable=C0103 --disable=C0302 --disable=R1716 --disable=W0632 --disable=E1136
pylint myfile.py --max-line-length=127 --load-plugins=pylint.extensions.docparams --load-plugins=pylint.extensions.docstyle --variable-naming-style=any --argument-naming-style=any --reports=n --suggestion-mode=y --disable=E303 --disable=R0913 --disable=R0801 --disable=C0114 --disable=E203 --disable=E0401 --disable=W9006 --disable=C0330 --disable=R0914 --disable=R0912 --disable=R0915 --disable=W0102 --disable=W0511 --disable=C1801 --disable=C0111 --disable=R1705 --disable=R1720 --disable=C0301 --disable=C0415 --disable=C0103 --disable=C0302 --disable=R1716 --disable=W0632 --disable=E1136 --extension-pkg-whitelist=numpy
The first three commands will make some modifications to your code so that it is nicely formatted, while the two last will run some checks to detect any additional issues. Please try to fix them!

*PS:* If you want to check the whole package, just replace 'myfile.py' by 'neurokit2' and add ``--recursive`` to ``isort`` and ``docformatter``.
*PS:* If you want to check the whole package (i.e., all the files of the package), run:

.. code-block::
isort neurokit2 -l 120 --balanced --multi-line 3 --lines-between-types 1 --lines-after-imports 2 --trailing-comma --skip neurokit2/complexity/__init__.py --recursive
black neurokit2 --line-length 120
docformatter neurokit2 --wrap-summaries 120 --wrap-descriptions 113 --blank --in-place --recursive
flake8 neurokit2 --exclude neurokit2/__init__.py --max-line-length=127 --max-complexity=10 --ignore E303,C901,E203,W503
pylint neurokit2 --max-line-length=127 --load-plugins=pylint.extensions.docparams --load-plugins=pylint.extensions.docstyle --variable-naming-style=any --argument-naming-style=any --reports=n --suggestion-mode=y --disable=E303 --disable=R0913 --disable=R0801 --disable=C0114 --disable=E203 --disable=E0401 --disable=W9006 --disable=C0330 --disable=R0914 --disable=R0912 --disable=R0915 --disable=W0102 --disable=W0511 --disable=C1801 --disable=C0111 --disable=R1705 --disable=R1720 --disable=C0301 --disable=C0415 --disable=C0103 --disable=C0302 --disable=R1716 --disable=W0632 --disable=E1136 --extension-pkg-whitelist=numpy --exit-zero
Avoid Semantic Errors
^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -58,14 +67,6 @@ Most errors detected by our code checks can be easily automated with ``isort``,

- Missing function arguments in ``Parameters`` and ``Returns``.
- In internal functions, missing ``Returns`` section detected only if ``Parameters`` is documented but is not followed by returns documentation.
- Failure to detect parameter/return type documentation when including commas:

.. code-block::
y_values : list, array or Series
will result in a ``pylint`` error like ``W9015: "y_values" missing in parameter documentation (missing-param-doc)`` so write it as such ``y_values : list or array or Series``.

- Failure to detect documentation of arguments when they are done simultaneously in one line:

.. code-block::
Expand Down
18 changes: 17 additions & 1 deletion .github/release-drafter-config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
name-template: '$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'

version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch

template: |
## 🚀 What’s New
$CHANGES
## 👏 Thanks to
$CONTRIBUTORS
$CONTRIBUTORS
5 changes: 2 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install https://github.com/DominiqueMakowski/popularipy/zipball/master
cd $GITHUB_WORKSPACE
python setup.py install
cd $GITHUB_WORKSPACE && pip install .[test]
- name: Run README_examples.py
run: |
Expand All @@ -30,4 +29,4 @@ jobs:
run: |
python -m pip install --upgrade setuptools pip wheel twine
python setup.py sdist bdist_wheel
python -m twine check dist/*
python -m twine check dist/*
18 changes: 18 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 🚀 Release Drafter

on:
push:
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: release-drafter-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 changes: 18 additions & 9 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,40 @@ jobs:
python -m pip install tox-gh-actions
tox
- name: Check isort (check import calls)
- name: Fix code style with isort (import calls)
run: |
python -m pip install isort
isort neurokit2 --recursive -l 120 --balanced --multi-line 3 --lines-between-types 1 --lines-after-imports 2 --trailing-comma --skip neurokit2/complexity/__init__.py --check --diff
isort neurokit2 --recursive -l 120 --balanced --multi-line 3 --lines-between-types 1 --lines-after-imports 2 --trailing-comma --skip neurokit2/complexity/__init__.py --diff
- name: Detect style errors that can be fixed by running black
- name: Fix code style with black (line lengths)
run: |
pip install black
# The GitHub editor is 127 chars wide. See https://black.readthedocs.io/en/stable/installation_and_usage.html
black neurokit2 --line-length 120 --check
black neurokit2 --line-length 120 .
- name: Check docstrings with docformatter
- name: Fix code style with docformatter (docstrings)
run: |
pip install docformatter
# See https://github.com/myint/docformatter
docformatter neurokit2 --recursive --wrap-summaries 120 --wrap-descriptions 113 --blank --pre-summary-newline --make-summary-multi-line
docformatter neurokit2 --wrap-summaries 120 --wrap-descriptions 113 --blank --make-summary-multi-line --recursive
- name: Detect style errors with flake8
- name: Detect remaining style errors with flake8
run: |
pip install flake8
# The GitHub editor is 127 chars wide. See https://flake8.pycqa.org/en/latest/user/configuration.html
flake8 neurokit2 --exclude neurokit2/__init__.py --max-line-length=127 --max-complexity=10 --ignore E303,C901,E203,W503
- name: Detect style errors with Pylint (fail under)
- name: Detect remaining style errors with Pylint (fail under)
run: |
pip install pylint-fail-under
# See http://pylint.pycqa.org/en/latest/index.html
pylint-fail-under neurokit2 --max-line-length=127 --load-plugins=pylint.extensions.docparams --load-plugins=pylint.extensions.docstyle --variable-naming-style=any --argument-naming-style=any --reports=n --suggestion-mode=y --disable=E303 --disable=R0913 --disable=R0801 --disable=C0114 --disable=E203 --disable=E0401 --disable=W9006 --disable=C0330 --disable=R0914 --disable=R0912 --disable=R0915 --disable=W0102 --disable=W0511 --disable=C1801 --disable=C0111 --disable=R1705 --disable=R1720 --disable=C0301 --disable=C0415 --disable=C0103 --disable=C0302 --disable=R1716 --disable=W0632 --disable=E1136 --exit-zero --fail_under 9.97
pylint-fail-under neurokit2 --max-line-length=127 --load-plugins=pylint.extensions.docparams --load-plugins=pylint.extensions.docstyle --variable-naming-style=any --argument-naming-style=any --reports=n --suggestion-mode=y --disable=E303 --disable=R0913 --disable=R0801 --disable=C0114 --disable=E203 --disable=E0401 --disable=W9006 --disable=C0330 --disable=R0914 --disable=R0912 --disable=R0915 --disable=W0102 --disable=W0511 --disable=C1801 --disable=C0111 --disable=R1705 --disable=R1720 --disable=C0301 --disable=C0415 --disable=C0103 --disable=C0302 --disable=R1716 --disable=W0632 --disable=E1136 --extension-pkg-whitelist=numpy --exit-zero --fail_under 9.95
- name: Commit changes
uses: EndBug/add-and-commit@v4
with:
message: "Commit style fixes"
add: "*.py"
cwd: "./neurokit2/"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: 📊 Tests

# on: [push, pull_request]
on: pull_request
on:
# Trigger the workflow on push to master branch or pull request
push:
branches:
- master
pull_request:

jobs:
build:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@ data/ludb/mit-bih-normal-sinus-rhythm-database-1.0.0/*
data/ludb/ECGs.csv
data/ludb/Rpeaks.csv
benchmarks/ecg_preprocessing/make_data.py
data/eogdb/eogdb.csv
data/eogdb/eogdb_task1.csv
data/eogdb/eogdb_task2.csv
data/eogdb/eogdb_task3.csv
data/eogdb/eogdb_task4.csv
116 changes: 112 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Contributing
:target: https://github.com/neuropsychology/NeuroKit/blob/master/LICENSE
:alt: License

.. image:: https://github.com/neuropsychology/neurokit/workflows/%E2%9C%A8%20Style/badge.svg
.. image:: https://github.com/neuropsychology/neurokit/workflows/%E2%9C%A8%20Style/badge.svg?branch=master
:target: https://github.com/neuropsychology/NeuroKit/actions
:alt: GitHub CI

Expand Down Expand Up @@ -133,6 +133,8 @@ Examples
- `Extract and Visualize Individual Heartbeats <https://neurokit2.readthedocs.io/en/latest/examples/heartbeats.html>`_
- `Locate P, Q, S and T waves in ECG <https://neurokit2.readthedocs.io/en/latest/examples/ecg_delineate.html>`_
- `Complexity Analysis of Physiological Signals <https://neurokit2.readthedocs.io/en/latest/tutorials/complexity.html>`_
- `Analyze Electrooculography EOG data <https://neurokit2.readthedocs.io/en/latest/examples/eog.html>`_
- `Fit a function to a signal <https://neurokit2.readthedocs.io/en/latest/tutorials/fit_function.html>`_

*You can try out these examples directly* `in your browser <https://github.com/neuropsychology/NeuroKit/tree/master/docs/examples#cloud-based-interactive-examples>`_.

Expand Down Expand Up @@ -301,19 +303,41 @@ Photoplethysmography (PPG/BVP)
# Generate 15 seconds of PPG signal (recorded at 250 samples / second)
ppg = nk.ppg_simulate(duration=15, sampling_rate=250, heart_rate=70)
# Process it
signals, info = nk.ppg_process(ppg, sampling_rate=250)
# Visualize the processing
nk.ppg_plot(signals, sampling_rate=250)
Electrogastrography (EGG)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Consider `helping us develop it <https://neurokit2.readthedocs.io/en/latest/tutorials/contributing.html>`_!
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_ppg.png


Electrooculography (EOG)
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# Import EOG data
eog_signal = nk.data("eog_100hz")
# Process it
signals, info = nk.eog_process(eog_signal, sampling_rate=100)
# Plot
plot = nk.eog_plot(signals, sampling_rate=100)
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_eog.png



Electrogastrography (EGG)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Consider `helping us develop it <https://neurokit2.readthedocs.io/en/latest/tutorials/contributing.html>`_!


Physiological Data Analysis
----------------------------

Expand Down Expand Up @@ -390,6 +414,30 @@ Heart Rate Variability (HRV)
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_hrv.png


ECG Delineation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Delineate the QRS complex of an electrocardiac signal (ECG) including P-peaks, T-peaks, as well as their onsets and offsets.


.. code-block:: python
# Download data
ecg_signal = nk.data(dataset="ecg_3000hz")['ECG']
# Extract R-peaks locations
_, rpeaks = nk.ecg_peaks(ecg_signal, sampling_rate=3000)
# Delineate
signal, waves = nk.ecg_delineate(ecg_signal, rpeaks, sampling_rate=3000, method="dwt", show=True, show_type='all')
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_delineation.png
:target: https://neurokit2.readthedocs.io/en/latest/examples/ecg_delineate.html



Signal Processing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -424,6 +472,7 @@ Signal Processing
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_signalprocessing.png


Complexity (Entropy, Fractal Dimensions, ...)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -456,6 +505,65 @@ Complexity (Entropy, Fractal Dimensions, ...)
nk.entropy_approximate(signal)
Signal Decomposition
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python
# Create complex signal
signal = nk.signal_simulate(duration=10, frequency=1) # High freq
signal += 3 * nk.signal_simulate(duration=10, frequency=3) # Higher freq
signal += 3 * np.linspace(0, 2, len(signal)) # Add baseline and linear trend
signal += 2 * nk.signal_simulate(duration=10, frequency=0.1, noise=0) # Non-linear trend
signal += np.random.normal(0, 0.02, len(signal)) # Add noise
# Decompose signal using Empirical Mode Decomposition (EMD)
components = nk.signal_decompose(signal, method='emd')
nk.signal_plot(components) # Visualize components
# Recompose merging correlated components
recomposed = nk.signal_recompose(components, threshold=0.99)
nk.signal_plot(recomposed) # Visualize components
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_decomposition.png
:target: https://neurokit2.readthedocs.io/en/latest/

Signal Power Spectrum Density (PSD)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
# Generate signal with frequencies of 5, 20 and 30
signal = nk.signal_simulate(frequency=5) + 0.5*nk.signal_simulate(frequency=20) + nk.signal_simulate(frequency=30)
# Find Power Spectrum Density with different methods
# Mutlitaper
multitaper = nk.signal_psd(signal, method="multitapers", show=False, max_frequency=100)
# Welch
welch = nk.signal_psd(signal, method="welch", min_frequency=1, show=False, max_frequency=100)
# Burg
burg = nk.signal_psd(signal, method="burg", min_frequency=1, show=False, ar_order=15, max_frequency=100)
# Visualize the different methods together
fig, ax = plt.subplots()
ax.plot(welch["Frequency"], welch["Power"], label="Welch", color="#CFD8DC", linewidth=2)
ax.plot(multitaper["Frequency"], multitaper["Power"], label="Multitaper", color="#00695C", linewidth=2)
ax.plot(burg["Frequency"], burg["Power"], label="Burg", color="#0097AC", linewidth=2)
ax.set_title("Power Spectrum Density (PSD)")
ax.set_yscale('log')
ax.set_xlabel("Frequency (Hz)")
ax.set_ylabel("PSD (ms^2/Hz)")
ax.legend(loc="upper right")
# Plot 3 frequencies of generated signal
ax.axvline(5, color="#689F38", linewidth=3, ymax=0.95, linestyle="--")
ax.axvline(20, color="#689F38", linewidth=3, ymax=0.95, linestyle="--")
ax.axvline(30, color="#689F38", linewidth=3, ymax=0.95, linestyle="--")
.. image:: https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_psd.png
:target: https://neurokit2.readthedocs.io/en/latest/

Statistics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
9 changes: 6 additions & 3 deletions benchmarks/ecg_preprocessing/README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ matplotlib$use("Agg", force = TRUE)

# Benchmarking of ECG Preprocessing Methods

*This study can be referenced by* [*citing the package*](https://github.com/neuropsychology/NeuroKit#citation).

**We'd like to publish this study, but unfortunately we currently don't have the time. If you want to help to make it happen, please contact us!**

## Introduction

This work is a replication and extension of the work by @porr2019r, that compared the performance of different popular R-peak detectors.

Expand Down Expand Up @@ -180,9 +185,7 @@ library(easystats)
library(lme4)
data <- read.csv("data_detectors.csv", stringsAsFactors = FALSE) %>%
mutate(Database = ifelse(str_detect(Database, "GUDB"), paste0(str_replace(Database, "GUDB_", "GUDB ("), ")"), Database),
Method = fct_relevel(Method, "neurokit", "pantompkins1985", "hamilton2002", "martinez2003", "christov2004", "gamboa2008", "elgendi2010", "engzeemod2012", "kalidas2017", "rodrigues2020"),
Participant = paste0(Database, Participant))
mutate(Method = fct_relevel(Method, "neurokit", "pantompkins1985", "hamilton2002", "martinez2003", "christov2004", "gamboa2008", "elgendi2010", "engzeemod2012", "kalidas2017", "rodrigues2020"))
colors <- c("neurokit"="#E91E63", "pantompkins1985"="#f44336", "hamilton2002"="#FF5722", "martinez2003"="#FF9800", "christov2004"="#FFC107", "gamboa2008"="#4CAF50", "elgendi2010"="#009688", "engzeemod2012"="#2196F3", "kalidas2017"="#3F51B5", "rodrigues2020"="#9C27B0")
```
Expand Down
Loading

0 comments on commit cb37d83

Please sign in to comment.