Skip to content

Commit

Permalink
Revert "Revert PR NeuroTechX#167: "ci: fix broken CI" (NeuroTechX#169)"
Browse files Browse the repository at this point in the history
This reverts commit 2d74871.
  • Loading branch information
ErikBjare committed Mar 27, 2022
1 parent 2d74871 commit dddba0e
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 391 deletions.
10 changes: 4 additions & 6 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-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -17,16 +17,14 @@ jobs:
python-version: 3.8
- name: Install dependencies
run: |
make install-deps-apt
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
make install-deps-wxpython
pip install .
- name: Build docs
run: |
cd doc && make html
make docs
- name: Deploy Docs
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/master'
Expand Down
62 changes: 20 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ on:

jobs:
test:
name: ${{ matrix.os }}, py-${{ matrix.python_version }}
name: test (${{ 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.7]
include:
- os: ubuntu-latest
python_version: 3.8
python_version: [3.8]
#include:
# 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 @@ -40,33 +38,22 @@ jobs:
- name: Install APT dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
# 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
make install-deps-apt
- name: Upgrade pip
run: |
python -m pip install --upgrade pip wheel
- name: Install Linux dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
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
make install-deps-wxpython
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install .
make build
- 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 @@ -78,9 +65,10 @@ jobs:
Xvfb :0 -screen 0 1024x768x24 -ac +extension GLX +render -noreset &> xvfb.log &
export DISPLAY=:0
fi
pytest
make test
typecheck:
name: typecheck (${{ matrix.os }}, py-${{ matrix.python_version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -97,27 +85,17 @@ jobs:
- name: Install APT dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
# 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
make install-deps-apt
- name: Upgrade pip
run: |
python -m pip install --upgrade pip wheel
- name: Install Linux dependencies
if: "startsWith(runner.os, 'Linux')"
run: |
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
make install-deps-wxpython
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install .
make build
- name: Typecheck
run: |
# Exclude visual_cueing due to errors
python -m mypy --exclude 'examples/visual_cueing'
make typecheck
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
build:
pip install .

test:
pytest

typecheck:
# Exclude visual_cueing due to errors
python -m mypy --exclude 'examples/visual_cueing'

docs:
cd doc && make html

clean:
cd doc && make clean

install-deps-apt:
sudo apt-get update # update archive links

# 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
# portaudio19-dev *might* be required to import psychopy on Ubuntu
# pulseaudio *might* be required to actually run the tests (on PsychoPy import)
# libpulse-dev required to build pocketsphinx (speech recognition dependency of psychopy)
# libsdl2-dev required by psychopy
sudo apt-get -y install xvfb libgtk-3-dev freeglut3-dev portaudio19-dev libpulse-dev pulseaudio libsdl2-dev

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
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_conffig_comments': True}
'remove_config_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_conffig_comments': True,
'remove_config_comments': True,
}
"""
55 changes: 43 additions & 12 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, Dict
from typing import Union, List
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,6 +32,33 @@
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 @@ -152,7 +179,9 @@ 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 @@ -193,7 +222,8 @@ 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 @@ -219,10 +249,9 @@ 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 @@ -232,7 +261,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 @@ -249,13 +278,15 @@ def plot_conditions(

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

if diff_waveform:
Expand Down
Loading

0 comments on commit dddba0e

Please sign in to comment.