Skip to content

Commit

Permalink
Merge branch 'dev' into dev-kim-bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattapong-OnePlanet authored Aug 31, 2022
2 parents d4db201 + ce2516d commit 74b5340
Show file tree
Hide file tree
Showing 278 changed files with 59,023 additions and 2,002,553 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scripts/* linguist-vendored
scripts/* linguist-vendored
*.ipynb linguist-language=Python
7 changes: 7 additions & 0 deletions .github/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ Contributing is the best way to learn programming, to meet new people, to grow y

For instance, authors of significant contributions (features, tough bug fixes etc.) will be listed as official `Contributors <https://neuropsychology.github.io/NeuroKit/authors.html>`_ section of our website. Additionally, frequent contributors that also get involved in general maintaining (e.g,participating in issues, fixing stuff, reviewing PRs, writing docs etc.) might be included in as package maintainers, in which case they'll be expected to be more generally involved in the general development direction. Finally, we expect this project (the development of the package *per se* and all of the discussions/experiments that are around it) to result in several **publications** (could be about some features of the package, but also some tutorial papers, validation studies or whatnot. Obviously, people that contributed and allowed for a paper to be written will be included as authors.

.. tip::

On top of this, you can add that you are a contributor of NeuroKit to your CV. Since many labs
and companies use it, they might be particularly interested in recruiting someone that
has a good understanding of NeuroKit, and demonstrated skills in Python and software
development.

Long story short, we want this project to be helpful to you, whether you're a user, a contributor, or anything else in between :) And as always, do not hesitate to ask us if you have any questions.


Expand Down
34 changes: 17 additions & 17 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 180
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 180
# Issues with these labels will never be considered stale
exemptLabels:
- feature idea 🔥
- bug 🐛
# Label to use when marking an issue as stale
staleLabel: inactive 👻
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as inactive because it has not had
recent activity. It will eventually be closed if no further activity occurs.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
This issue has been inactive for a long time. We're closing it (but feel free to reopen it if need be).
# # Number of days of inactivity before an issue becomes stale
# daysUntilStale: 180
# # Number of days of inactivity before a stale issue is closed
# daysUntilClose: 180
# # Issues with these labels will never be considered stale
# exemptLabels:
# - feature idea 🔥
# - bug 🐛
# # Label to use when marking an issue as stale
# staleLabel: inactive 👻
# # Comment to post when marking an issue as stale. Set to `false` to disable
# markComment: >
# This issue has been automatically marked as inactive because it has not had
# recent activity. It will eventually be closed if no further activity occurs.
# # Comment to post when closing a stale issue. Set to `false` to disable
# closeComment: >
# This issue has been inactive for a long time. We're closing it (but feel free to reopen it if need be).
1 change: 1 addition & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- master
- dev
push:

jobs:
Expand Down
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ data/eogdb/eogdb_task2.csv
data/eogdb/eogdb_task3.csv
data/eogdb/eogdb_task4.csv
data/rs_eeg_texas/data/
data/rebel_eeg_restingstate_fr
data/rebel_eeg_restingstate_sg
docs/readme/README_popularity.py
paper/NeuroKit_Submission/
data/fantasia/fantasia-database-1.0.0
Expand All @@ -147,6 +149,9 @@ data/RealObjectsEEG
studies/hrv_structure/efa.csv
studies/hrv_structure/data_stability_1.csv
studies/hrv_structure/data2.csv
data/lemon/lemon/*
data/srm_restingstate_eeg/eeg/
data/testretest_restingstate_eeg/eeg/
data/mit_nst/data2.csv
data/mit_long-term/download_mit_long-term.py
*.atr
Expand Down Expand Up @@ -203,5 +208,7 @@ docs/readme/README_popularity.py
paper/OHBM2022/OHBM2022_Makowski.mp4


studies/complexity_benchmark/README_cache/
studies/complexity_benchmark/manuscript_cache/
studies/complexity_structure/README_cache/
studies/complexity_structure/manuscript_cache/
studies/complexity_eeg/data_attractor.csv
studies/complexity_eeg/data_delay.csv
10 changes: 7 additions & 3 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Authors
.. hint::
Want to be a part of the project? Read how to `contribute and join us <https://neuropsychology.github.io/NeuroKit/resources/contributing.html>`_!

Maintainers
-----------
The full log of contributors is available on `GitHub <https://github.com/neuropsychology/NeuroKit/graphs/contributors>`_.

Current maintainers
-------------------

* `Dominique Makowski <https://github.com/DominiqueMakowski>`_ *(Nanyang Technological University, Singapore)*
* `An Shu Te <https://github.com/anshu-97>`_ *(Nanyang Technological University, Singapore)*
Expand All @@ -21,12 +23,13 @@ Core contributors
* `François Lespinasse <https://github.com/sangfrois>`_ *(Université de Montréal, Canada)*

.. note::
We might sometimes update the authors page categories, order of display, etc., and we won't necessarily notify each contributor every time. However, if you are for any reasons unsatisfied with the list, or your position in it, please do let us know!
We might sometimes update the categories, order of display, etc., and we won't necessarily notify each contributor every time. However, if you are for any reasons unsatisfied with the list, or your position in it, please do let us know!


Contributors
-------------

* `Danielle Benesch <https://github.com/danibene>`_ *(École de technologie supérieure, Canada)*
* `Hung Pham <https://github.com/hungpham2511>`_ *(Eureka Robotics, Singapore)*
* `Christopher Schölzel <https://github.com/CSchoel>`_ *(THM University of Applied Sciences, Germany)*
* `Duy Le <https://github.com/duylp>`_ *(Hubble, Singapore)*
Expand All @@ -46,6 +49,7 @@ Contributors
* `Jacob Epifano <https://github.com/jrepifano>`_ *(Rowan University - Children's Hospital of Philadelphia, USA)*
* `Patryk Wielopolski <https://github.com/pfilo8>`_ *(Wrocław University of Science and Technology, Poland)*
* `Danielle Benesch <https://github.com/danibene>`_ *(École de technologie supérieure, Canada)*
* `Jannik Gut <https://github.com/rostro36>`_
* `Nattapong Thammasan <https://github.com/Nattapong-OnePlanet>`_ *(OnePlanet, Netherlands)*


Expand Down
27 changes: 27 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@ News
=====





0.2.1
-------------------
New Features
+++++++++++++

* Allow for input with NaNs and extrapolation in `signal_interpolate()`
* Add argument `method` in `find_outliers()`





0.2.0
-------------------
New Features
+++++++++++++

* Add new time-domain measures in `hrv_time()`: `Prc20NN`, `Prc80NN`, `MinNN`, and `MaxNN`





0.1.6
-------------------

Expand All @@ -15,6 +41,7 @@ New Features
+++++++++++++

* Add new time-domain measures in `hrv_time()`: `Prc20NN`, `Prc80NN`, `MinNN`, and `MaxNN`
* Allow `fix_peaks()` to account for larger intervals

Fixes
+++++++++++++
Expand Down
95 changes: 95 additions & 0 deletions data/lemon/download_lemon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
"""Script for formatting the LEMON EEG dataset
https://ftp.gwdg.de/pub/misc/MPI-Leipzig_Mind-Brain-Body-LEMON/EEG_MPILMBB_LEMON/EEG_Preprocessed_BIDS_ID/EEG_Preprocessed/
Steps:
1. Download the ZIP database from https://physionet.org/content/nstdb/1.0.0/
2. Open it with a zip-opener (WinZip, 7zip).
3. Extract the folder of the same name (named 'mit-bih-noise-stress-test-database-1.0.0') to the same folder as this script.
4. Run this script.
Credits:
pycrostates package by Mathieu Scheltienne and Victor Férat
"""
import os

import mne
import numpy as np
import pooch

# Path of the database
path = "https://ftp.gwdg.de/pub/misc/MPI-Leipzig_Mind-Brain-Body-LEMON/EEG_MPILMBB_LEMON/EEG_Preprocessed_BIDS_ID/EEG_Preprocessed/"

# Create a registry with the file names
files = {
f"sub-01{i:04d}_{j}.{k}": None
for i in range(2, 319)
for j in ["EC", "EO"]
for k in ["fdt", "set"]
}

# Create fetcher
fetcher = pooch.create(
path="lemon/",
base_url=path,
registry=files,
)

# Download the files
for sub in files.keys():
try:
_ = fetcher.fetch(sub)
except:
pass

print("Finished downloading!")

# Preprocessing

# fmt: off
standard_channels = [
"Fp1", "Fp2", "F7", "F3", "Fz", "F4", "F8", "FC5",
"FC1", "FC2", "FC6", "T7", "C3", "Cz", "C4", "T8",
"CP5", "CP1", "CP2", "CP6", "AFz", "P7", "P3", "Pz",
"P4", "P8", "PO9", "O1", "Oz", "O2", "PO10", "AF7",
"AF3", "AF4", "AF8", "F5", "F1", "F2", "F6", "FT7",
"FC3", "FC4", "FT8", "C5", "C1", "C2", "C6", "TP7",
"CP3", "CPz", "CP4", "TP8", "P5", "P1", "P2", "P6",
"PO7", "PO3", "POz", "PO4", "PO8",
]
# fmt: on

for sub in os.listdir("lemon/"):
if sub.endswith("fdt") is True or sub.endswith("fif") or "sub" not in sub:
continue
raw = mne.io.read_raw_eeglab("lemon/" + sub, preload=True)

missing_channels = list(set(standard_channels) - set(raw.info["ch_names"]))

if len(missing_channels) != 0:
# add the missing channels as bads (array of zeros)
missing_data = np.zeros((len(missing_channels), raw.n_times))
data = np.vstack([raw.get_data(), missing_data])
ch_names = raw.info["ch_names"] + missing_channels
ch_types = raw.get_channel_types() + ["eeg"] * len(missing_channels)
info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq=raw.info["sfreq"])
raw = mne.io.RawArray(data=data, info=info)
raw.info["bads"].extend(missing_channels)

raw = raw.add_reference_channels("FCz")
raw = raw.reorder_channels(standard_channels)
raw = raw.set_montage("standard_1005")
raw = raw.interpolate_bads()
raw = raw.set_eeg_reference("average").apply_proj()

raw.save("lemon/" + sub.replace(".set", "") + "_raw.fif", overwrite=True)


# Clean-up
for sub in os.listdir("lemon/"):
if sub.endswith("fif"):
continue
os.remove(f"lemon/{sub}")

print("FINISHED.")
44 changes: 44 additions & 0 deletions data/srm_restingstate_eeg/download_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
https://openneuro.org/datasets/ds003775/versions/1.0.0
"""
import os
import shutil

import mne
import numpy as np
import openneuro as on

import neurokit2 as nk

# Download cleaned data (takes some time)
on.download(
dataset="ds003775",
target_dir="eeg/raw",
include="sub-*",
exclude="derivatives/cleaned_data",
)

# Convert to MNE
path = "eeg/raw/"
for sub in os.listdir(path):
if "sub" not in sub:
continue
print(f"Participant: {sub}")
file = [f for f in os.listdir(path + sub + "/ses-t1/eeg/") if ".edf" in f][0]
raw = mne.io.read_raw_edf(path + sub + "/ses-t1/eeg/" + file, preload=True, verbose=False)
raw = raw.set_montage("biosemi64")

# Clean
raw = raw.notch_filter(freqs=np.arange(50, 501, 50), verbose=False)
raw.info["bads"], _ = nk.eeg_badchannels(
raw, bad_threshold=0.33, distance_threshold=0.99, show=False
)
print("Bad channels: " + str(len(raw.info['bads'])))
raw = raw.interpolate_bads()

raw.save("eeg/" + sub + "_raw.fif", overwrite=True)

print("FINISHED.")

# Clean-up
shutil.rmtree("eeg/raw/")
61 changes: 61 additions & 0 deletions data/testretest_restingstate_eeg/download_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
https://openneuro.org/datasets/ds003685/
"""
import os
import re
import shutil

import mne
import numpy as np
import openneuro as on

import neurokit2 as nk

# Download cleaned data (takes some time)
on.download(
dataset="ds003685",
target_dir="eeg/raw",
include="sub-*/ses-session1/*eyes*",
)

# Convert to MNE
path = "eeg/raw/"
for sub in os.listdir(path):
if "sub" not in sub or "sub-60" in sub:
continue
print(f"Participant: {sub}")
newpath = path + sub + "/ses-session1/eeg/"

# The header file is broken as the name in it is incorrect
# -------------------------------------------------------------------------
for file in [f for f in os.listdir(newpath) if ".vmrk" in f]:
with open(newpath + file, "r+") as f:
text = f.read() # read everything in the file
pattern = re.search("DataFile=.*\\n", text).group(0)
text = text.replace(pattern, pattern.replace(" ", ""))
with open(newpath + file, "r+") as f:
f.write(text)

for file in [f for f in os.listdir(newpath) if ".vhdr" in f]:

with open(newpath + file, "r+") as f:
text = f.read() # read everything in the file
pattern = re.search("DataFile=.*\\n", text).group(0)
text = text.replace(pattern, pattern.replace(" ", ""))
pattern = re.search("MarkerFile=.*\\n", text).group(0)
text = text.replace(pattern, pattern.replace(" ", ""))
with open(newpath + file, "r+") as f:
f.write(text)
# -------------------------------------------------------------------------

raw = mne.io.read_raw_brainvision(newpath + file, preload=True, verbose=False)
raw = raw.set_eeg_reference("average")
# raw = raw.set_montage("biosemi64")
if "eyesopen" in file:
raw.save("eeg/" + sub + "_eyesopen_raw.fif", overwrite=True)
else:
raw.save("eeg/" + sub + "_eyesclosed_raw.fif", overwrite=True)

print("FINISHED.")
# Clean-up
shutil.rmtree("eeg/raw/")
Loading

0 comments on commit 74b5340

Please sign in to comment.