Skip to content

Commit

Permalink
Merge pull request #749 from neuropsychology/dev
Browse files Browse the repository at this point in the history
0.2.3
  • Loading branch information
DominiqueMakowski authored Feb 9, 2023
2 parents a1f317b + 08347f7 commit 8c56493
Show file tree
Hide file tree
Showing 33 changed files with 1,055 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.8"
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade setuptools pip wheel
python -m pip install tox-gh-actions
tox
- name: Fix code style with isort (import calls)
run: |
Expand All @@ -36,17 +34,17 @@ jobs:
# The GitHub editor is 127 chars wide. See https://black.readthedocs.io/en/stable/installation_and_usage.html
black neurokit2 --line-length 120 .
- name: Fix code style with docformatter (docstrings)
run: |
pip install docformatter
# See https://github.com/myint/docformatter
docformatter neurokit2 --wrap-summaries 120 --wrap-descriptions 113 --blank --make-summary-multi-line --recursive
# - name: Fix code style with docformatter (docstrings)
# run: |
# pip install docformatter
# # See https://github.com/myint/docformatter
# docformatter neurokit2 --wrap-summaries 120 --wrap-descriptions 113 --blank --make-summary-multi-line --recursive

- 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
flake8 neurokit2 --exclude neurokit2/__init__.py --max-line-length=127 --max-complexity=10 --ignore E303,C901,E203,W503,E712
- name: Detect remaining style errors with Pylint (fail under)
run: |
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def find_author():

project = "NeuroKit2"
copyright = f"2020–{datetime.datetime.now().year}"
author = '<a href="https://dominiquemakowski.github.io/">Dominique Makowski</a> and the <a href="https://github.com/neuropsychology/NeuroKit/blob/master/AUTHORS.rst">Team</a>'
author = '<a href="https://dominiquemakowski.github.io/">Dominique Makowski</a> and the <a href="https://github.com/neuropsychology/NeuroKit/blob/master/AUTHORS.rst">Team</a>. This documentation is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a> license.'

