Skip to main content

The Python Toolbox for Neurophysiological Signal Processing.

Project description

https://raw.github.com/neuropsychology/NeuroKit/master/docs/img/banner.png https://img.shields.io/pypi/pyversions/neurokit2.svg?logo=python&logoColor=FFE873 https://img.shields.io/pypi/dm/neurokit2 https://img.shields.io/pypi/v/neurokit2.svg?logo=pypi&logoColor=FFE873 https://img.shields.io/travis/neuropsychology/neurokit/master?label=Travis%20CI&logo=travis https://codecov.io/gh/neuropsychology/NeuroKit/branch/master/graph/badge.svg Maintainability

The Python Toolbox for Neurophysiological Signal Processing

This package is the continuation of NeuroKit 1. It’s a user-friendly package providing easy access to advanced biosignal processing routines. Researchers and clinicians without extensive knowledge of programming or biomedical signal processing can analyze physiological data with only two lines of code.

Quick Example

import neurokit2 as nk

# Download example data
data = nk.data("bio_eventrelated_100hz")

# Preprocess the data (filter, find peaks, etc.)
processed_data, info = nk.bio_process(ecg=data["ECG"], rsp=data["RSP"], eda=data["EDA"], sampling_rate=100)

# Compute relevant features
results = nk.bio_analyze(processed_data, sampling_rate=100)

And boom 💥 your analysis is done 😎

Installation

To install NeuroKit2, run this command in your terminal:

pip install https://github.com/neuropsychology/neurokit/zipball/master

If you’re not sure how/what to do, be sure to read our installation guide.

Contribution

License GitHub CI Style

NeuroKit2 is a collaborative project with a community of contributors with all levels of development expertise. Thus, if you have some ideas for improvement, new features, or just want to learn Python and do something useful at the same time, do not hesitate and check out the CONTRIBUTION guide. Once this is done, you can also read our ideas for first contributions

Documentation

Documentation Status API Tutorials PDF Binder Chat on Gitter

Click on the links above and check out our tutorials:

Guides

Examples

You can try out these examples directly in your browser.

Don’t know which tutorial is suited for your case? Follow this flowchart:

https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/workflow.png

Citation

https://zenodo.org/badge/218212111.svg https://img.shields.io/badge/details-authors-purple.svg?colorB=9C27B0
nk.cite()
You can cite NeuroKit2 as follows:

- Makowski, D., Pham, T., Lau, Z. J., Brammer, J. C., Lesspinasse, F., Pham, H.,
  Schölzel, C., & S H Chen, A. (2020). NeuroKit2: A Python Toolbox for Neurophysiological
  Signal Processing. Retrieved March 28, 2020, from https://github.com/neuropsychology/NeuroKit

Full bibtex reference:

@misc{neurokit2,
  doi = {10.5281/ZENODO.3597887},
  url = {https://github.com/neuropsychology/NeuroKit},
  author = {Makowski, Dominique and Pham, Tam and Lau, Zen J. and Brammer, Jan C. and Lespinasse, Fran\c{c}ois and Pham, Hung and Schölzel, Christopher and S H Chen, Annabel},
  title = {NeuroKit2: A Python Toolbox for Neurophysiological Signal Processing},
  publisher = {Zenodo},
  year = {2020},
}

Physiological Data Preprocessing

Simulate physiological signals

import numpy as np
import pandas as pd
import neurokit2 as nk

# Generate synthetic signals
ecg = nk.ecg_simulate(duration=10, heart_rate=70)
ppg = nk.ppg_simulate(duration=10, heart_rate=70)
rsp = nk.rsp_simulate(duration=10, respiratory_rate=15)
eda = nk.eda_simulate(duration=10, scr_number=3)
emg = nk.emg_simulate(duration=10, burst_number=2)

# Visualise biosignals
data = pd.DataFrame({"ECG": ecg,
                     "PPG": ppg,
                     "RSP": rsp,
                     "EDA": eda,
                     "EMG": emg})
nk.signal_plot(data, subplots=True)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_simulation.png

Electrodermal Activity (EDA/GSR)

# Generate 10 seconds of EDA signal (recorded at 250 samples / second) with 2 SCR peaks
eda = nk.eda_simulate(duration=10, sampling_rate=250, scr_number=2, drift=0.01)

# Process it
signals, info = nk.eda_process(eda, sampling_rate=250)

# Visualise the processing
nk.eda_plot(signals, sampling_rate=250)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_eda.png

Cardiac activity (ECG)

# Generate 15 seconds of ECG signal (recorded at 250 samples / second)
ecg = nk.ecg_simulate(duration=15, sampling_rate=250, heart_rate=70)

# Process it
signals, info = nk.ecg_process(ecg, sampling_rate=250)

# Visualise the processing
nk.ecg_plot(signals, sampling_rate=250)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_ecg.png

Respiration (RSP)

# Generate one minute of respiratory (RSP) signal (recorded at 250 samples / second)
rsp = nk.rsp_simulate(duration=60, sampling_rate=250, respiratory_rate=15)

# Process it
signals, info = nk.rsp_process(rsp, sampling_rate=250)

# Visualise the processing
nk.rsp_plot(signals, sampling_rate=250)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_rsp.png

Electromyography (EMG)

# Generate 10 seconds of EMG signal (recorded at 250 samples / second)
emg = nk.emg_simulate(duration=10, sampling_rate=250, burst_number=3)

# Process it
signal, info = nk.emg_process(emg, sampling_rate=250)

# Visualise the processing
nk.emg_plot(signals, sampling_rate=250)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_emg.png

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)

