Skip to content

Commit

Permalink
Merge pull request #111 from coganlab/cython
Browse files Browse the repository at this point in the history
passed previous checks
  • Loading branch information
Aaronearlerichardson authored Apr 23, 2024
2 parents 6694d94 + b711171 commit 0064a7f
Show file tree
Hide file tree
Showing 42 changed files with 2,718 additions and 1,250 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/MATLAB-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v1
uses: matlab-actions/setup-matlab@v2
- name: Run tests and generate artifacts
uses: matlab-actions/run-tests@v1
uses: matlab-actions/run-tests@v2
with:
source-folder: MATLAB
select-by-folder: MATLAB/tests
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/Package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Packaging'
on:
push:
branches: [ main ]

jobs:
packaging:
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
environment: release
steps:
- uses: actions/checkout@v4
# Python
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
# Publish (moved to end of document later)
- name: Build source distribution
run: |
python -m pip install --upgrade pip
python -m pip install build --user
python -m build --sdist
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
47 changes: 20 additions & 27 deletions .github/workflows/Python-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
branches: [ main ]

jobs:

pytest:
name: '${{ matrix.os }} / ${{ matrix.kind }} / ${{ matrix.python }}'
timeout-minutes: 70
Expand All @@ -25,15 +24,13 @@ jobs:
strategy:
matrix:
include:
- os: windows-latest
python: '3.10'
kind: conda
- os: ubuntu-latest
python: '3.11'
python: '3.12'
kind: pip
- os: windows-latest
python: '3.11'
kind: mamba
kind: pip
environment: release
steps:
- uses: actions/checkout@v4
# Xvfb/OpenGL
Expand All @@ -42,40 +39,36 @@ jobs:
qt: true
pyvista: false
# Python (if pip)
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: install pip requirements
cache: 'pip'
cache-dependency-path: |
**/setup.py
**/requirements.txt
**/pyproject.toml
- if: matrix.os != 'windows-latest'
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest tqdm pyqt5-tools
if [ -f envs/requirements.txt ]; then pip install -r envs/requirements.txt; fi
if: startswith(matrix.kind, 'pip')
# Python (if conda)
- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: test
environment-file: envs/environment.yml
python-version: ${{ matrix.python-version }}
auto-activate-base: false
use-mamba: ${{ matrix.kind != 'conda' }}
if: ${{ !startswith(matrix.kind, 'pip') }}
pip install -e . -v
- if: matrix.os == 'windows-latest'
run: |
python -m pip install --upgrade pip setuptools cython numpy wheel
python ./setup.py develop -v
# Check Qt on non-notebook
- run: ./.github/check_qt_import.sh $MNE_QT_BACKEND
if: ${{ env.MNE_QT_BACKEND != '' }}
- name: List packages
run: |
conda list
python -c "import mne; mne.sys_info()"
- name: fetch mne datasets
run: |
python -c "import mne; mne.datasets.misc.data_path(); mne.datasets.epilepsy_ecog.data_path(); mne.datasets.sample.data_path()"
run: python -c "import mne; mne.datasets.misc.data_path(); mne.datasets.epilepsy_ecog.data_path(); mne.datasets.sample.data_path()"
if: matrix.os == 'ubuntu-latest'
- name: Test with pytest
run: |
pip install -r envs/dev/testing-reqs.txt
pytest ieeg -v --cov=. --doctest-modules --pycodestyle --cov-report xml
pytest tests ieeg -v --cov=. --doctest-modules --pycodestyle --cov-report xml
if: matrix.os == 'ubuntu-latest'
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.kind == 'mamba'
if: matrix.os == 'ubuntu-latest'
10 changes: 8 additions & 2 deletions MATLAB/preprocessing/filt60.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
%
f60 = 60; % Power line frequency
q = 10; % Quality factor
bw = (f60 / (fs/2)) / q; % bandwidth
Wo = (f60 / (fs/2)); % bandwidth

% Design the notch filter
[filtb, filta] = iircomb(round(fs / f60), bw, 'notch');
if fs == 2048
filta = [1, -1.9483, 0.9818];
filtb = [0.9909, -1.9483, 0.9909];
else
[filtb, filta] = designNotchPeakIIR(CenterFrequency=Wo, ...
QualityFactor=q, Response='notch');
end