# The short X.Y version.
def find_version():
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/eeg_power/eeg_power.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# EEG Frequency Bands\n",
"## EEG Frequency Bands\n",
"\n",
"From fastest to slowest:\n",
"\n",
Expand All @@ -71,7 +71,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Preprocessing"
"## Preprocessing"
]
},
{
Expand Down Expand Up @@ -160,7 +160,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Frontal Alpha Asymmetry (FAA)"
"## Frontal Alpha Asymmetry (FAA)"
]
},
{
Expand Down Expand Up @@ -454,7 +454,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Frontal Midline Theta (FMT)\n",
"## Frontal Midline Theta (FMT)\n",
"\n",
"\n",
"\n"
Expand Down
1 change: 1 addition & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Physiological
rsp_rrv/rsp_rrv
eog_analyze/eog_analyze
signal_simulation/signal_simulation
ppg_report/ppg_report

EEG
=============
Expand Down
113 changes: 113 additions & 0 deletions docs/examples/ppg_report/ppg_report.html

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions docs/examples/ppg_report/ppg_report.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save Preprocessing Reports"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example can be referenced by [citing the package](https://neuropsychology.github.io/NeuroKit/cite_us.html).\n",
"\n",
"Reports are currently a **beta** feature (help us improve it!) only available for PPG signals. \n",
"\n",
"You can generate a report via the `report` argument in the processing function."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [],
"source": [
"# Note: this cell is hidden using the \"remove-input\" tag\n",
"import matplotlib.pyplot as plt\n",
"# Make bigger images\n",
"plt.rcParams['figure.figsize'] = [15, 5] \n",
"plt.rcParams['font.size']= 14"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"skip-execution"
]
},
"outputs": [],
"source": [
"# import neurokit2 as nk\n",
"\n",
"# Simulate PPG signal\n",
"# signal = nk.ppg_simulate(duration=30, sampling_rate=200, heart_rate=60)\n",
"\n",
"# Process signal and save report\n",
"# df, info = nk.ppg_process(ppg_signal = signal, report = \"ppg_report.html\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The raw signal, sampled at 1000 Hz, was preprocessed using a bandpass filter ([0.5 - 8 Hz], Butterworth 3rd order; following Elgendi et al., 2013).\n",
"\n",
"The peak detection was carried out using the method described in Elgendi et al. (2013).\n",
"\n",
"| PPG_Rate_Mean | PPG_Rate_SD |\n",
"|----------------:|--------------:|\n",
"| 93.7041 | 23.5124 |\n",
"\n",
"References\n",
"- Elgendi M, Norton I, Brearley M, Abbott D, Schuurmans D (2013) Systolic Peak Detection in Acceleration Photoplethysmograms Measured from Emergency Responders in Tropical Conditions. PLoS ONE 8(10): e76585. doi:10.1371/journal.pone.0076585.\n"
]
}
],
"source": [
"# Note: this cell is hidden using the \"remove-input\" tag\n",
"# import neurokit2 as nk\n",
"\n",
"# Simulate PPG signal\n",
"# signal = nk.ppg_simulate(duration=30, sampling_rate=200, heart_rate=60)\n",
"\n",
"# Process signal and save report\n",
"# df, info = nk.ppg_process(ppg_signal = signal, report = \"text\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It also saves a `html` file (see example here) with interactive plots.\n",
"\n",
"![](ppg_report.png)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.7 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "11938c6bc6919ae2720b4d5011047913343b08a43b18698fd82dedb0d4417594"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Binary file added docs/examples/ppg_report/ppg_report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion neurokit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .video import *

# Info
__version__ = "0.2.2"
__version__ = "0.2.3"


# Maintainer info
Expand Down
5 changes: 3 additions & 2 deletions neurokit2/complexity/entropy_fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def entropy_fuzzy(signal, delay=1, dimension=2, tolerance="sd", approximate=Fals
Tolerance (often denoted as *r*), distance to consider two data points as similar. If
``"sd"`` (default), will be set to :math:`0.2 * SD_{signal}`. See
:func:`complexity_tolerance` to estimate the optimal value for this parameter.
approximate : bool
If ``True``, will compute the fuzzy approximate entropy (FuzzyApEn).
**kwargs
Other arguments.
Expand All @@ -38,8 +40,6 @@ def entropy_fuzzy(signal, delay=1, dimension=2, tolerance="sd", approximate=Fals
info : dict
A dictionary containing additional information regarding the parameters used
to compute fuzzy entropy.
approximate : bool
If ``True``, will compute the fuzzy approximate entropy (FuzzyApEn).
See Also
--------
Expand All @@ -62,6 +62,7 @@ def entropy_fuzzy(signal, delay=1, dimension=2, tolerance="sd", approximate=Fals
fuzzycapen, parameters = nk.entropy_fuzzy(signal, approximate=True, corrected=True)
fuzzycapen
References
----------
* Ishikawa, A., & Mieno, H. (1979). The fuzzy entropy concept and its application. Fuzzy Sets
Expand Down
4 changes: 3 additions & 1 deletion neurokit2/complexity/entropy_multiscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def entropy_multiscale(
"""
# Sanity checks
if isinstance(signal, (np.ndarray, pd.DataFrame)) and signal.ndim > 1:
raise ValueError("Multidimensional inputs (e.g., matrices or multichannel data) are not supported yet.")
raise ValueError(
"Multidimensional inputs (e.g., matrices or multichannel data) are not supported yet."
)
# Prevent multiple arguments error in case 'delay' is passed in kwargs
if "delay" in kwargs:
kwargs.pop("delay")
Expand Down
16 changes: 11 additions & 5 deletions neurokit2/complexity/fractal_tmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import pandas as pd
import scipy.stats
from packaging import version

from ..signal import signal_surrogate
from .fractal_dfa import fractal_dfa
Expand All @@ -11,8 +12,8 @@ def fractal_tmf(signal, n=40, show=False, **kwargs):
"""**Multifractal Nonlinearity (tMF)**
The Multifractal Nonlinearity index (*t*\\MF) is the *t*\\-value resulting from the comparison
between the multifractality of the signal (measured by the spectrum width, see
:func:`.fractal_dfa`) and the multifractality of linearized
of the multifractality of the signal (measured by the spectrum width, see
:func:`.fractal_dfa`) with the multifractality of linearized
:func:`surrogates <.signal_surrogate>` obtained by the IAAFT method (i.e., reshuffled series
with comparable linear structure).
Expand Down Expand Up @@ -111,9 +112,14 @@ def fractal_tmf(signal, n=40, show=False, **kwargs):
w[i] = fractal_dfa(surro, multifractal=True, show=False)[0]["Width"]

# Run t-test
t, p = scipy.stats.ttest_1samp(w, w0)
t = t[0]
info["p"] = p[0]
# TODO: adjust in the future
if version.parse(scipy.__version__) < version.parse("1.10.0"):
t, p = scipy.stats.ttest_1samp(w, w0)
t = t[0]
t = t.item()
info["p"] = p[0]
else:
t, info["p"] = scipy.stats.ttest_1samp(w, w0)

if show is True:
pd.Series(w).plot(kind="density", label="Width of surrogates")
Expand Down
2 changes: 1 addition & 1 deletion neurokit2/complexity/utils_complexity_coarsegraining.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def complexity_coarsegraining(signal, scale=2, method="nonoverlapping", show=Fal
signal = nk.signal_simulate(duration=0.5, frequency=[5, 20])
@savefig p_complexity_coarsegraining4.png scale=100%
coarsegrained = nk.complexity_coarsegraining(signal, scale=40, method="timeshift", show=True)
coarsegrained = nk.complexity_coarsegraining(signal, scale=30, method="timeshift", show=True)
@suppress
plt.close()
Expand Down
Loading

0 comments on commit 8c56493

Please sign in to comment.