Electrogastrography (EGG)

Consider helping us develop it!

Electrooculography (EOG)

Consider helping us develop it!

Physiological Data Analysis

The analysis of physiological data usually comes in two types, event-related or interval-related.

https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/features.png

Miscellaneous

Heart Rate Variability (HRV)

  • Compute HRV indices

    • Time domain: RMSSD, MeanNN, SDNN, SDSD, CVNN etc.

    • Frequency domain: Spectral power density in various frequency bands (Ultra low/ULF, Very low/VLF, Low/LF, High/HF, Very high/VHF), Ratio of LF to HF power, Normalized LF (LFn) and HF (HFn), Log transformed HF (LnHF).

    • Nonlinear domain: Spread of RR intervals (SD1, SD2, ratio between SD2 to SD1), Cardiac Sympathetic Index (CSI), Cardial Vagal Index (CVI), Modified CSI, Sample Entropy (SampEn).

# Download data
data = nk.data("bio_resting_8min_100hz")

# Find peaks
peaks, info = nk.ecg_peaks(data["ECG"], sampling_rate=100)

# Compute HRV indices
nk.hrv(peaks, sampling_rate=100, show=True)
>>>    HRV_RMSSD  HRV_MeanNN   HRV_SDNN  ...   HRV_CVI  HRV_CSI_Modified  HRV_SampEn
>>> 0  69.697983  696.395349  62.135891  ...  4.829101        592.095372    1.259931
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_hrv.png

Signal Processing

  • Signal processing functionalities

    • Filtering: Using different methods.

    • Detrending: Remove the baseline drift or trend.

    • Distorting: Add noise and artifacts.

# Generate original signal
original = nk.signal_simulate(duration=6, frequency=1)

# Distort the signal (add noise, linear trend, artifacts etc.)
distorted = nk.signal_distort(original,
                              noise_amplitude=0.1,
                              noise_frequency=[5, 10, 20],
                              powerline_amplitude=0.05,
                              artifacts_amplitude=0.3,
                              artifacts_number=3,
                              linear_drift=0.5)

# Clean (filter and detrend)
cleaned = nk.signal_detrend(distorted)
cleaned = nk.signal_filter(cleaned, lowcut=0.5, highcut=1.5)

# Compare the 3 signals
plot = nk.signal_plot([original, distorted, cleaned])
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_signalprocessing.png

Complexity (Entropy, Fractal Dimensions, …)

  • Optimize complexity parameters (delay tau, dimension m, tolerance r)

# Generate signal
signal = nk.signal_simulate(frequency=[1, 3], noise=0.01, sampling_rate=100)

# Find optimal time delay, embedding dimension and r
parameters = nk.complexity_optimize(signal, show=True)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_complexity_optimize.png
  • Compute complexity features

    • Entropy: Sample Entropy (SampEn), Approximate Entropy (ApEn), Fuzzy Entropy (FuzzEn), Multiscale Entropy (MSE), Shannon Entropy (ShEn)

    • Fractal dimensions: Correlation Dimension D2, …

    • Detrended Fluctuation Analysis

nk.entropy_sample(signal)
nk.entropy_approximate(signal)

Statistics

  • Highest Density Interval

x = np.random.normal(loc=0, scale=1, size=100000)

ci_min, ci_max = nk.hdi(x, ci=0.95, show=True)
https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_hdi.png

Popularity

https://img.shields.io/pypi/dd/neurokit2 https://img.shields.io/github/stars/neuropsychology/NeuroKit https://img.shields.io/github/forks/neuropsychology/NeuroKit https://raw.github.com/neuropsychology/NeuroKit/master/docs/readme/README_popularity.png

Notes

The authors do not provide any warranty. If this software causes your keyboard to blow up, your brain to liquify, your toilet to clog or a zombie plague to break loose, the authors CANNOT IN ANY WAY be held responsible.

News

0.0.1 (2019-10-29)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neurokit2-0.0.34.tar.gz (15.2 MB view details)

Uploaded Source

Built Distribution

neurokit2-0.0.34-py2.py3-none-any.whl (881.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file neurokit2-0.0.34.tar.gz.

File metadata

  • Download URL: neurokit2-0.0.34.tar.gz
  • Upload date:
  • Size: 15.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for neurokit2-0.0.34.tar.gz
Algorithm Hash digest
SHA256 76793e67aee478ac3ac8d37002c92f2b3a4a48e93f449a8a4e5827e3a9151121
MD5 58c202313abe37eed59d7da9f75f91fc
BLAKE2b-256 a5baa27c8ee37946c5f637804de4100b229743537d52285fc82f5721dbf64a87

See more details on using hashes here.

File details

Details for the file neurokit2-0.0.34-py2.py3-none-any.whl.

File metadata

  • Download URL: neurokit2-0.0.34-py2.py3-none-any.whl
  • Upload date:
  • Size: 881.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for neurokit2-0.0.34-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d8088dc1487c516cbc05c2088825b671f80da321fcac5f331132c8fb181bdd24
MD5 3cbf885a66abd0bfdcbcd0bb95d82f0f
BLAKE2b-256 73144ca7bf083c6ebac86c857759f94476aa548376153943e6378e13fd9c34b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page