Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix broken CI #167

Merged
merged 20 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9f8f0c6
ci: fix broken CI
ErikBjare Mar 25, 2022
405dfb2
build(deps): removed version locks for doc deps
ErikBjare Mar 25, 2022
9d8b0a8
build(deps): added pygame, to resolve PsychoPy 'no audio device' erro…
ErikBjare Mar 25, 2022
af4323d
docs: fixed docs config
ErikBjare Mar 25, 2022
00be982
ci: added installation of libportaudio2 on Ubuntu
ErikBjare Mar 25, 2022
fc49c84
ci: added experimental macOS + py-3.9 run
ErikBjare Mar 25, 2022
81105c3
ci: removed unnecessary explicit install of psychtoolbox
ErikBjare Mar 25, 2022
d0a793b
build(deps): updated psychopy to 2022.1.1 (to fix issues in CI)
ErikBjare Mar 25, 2022
19be96f
ci: improved CI config, added libpulse-dev
ErikBjare Mar 25, 2022
2e0f55e
ci: bumped Python to 3.8, added libsdl2-dev
ErikBjare Mar 25, 2022
d678aed
build(deps): loosened requirements for seaborn, removed unneeded requ…
ErikBjare Mar 25, 2022
a5c9389
ci: set job names
ErikBjare Mar 25, 2022
0c32c9e
ci: more fixes
ErikBjare Mar 25, 2022
89e80e4
ci: fix install of deps for typechecking job
ErikBjare Mar 25, 2022
f67bde6
fix: fixed seaborn compatibility
ErikBjare Mar 25, 2022
ea3d3e4
build: refactored common build/testing/CI commands into Makefile
ErikBjare Mar 25, 2022
bfad134
fix: fixed notebook loading data with incorrect device_name
ErikBjare Mar 25, 2022
1182473
fix: fixed incorrect indentation in Makefile
ErikBjare Mar 25, 2022
1398794
fix: fixed plot_conditions
ErikBjare Mar 25, 2022
430bafb
fix: throw exception for unhandled case
ErikBjare Mar 25, 2022
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: 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: 22 additions & 40 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ 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]
python_version: [3.8]
include:
- os: ubuntu-latest
python_version: 3.8
python_version: 3.9
#- os: macOS-latest
# python_version: 3.9
# Experimental: Python 3.9
# See issue: https://github.com/NeuroTechX/eeg-notebooks/issues/50
#- os: ubuntu-18.04
Expand All @@ -39,33 +41,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 @@ -77,9 +68,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 @@ -96,27 +88,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