Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -17,14 +17,16 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
make install-deps-apt
python -m pip install --upgrade pip wheel

make install-deps-wxpython
# Install wxPython wheels since they are distribution-specific and therefore not on PyPI
# See: https://wxpython.org/pages/downloads/index.html
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

pip install .
- name: Build docs
run: |
make docs
cd doc && make html
- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/master'
Expand Down
62 changes: 42 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ on:

jobs:
test:
name: test (${{ matrix.os }}, py-${{ matrix.python_version }})
name: ${{ matrix.os }}, py-${{ matrix.python_version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python_version: [3.8]
#include:
python_version: [3.7]
include:
- os: ubuntu-latest
python_version: 3.8
# Experimental: Python 3.9
# Works fine, commented out because mostly covered (at least installing/building deps) by the typecheck job
# See issue: https://github.com/NeuroTechX/eeg-notebooks/issues/50
Expand All @@ -38,22 +40,33 @@ jobs:
- name: Install APT dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
make install-deps-apt
- name: Upgrade pip
run: |
python -m pip install --upgrade pip wheel
# update archive links
sudo apt-get update
# xvfb is a dependency to create a virtual display
# libgtk-3-dev is a requirement for wxPython
# freeglut3-dev is a requirement for a wxPython dependency
sudo apt-get -y install xvfb libgtk-3-dev freeglut3-dev
- name: Install Linux dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
make install-deps-wxpython
- name: Install dependencies
python -m pip install --upgrade pip wheel

# Install wxPython wheels since they are distribution-specific and therefore not on PyPI
# See: https://wxpython.org/pages/downloads/index.html
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

pip install .
- name: Install MacOS/Windows dependencies
run: |
make build
python -m pip install --upgrade pip wheel
pip install .
- name: Run eegnb install test
shell: bash
pip install -U psychtoolbox # JG_ADD
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
Xvfb :0 -screen 0 1024x768x24 -ac +extension GLX +render -noreset &> xvfb.log &
/
export DISPLAY=:0
fi
eegnb --help
Expand All @@ -65,10 +78,9 @@ jobs:
Xvfb :0 -screen 0 1024x768x24 -ac +extension GLX +render -noreset &> xvfb.log &
export DISPLAY=:0
fi
make test
pytest

typecheck:
name: typecheck (${{ matrix.os }}, py-${{ matrix.python_version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -85,17 +97,27 @@ jobs:
- name: Install APT dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
make install-deps-apt
- name: Upgrade pip
run: |
python -m pip install --upgrade pip wheel
# update archive links
sudo apt-get update
# xvfb is a dependency to create a virtual display
# libgtk-3-dev is a requirement for wxPython
# freeglut3-dev is a requirement for a wxPython dependency
sudo apt-get -y install xvfb libgtk-3-dev freeglut3-dev
- name: Install Linux dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
make install-deps-wxpython
- name: Install dependencies
python -m pip install --upgrade pip wheel

# Install wxPython wheels since they are distribution-specific and therefore not on PyPI
# See: https://wxpython.org/pages/downloads/index.html
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

pip install .
- name: Install MacOS/Windows dependencies
run: |
make build
python -m pip install --upgrade pip wheel
pip install .
- name: Typecheck
run: |
make typecheck
# Exclude visual_cueing due to errors
python -m mypy --exclude 'examples/visual_cueing'
32 changes: 0 additions & 32 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def setup(app):
'backreferences_dir': 'generated', # Where to drop linking files between examples & API
'doc_module': ('eeg-notebooks'),
'reference_url': {'eeg-notebooks': None},
'remove_config_comments': True}
'remove_conffig_comments': True}

"""
sphinx_gallery_conf = {
Expand All @@ -284,7 +284,7 @@ def setup(app):
'backreferences_dir': 'generated', # Where to drop linking files between examples & API
'doc_module': ('eeg-notebooks',),
'reference_url': {'eeg-notebooksS': None},
'remove_config_comments': True,
'remove_conffig_comments': True,
}

"""
55 changes: 12 additions & 43 deletions eegnb/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from copy import deepcopy
import math
import logging
import sys
from collections import OrderedDict
from glob import glob
from typing import Union, List
from typing import Union, List, Dict
from time import sleep, time
from numpy.core.fromnumeric import std

import pandas as pd
import numpy as np
Expand All @@ -16,13 +16,13 @@
from mne.channels import make_standard_montage
from mne.filter import create_filter
from matplotlib import pyplot as plt
from scipy import stats
from scipy.signal import lfilter, lfilter_zi

from eegnb import _get_recording_dir
from eegnb.devices.eeg import EEG
from eegnb.devices.utils import EEG_INDICES, SAMPLE_FREQS



# this should probably not be done here
sns.set_context("talk")
Expand All @@ -32,33 +32,6 @@
logger = logging.getLogger(__name__)


def _bootstrap(data, n_boot: int, ci: float):
"""From: https://stackoverflow.com/a/47582329/965332"""
boot_dist = []
for i in range(int(n_boot)):
resampler = np.random.randint(0, data.shape[0], data.shape[0])
sample = data.take(resampler, axis=0)
boot_dist.append(np.mean(sample, axis=0))
b = np.array(boot_dist)
s1 = np.apply_along_axis(stats.scoreatpercentile, 0, b, 50 - ci / 2)
s2 = np.apply_along_axis(stats.scoreatpercentile, 0, b, 50 + ci / 2)
return (s1, s2)


def _tsplotboot(ax, data, time: list, n_boot: int, ci: float, color):
"""From: https://stackoverflow.com/a/47582329/965332"""
# Time forms the xaxis of the plot
if time is None:
x = np.arange(data.shape[1])
else:
x = np.asarray(time)
est = np.mean(data, axis=0)
cis = _bootstrap(data, n_boot, ci)
ax.fill_between(x, cis[0], cis[1], alpha=0.2, color=color)
ax.plot(x, est, color=color)
ax.margins(x=0)


def load_csv_as_raw(
fnames: List[str],
sfreq: float,
Expand Down Expand Up @@ -179,9 +152,7 @@ def load_data(
site = "*"

data_path = (
_get_recording_dir(
device_name, experiment, subject_str, session_str, site, data_dir
)
_get_recording_dir(device_name, experiment, subject_str, session_str, site, data_dir)
/ "*.csv"
)
fnames = glob(str(data_path))
Expand Down Expand Up @@ -222,8 +193,7 @@ def plot_conditions(
ylim=(-6, 6),
diff_waveform=(1, 2),
channel_count=4,
channel_order=None,
):
channel_order=None):
"""Plot ERP conditions.
Args:
epochs (mne.epochs): EEG epochs
Expand All @@ -249,9 +219,10 @@ def plot_conditions(
"""

if channel_order:
channel_order = np.array(channel_order)
channel_order = np.array(channel_order)
else:
channel_order = np.array(range(channel_count))
channel_order = np.array(range(channel_count))


if isinstance(conditions, dict):
conditions = OrderedDict(conditions)
Expand All @@ -261,7 +232,7 @@ def plot_conditions(

X = epochs.get_data() * 1e6

X = X[:, channel_order]
X = X[:,channel_order]

times = epochs.times
y = pd.Series(epochs.events[:, -1])
Expand All @@ -278,15 +249,13 @@ def plot_conditions(

for ch in range(channel_count):
for cond, color in zip(conditions.values(), palette):
y_cond = y.isin(cond)
X_cond = X[y_cond, ch]
_tsplotboot(
ax=axes[ch],
data=X_cond,
sns.tsplot(
X[y.isin(cond), ch],
time=times,
color=color,
n_boot=n_boot,
ci=ci,
ax=axes[ch],
)

if diff_waveform:
Expand Down
Loading