Skip to content

Commit

Permalink
Merge pull request #119 from coganlab/pytest-mri
Browse files Browse the repository at this point in the history
Change test_mri to pytest style.
  • Loading branch information
rayarxti authored May 21, 2024
2 parents 50377f9 + 72b6377 commit 9793335
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 30 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/Package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ jobs:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs:
- build
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- 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

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
Expand All @@ -68,4 +50,22 @@ jobs:
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
needs:
- publish-to-testpypi
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- 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
6 changes: 4 additions & 2 deletions ieeg/viz/mri.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,9 @@ def _group_channels(info, groups: dict = None) -> dict:


def _add_labels(fig, info, sub, every, hemi, lr, **kwargs):
if len(info.ch_names) < every:
return
names = info.ch_names[slice(every - 1, None, every)]

if not hemi == 'both':
for hems, pos in enumerate(lr):
if (not pos) or \
Expand All @@ -646,7 +647,8 @@ def _add_labels(fig, info, sub, every, hemi, lr, **kwargs):
plt_names = filter(lambda x: x.startswith(['L', 'R'][hems]), names)
plt_names = [f'{sub}-{n}' for n in plt_names]
positions = np.array([pos[n.split("-")[1]] for n in plt_names])
fig.plotter.subplot(0, hems)
if hemi == 'split':
fig.plotter.subplot(0, hems)
fig.plotter.add_point_labels(positions, plt_names, **kwargs)
else:
pos = {}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_file_list(path, ext):

setup(
name='ieeg',
version='0.5',
version='0.5.1',
packages=find_packages(
where='.',
include=['ieeg*'],
Expand Down
54 changes: 46 additions & 8 deletions tests/test_mri.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

import mne
import vtk
import pytest
from ieeg.viz.mri import plot_subj, plot_on_average

misc_path = mne.datasets.misc.data_path()
sample_path = mne.datasets.sample.data_path()
Expand All @@ -11,18 +12,55 @@
if not os.path.exists(os.path.join(subjects_dir, "1")):
os.symlink(os.path.join(subjects_dir, 'sample'),
os.path.join(subjects_dir, '1'))

raw = mne.io.read_raw(misc_path / "seeg" / "sample_seeg_ieeg.fif")


def test_plot_seeg():
from ieeg.viz.mri import plot_subj
plot_subj(raw, subj_dir=subjects_dir, show=False)
@pytest.mark.parametrize(
'args, expected', [
({}, None),
({'labels_every': 1}, None),
({'hemi': 'split'}, None),
({'hemi': 'lh'}, None),
({'size': 0.2}, None),
({'background': 'red'}, None),
({'transparency': 0.2}, None),
({'color': (1, 0, 0)}, None),
({'picks': ['LSTG 1', 'LSTG 2', 'LSTG 3', 'LSTG 4', 'RAHP 1',
'RAHP 2', 'RAHP 3', 'RAHP 4', 'RAHP 5', 'RAHP 6']}, None),
({'picks': ['LSTG 1', 'LSTG 2', 'LSTG 3'], 'hemi': 'rh'}, None),
({'picks': [0, 1, 2, 3, 4, 5, 6, 7, 8]}, None),
({'picks': [0, 1, 2, 3, 4]}, None),
({'hemi': 'rh'}, None),
# Fails bc no wm parcellation file
# ({'no_wm': True}, None),
]
)
def test_plot_seeg_inst(args, expected):
plot_subj(inst=raw, subj_dir=subjects_dir, show=False, **args)


def test_plot_avg():
from ieeg.viz.mri import plot_on_average
plot_on_average(raw, subj_dir=subjects_dir, show=False, rm_wm=False,
hemi='both')
@pytest.mark.parametrize(
'args, expected', [
({}, None),
({'label_every': 1}, None),
({'hemi': 'both'}, None),
({'hemi': 'split'}, None),
({'hemi': 'lh'}, None),
({'size': 0.2}, None),
({'background': 'red'}, None),
({'transparency': 0.2}, None),
({'color': (1, 0, 0)}, None),
({'picks': ['LSTG 1', 'LSTG 2', 'LSTG 3', 'LSTG 4', 'RAHP 1',
'RAHP 2', 'RAHP 3', 'RAHP 4', 'RAHP 5', 'RAHP 6']}, None),
({'picks': ['LSTG 1', 'LSTG 2', 'LSTG 3'], 'hemi': 'rh'}, None),
({'picks': [0, 1, 2, 3, 4, 5, 6, 7, 8]}, None),
({'picks': [0, 1, 2, 3, 4]}, None),
({'hemi': 'rh'}, None),
]
)
def test_plot_avg(args, expected):
plot_on_average(sigs=raw, subj_dir=subjects_dir, show=False, **args)


# if on windows, finalize closing the vtk window
Expand Down

0 comments on commit 9793335

Please sign in to comment.