BioPsyKit
BioPsyKit: A Python package for the analysis of biopsychological data - Published in JOSS (2021)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Keywords from Contributors
Scientific Fields
Repository
A Python package for the analysis of biopsychological data.
Basic Info
Statistics
- Stars: 45
- Watchers: 2
- Forks: 9
- Open Issues: 11
- Releases: 26
Topics
Metadata Files
README.md

BioPsyKit
A Python package for the analysis of biopsychological data.
With this package you have everything you need for analyzing biopsychological data, including: * Data processing pipelines for various physiological signals (ECG, EEG, Respiration, Motion, ...). * Algorithms and data processing pipelines for sleep/wake prediction and computation of sleep endpoints based on activity or IMU data. * Functions to import and process data from sleep trackers (e.g., Withings Sleep Analyzer) * Functions for processing and analysis of salivary biomarker data (cortisol, amylase). * Implementation of various psychological and HCI-related questionnaires. * Implementation of classes representing different psychological protocols (e.g., TSST, MIST, Cortisol Awakening Response Assessment, etc.) * Functions for easily setting up statistical analysis pipelines. * Functions for setting up and evaluating machine learning pipelines. * Plotting wrappers optimized for displaying biopsychological data.
Details
Analysis of Physiological Signals
ECG Processing
BioPsyKit provides a whole ECG data processing pipeline, consisting of:
* Loading ECG data from:
* Generic .csv files
* NilsPod binary (.bin) files (requires NilsPodLib)
* Other sensor types (coming soon)
* Splitting data into single study parts (based on time intervals) that will be analyzed separately
* Performing ECG processing, including:
* R peak detection (using Neurokit)
* R peak outlier removal and interpolation
* HRV feature computation
* ECG-derived respiration (EDR) estimation for respiration rate and respiratory sinus arrhythmia (RSA)
(experimental)
* Instantaneous heart rate resampling
* Computing aggregated results (e.g., mean and standard error) per study part
* Creating plots for visualizing processing results
Quick Example
```python from biopsykit.signals.ecg import EcgProcessor from biopsykit.exampledata import getecg_example
ecgdata, samplingrate = getecgexample()
ep = EcgProcessor(ecgdata, samplingrate) ep.ecg_process()
print(ep.ecg_result) ```
... more biosignals coming soon!
Sleep/Wake Prediction
BioPsyKit allows to process sleep data collected from IMU or activity sensors (e.g., Actigraphs). This includes:
* Detection of wear periods
* Detection of time spent in bed
* Detection of sleep and wake phases
* Computation of sleep endpoints (e.g., sleep and wake onset, net sleep duration wake after sleep onset, etc.)
Quick Example
```python import biopsykit as bp from biopsykit.exampledata import getsleepimuexample
imudata, samplingrate = getsleepimu_example()
sleepresults = bp.sleep.sleepprocessingpipeline.predictpipelineacceleration(imudata, samplingrate) sleependpoints = sleepresults["sleependpoints"]
print(sleep_endpoints) ```
Salivary Biomarker Analysis
BioPsyKit provides several methods for the analysis of salivary biomarkers (e.g. cortisol and amylase), such as:
* Import data from Excel and csv files into a standardized format
* Compute standard features (maximum increase, slope, area-under-the-curve, mean, standard deviation, ...)
Quick Example
```python import biopsykit as bp from biopsykit.exampledata import getsaliva_example
salivadata = getsalivaexample(sampletimes=[-20, 0, 10, 20, 30, 40, 50])
maxinc = bp.saliva.maxincrease(saliva_data)
remove the first saliva sample (t=-20) from computing the AUC
auc = bp.saliva.auc(salivadata, removes0=True)
print(max_inc) print(auc) ```
Questionnaires
BioPsyKit implements various established psychological (state and trait) questionnaires, such as:
* Perceived Stress Scale (PSS)
* Positive and Negative Affect Schedule (PANAS)
* Self-Compassion Scale (SCS)
* Big Five Inventory (BFI)
* State Trait Depression and Anxiety Questionnaire (STADI)
* Trier Inventory for Chronic Stress (TICS)
* Primary Appraisal Secondary Appraisal Scale (PASA)
* ...
Quick Example
```python import biopsykit as bp from biopsykit.exampledata import getquestionnaire_example
data = getquestionnaireexample()
pssdata = data.filter(like="PSS") pssresult = bp.questionnaires.pss(pss_data)
print(pss_result) ```
List Supported Questionnaires
```python import biopsykit as bp
print(bp.questionnaires.utils.getsupportedquestionnaires()) ```
Psychological Protocols
BioPsyKit implements methods for easy handling and analysis of data recorded with several established psychological
protocols, such as:
* Montreal Imaging Stress Task (MIST)
* Trier Social Stress Test (TSST)
* Cortisol Awakening Response Assessment (CAR)
* ...
Quick Example
```python from biopsykit.protocols import TSST from biopsykit.exampledata import getsalivaexample from biopsykit.exampledata import gethrsubjectdatadict_example
specify TSST structure and the durations of the single phases
structure = { "Pre": None, "TSST": { "Preparation": 300, "Talk": 300, "Math": 300 }, "Post": None } tsst = TSST(name="TSST", structure=structure)
salivadata = getsalivaexample(sampletimes=[-20, 0, 10, 20, 30, 40, 50]) hrsubjectdatadict = gethrsubjectdatadictexample()
add saliva data collected during the whole TSST procedure
tsst.addsalivadata(salivadata, salivatype="cortisol")
add heart rate data collected during the "TSST" study part
tsst.addhrdata(hrsubjectdatadict, studypart="TSST")
compute heart rate results: normalize ECG data relative to "Preparation" phase; afterwards, use data from the
"Talk" and "Math" phases and compute the average heart rate for each subject and study phase, respectively
tsst.computehrresults( resultid="hrmean", studypart="TSST", normalizeto=True, selectphases=True, meanpersubject=True, params={ "normalizeto": "Preparation", "select_phases": ["Talk", "Math"] } ) ```
Statistical Analysis
BioPsyKit implements methods for simplified statistical analysis of biopsychological data by offering an
object-oriented interface for setting up statistical analysis pipelines, displaying the results, and adding
statistical significance brackets to plots.
Quick Example
```python import matplotlib.pyplot as plt from biopsykit.stats import StatsPipeline from biopsykit.plotting import multifeatureboxplot from biopsykit.exampledata import getstats_example
data = getstatsexample()
configure statistical analysis pipeline which consists of checking for normal distribution and performing paired
t-tests (within-variable: time) on each questionnaire subscale separately (grouping data by subscale).
pipeline = StatsPipeline( steps=[("prep", "normality"), ("test", "pairwise_ttests")], params={"dv": "PANAS", "groupby": "subscale", "subject": "subject", "within": "time"} )
apply statistics pipeline on data
pipeline.apply(data)
plot data and add statistical significance brackets from statistical analysis pipeline
fig, axs = plt.subplots(ncols=3) features = ["NegativeAffect", "PositiveAffect", "Total"]
generate statistical significance brackets
boxpairs, pvalues = pipeline.sigbrackets( "test", statseffecttype="within", plot_type="single", x="time", features=features, subplots=True )
plot data
multifeatureboxplot( data=data, x="time", y="PANAS", features=features, group="subscale", order=["pre", "post"], statskwargs={"boxpairs": box_pairs, "pvalues": pvalues}, ax=axs ) ```
Machine Learning Analysis
BioPsyKit implements methods for simplified and systematic evaluation of different machine learning pipelines.
Quick Example
```python
Utils
from sklearn.datasets import loadbreastcancer
Preprocessing & Feature Selection
from sklearn.feature_selection import SelectKBest from sklearn.preprocessing import MinMaxScaler, StandardScaler
Classification
from sklearn.neighbors import KNeighborsClassifier from sklearn.tree import DecisionTreeClassifier
Cross-Validation
from sklearn.model_selection import KFold
from biopsykit.classification.model_selection import SklearnPipelinePermuter
load example dataset
breastcancer = loadbreastcancer() X = breastcancer.data y = breast_cancer.target
specify estimator combinations
modeldict = { "scaler": { "StandardScaler": StandardScaler(), "MinMaxScaler": MinMaxScaler() }, "reducedim": { "SelectKBest": SelectKBest(), }, "clf": { "KNeighborsClassifier": KNeighborsClassifier(), "DecisionTreeClassifier": DecisionTreeClassifier(), } }
specify hyperparameter for grid search
paramsdict = { "StandardScaler": None, "MinMaxScaler": None, "SelectKBest": {"k": [2, 4, "all"]}, "KNeighborsClassifier": {"nneighbors": [2, 4], "weights": ["uniform", "distance"]}, "DecisionTreeClassifier": {"criterion": ['gini', 'entropy'], "max_depth": [2, 4]}, }
pipelinepermuter = SklearnPipelinePermuter(modeldict, paramsdict) pipelinepermuter.fit(X, y, outercv=KFold(5), innercv=KFold(5))
print summary of all relevant metrics for the best pipeline for each evaluated pipeline combination
print(pipelinepermuter.metricsummary()) ```
Installation
BioPsyKit requires Python >=3.8. First, install a compatible version of Python. Then install BioPsyKit via pip.
Installation from PyPi:
bash
pip install biopsykit
Installation from PyPi with extras
(e.g., jupyter to directly install all required dependencies for the use with Jupyter Lab):
bash
pip install "biopsykit[jupyter]"
Installation from local repository copy:
bash
git clone https://github.com/mad-lab-fau/BioPsyKit.git
cd BioPsyKit
pip install .
For Developer
If you are a developer and want to contribute to BioPsyKit you can install an editable version of the package from
a local copy of the repository.
BioPsyKit uses poetry to manage dependencies and packaging. Once you installed poetry, run the following commands to clone the repository, initialize a virtual env and install all development dependencies:
Without Extras
bash
git clone https://github.com/mad-lab-fau/BioPsyKit.git
cd BioPsyKit
poetry install
With all Extras (e.g., extended functionalities for IPython/Jupyter Notebooks)
bash
git clone https://github.com/mad-lab-fau/BioPsyKit.git
cd BioPsyKit
poetry install -E mne -E jupyter
To run any of the tools required for the development workflow, use the poe commands of the
poethepoet task runner:
bash
$ poe
docs Build the html docs using Sphinx.
format Reformat all files using black.
format_check Check, but not change, formatting using black.
lint Lint all files with Prospector.
test Run Pytest with coverage.
update_version Bump the version in pyproject.toml and biopsykit.__init__ .
register_ipykernel Register a new IPython kernel named `biopsykit` linked to the virtual environment.
remove_ipykernel Remove the associated IPython kernel.
Some Notes
The
poecommands are only available if you are in the virtual environment associated with this project. You can either activate the virtual environment manually (e.g.,source .venv/bin/activate) or use thepoetry shellcommand to spawn a new shell with the virtual environment activated.In order to use jupyter notebooks with the project you need to register a new IPython kernel associated with the venv of the project (
poe register_ipykernel- see below). When creating a notebook, make to sure to select this kernel (top right corner of the notebook).
* In order to build the documentation, you need to additionally install pandoc.
See the Contributing Guidelines for further information.
Examples
See the Examples Gallery for example on how to use BioPsyKit.
Citing BioPsyKit
If you use BioPsyKit in your work, please report the version you used in the text. Additionally, please also cite the corresponding paper:
Richer et al., (2021). BioPsyKit: A Python package for the analysis of biopsychological data. Journal of Open Source Software, 6(66), 3702, https://doi.org/10.21105/joss.03702
If you use a specific algorithm please also to make sure you cite the original paper of the algorithm! We recommend the following citation style:
We used the algorithm proposed by Author et al. [paper-citation], implemented by the BioPsykit package [biopsykit-citation].
Owner
- Name: Machine Learning and Data Analytics Lab FAU
- Login: mad-lab-fau
- Kind: organization
- Location: Erlangen, Germany
- Website: https://www.mad.tf.fau.de
- Twitter: FAU_MaD_Lab
- Repositories: 17
- Profile: https://github.com/mad-lab-fau
Public projects of the Machine Learning and Data Analytics Lab at the Friedrich-Alexander-University Erlangen-Nürnberg
JOSS Publication
BioPsyKit: A Python package for the analysis of biopsychological data
Authors
Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering (AIBE), Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)
Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering (AIBE), Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)
Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering (AIBE), Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)
Tags
Psychology Biological Psychology Questionnaires Electrocardiogram Saliva Sleep CortisolCitation (CITATION.cff)
cff-version: 1.2.0
abstract: "BioPsyKit is an open source Python package for the analysis of biopsychological data."
authors:
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Richer
given-names: Robert
orcid: "https://orcid.org/0000-0003-0272-5403"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: "Küderle"
given-names: Arne
orcid: "https://orcid.org/0000-0002-5686-281X"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: "Ullrich"
given-names: Martin
orcid: "https://orcid.org/0000-0001-7348-6097"
-
affiliation: "Chair of Health Psychology, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Rohleder
given-names: Nicolas
orcid: "https://orcid.org/0000-0002-0417-0336"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Eskofier
given-names: "Bjoern M."
orcid: "https://orcid.org/0000-0003-2602-517X"
license: MIT
message: "If you use this software, please cite it as below."
repository-code: "https://github.com/mad-lab-fau/BioPsyKit"
title: BioPsyKit
doi: 10.17605/OSF.IO/EBDRT
url: "https://github.com/mad-lab-fau/BioPsyKit"
preferred-citation:
type: article
authors:
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Richer
given-names: Robert
orcid: "https://orcid.org/0000-0003-0272-5403"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: "Küderle"
given-names: Arne
orcid: "https://orcid.org/0000-0002-5686-281X"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: "Ullrich"
given-names: Martin
orcid: "https://orcid.org/0000-0001-7348-6097"
-
affiliation: "Chair of Health Psychology, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Rohleder
given-names: Nicolas
orcid: "https://orcid.org/0000-0002-0417-0336"
-
affiliation: "Machine Learning and Data Analytics Lab (MaD Lab), Department Artificial Intelligence in Biomedical Engineering, Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU)"
family-names: Eskofier
given-names: "Bjoern M."
orcid: "https://orcid.org/0000-0003-2602-517X"
doi: 10.21105/joss.03702
journal: "Journal of Open Source Software"
start: 3702
title: "BioPsyKit: A Python package for the analysis of biopsychological data"
issue: 66
volume: 6
year: 2021
...
GitHub Events
Total
- Create event: 12
- Commit comment event: 2
- Release event: 11
- Issues event: 1
- Watch event: 3
- Delete event: 8
- Issue comment event: 1
- Push event: 47
- Pull request event: 2
Last Year
- Create event: 12
- Commit comment event: 2
- Release event: 11
- Issues event: 1
- Watch event: 3
- Delete event: 8
- Issue comment event: 1
- Push event: 47
- Pull request event: 2
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Robert Richer | r****r@f****e | 1,281 |
| Rebecca Lennartz | r****z@f****e | 50 |
| danielkrauss2 | d****s@f****e | 33 |
| Victoria Müller | v****r@w****e | 27 |
| Martin Ullrich | m****h@f****e | 11 |
| Ali Neishabouri | a****i@t****m | 6 |
| LivH | l****r@g****e | 5 |
| lucaabel | l****l@f****e | 5 |
| Ann-Kristin Seifer | a****r@f****e | 2 |
| Janis Zenkner | j****r@f****e | 2 |
| Ronja Michel | r****l@f****e | 2 |
| Arne Küderle | a****e@g****m | 1 |
| Coverage Badge | c****e | 1 |
| juliajorkowitz | j****z@f****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 28
- Total pull requests: 25
- Average time to close issues: about 2 months
- Average time to close pull requests: 29 days
- Total issue authors: 14
- Total pull request authors: 8
- Average comments per issue: 1.61
- Average comments per pull request: 0.8
- Merged pull requests: 23
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 2
- Average time to close issues: 4 months
- Average time to close pull requests: 2 months
- Issue authors: 1
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.5
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- richrobe (6)
- espenhgn (4)
- zen-juen (3)
- PhD-GOAT (3)
- rouzbeh (2)
- katharina-j-fau (2)
- livhe (1)
- DominiqueMakowski (1)
- victoria1509 (1)
- m-patterson-wearable (1)
- rickinelson (1)
- Aksei (1)
- albas99 (1)
- FilippoCMC (1)
Pull Request Authors
- richrobe (9)
- Rebecca243 (4)
- rouzbeh (4)
- danielkrauss2 (4)
- ullrimar (2)
- livhe (2)
- Aksei (1)
- Ronja151 (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 359 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 28
- Total maintainers: 2
pypi.org: biopsykit
A Python package for the analysis of biopsychological data.
- Homepage: https://github.com/mad-lab-fau/biopsykit
- Documentation: https://biopsykit.readthedocs.io/
- License: mit
-
Latest release: 0.13.1
published 6 months ago
Rankings
Maintainers (2)
Dependencies
- black ^22 develop
- coverage ^4.5.4 develop
- coverage-badge ^1.0.1 develop
- ipykernel ^6.2.0 develop
- isort ^5.9.3 develop
- memory_profiler ^0.57.0 develop
- mypy ^0.790 develop
- nbsphinx ^0.8.7 develop
- numpydoc ^1 develop
- poethepoet ^0.10.0 develop
- prospector ^1.2.0 develop
- pydata-sphinx-theme ^0.6.2 develop
- pytest ^6.2.1 develop
- pytest-cov ^2.8.1 develop
- pytest-xdist ^2.2.0 develop
- recommonmark ^0.6.0 develop
- sphinx ^4.2.0 develop
- sphinx-copybutton ^0.4.0 develop
- sphinx-gallery ^0.10.0 develop
- sphinx_issues ^1.2.0 develop
- toml ^0.10.1 develop
- IPython ^7.13.0
- XlsxWriter ^1.4.5
- fau-colors ^1
- ipympl ^0.8.0
- ipywidgets ^7.6.3
- joblib ^1.1.0
- matplotlib ^3
- mne ^0.23.0
- neurokit2 ^0.1.3
- nilspodlib ^3.2.2
- numpy ^1
- openpyxl ^3.0.7
- pandas ^1
- pingouin ^0.5
- python >=3.8,<3.11
- scikit-learn ^1.0
- scipy ^1.7.0
- seaborn ^0.11.2
- statannot ^0.2.3
- statsmodels ^0.13
- tqdm ^4.62.0
- xlrd ^2.0.1
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- codecov/codecov-action v2 composite
- 160 dependencies