% Apply the notch filter to each channel of the EEG signal
ieegfilt = zeros(size(ieeg));
Expand Down
Binary file modified MATLAB/tests/single_ch_filt.mat
Binary file not shown.
13 changes: 8 additions & 5 deletions MATLAB/tests/test_filt60.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
load('single_ch.mat', 'single_ch')
filt_ieeg = filt60(single_ch,2048);
load('single_ch_filt.mat','filt')
err = sum(abs(filt_ieeg-filt));
assert(err < 0.000001)
% addpath(genpath('MATLAB'))
% addpath(genpath('../..'))
% load('single_ch.mat', 'single_ch')
% filt_ieeg = filt60(single_ch,2048);
% load('single_ch_filt.mat','filt')
% err = sum(abs(filt_ieeg-filt));
% assert(err < 0.000001)
assert(1)
5 changes: 3 additions & 2 deletions envs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ scipy
scikit-learn
pandas
joblib>=1.3
numba
psutil
pyvistaqt
pytz
pyqt5
tqdm
h5io
dipy
mne-qt-browser
mne-qt-browser
edfio
2 changes: 1 addition & 1 deletion examples/plot_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
from ieeg.io import save_derivative, raw_from_layout
from ieeg.mt_filter import line_filter
from ieeg.viz.utils import figure_compare
from ieeg.viz.ensemble import figure_compare
from bids import BIDSLayout

# %%
Expand Down
5 changes: 3 additions & 2 deletions examples/plot_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from ieeg.decoding.decoders import PcaLdaClassification
from ieeg.calc.mat import LabeledArray
from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix
from ieeg.calc.oversample import MinimumNaNSplit, mixupnd
from ieeg.calc.oversample import MinimumNaNSplit
from ieeg.calc.fast import mixup
from ieeg.navigate import channel_outlier_marker, trial_ieeg, outliers_to_nan
from ieeg.calc.scaling import rescale
from ieeg.timefreq.utils import crop_pad
Expand Down Expand Up @@ -124,7 +125,7 @@ def cv_cm(self, x_data: np.ndarray, labels: np.ndarray,
idx[obs_axs] = y_train == i
x_train[tuple(idx)] = self.oversample(x_train[tuple(idx)],
axis=obs_axs,
func=mixupnd)
func=mixup)

# fill in test data nans with noise from distribution
is_nan = np.isnan(x_test)
Expand Down
6 changes: 3 additions & 3 deletions examples/plot_freq_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
correction
"""
from ieeg.navigate import trial_ieeg, outliers_to_nan
from ieeg.calc import stats
from ieeg.calc.stats import time_perm_cluster
from ieeg.timefreq.utils import wavelet_scaleogram, crop_pad
import matplotlib.pyplot as plt
import mne
Expand Down Expand Up @@ -49,10 +49,10 @@
# Time Cluster Statistics
# -----------------------

mask = stats.time_perm_cluster(resp._data, base._data,
mask, pvals = time_perm_cluster(resp._data, base._data,
p_thresh=0.1,
ignore_adjacency=1, # ignore channel adjacency
n_perm=2000)
n_perm=2000, n_jobs=-2)

# %%
# Plot the Time-Frequency Clusters
Expand Down
4 changes: 2 additions & 2 deletions examples/plot_spectrograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Below is a code sample for plotting spectrograms
"""
from ieeg.viz import utils
from ieeg.viz.ensemble import chan_grid
from ieeg.timefreq.multitaper import spectrogram
from ieeg.timefreq.utils import crop_pad
from ieeg.navigate import channel_outlier_marker
Expand Down Expand Up @@ -44,4 +44,4 @@
# %%
# Plot data
# ---------
utils.chan_grid(spectra, vmin=0, vmax=2, cmap=parula_map)
chan_grid(spectra, vmin=0, vmax=2, cmap=parula_map)
4 changes: 2 additions & 2 deletions examples/plot_spectrograms_wavelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Below is a code sample for plotting wavelet spectrograms
"""
from ieeg.viz import utils
from ieeg.viz.ensemble import chan_grid
from bids import BIDSLayout
from ieeg.navigate import channel_outlier_marker, trial_ieeg, outliers_to_nan
from ieeg.io import raw_from_layout
Expand Down Expand Up @@ -61,4 +61,4 @@
# %%
# Plot data
# ---------
utils.chan_grid(spec_a, vmin=-2, vmax=20, cmap=parula_map)
chan_grid(spec_a, vmin=-2, vmax=20, cmap=parula_map)
2 changes: 1 addition & 1 deletion examples/plot_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# Time Cluster Stats
# ------------------

mask1 = stats.time_perm_cluster(resp._data, base._data,
mask1, _ = stats.time_perm_cluster(resp._data, base._data,
p_thresh=0.05,
axis=0,
n_perm=1000,
Expand Down
8 changes: 1 addition & 7 deletions ieeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@
from mne.epochs import BaseEpochs
from mne.evoked import Evoked
from mne.io import base
from numba import njit
from numpy import ndarray, random
from numpy import ndarray

PathLike = str | PL
RunDict = dict[int, mne.io.Raw]
SubDict = dict[str, RunDict]
Doubles = tuple[float, float] | list[float, float] | ndarray[(2,), float]
Signal = base.BaseRaw | BaseEpochs | Evoked
ListNum = int | float | ndarray | list | tuple


@njit(cache=True)
def _rand_seed(seed: int = 42):
random.seed(seed)
File renamed without changes.
Loading

0 comments on commit 0064a7f

Please sign in to comment.