Skip to content

Commit

Permalink
Merge pull request #38 from cibr-jyu/update-mne
Browse files Browse the repository at this point in the history
Update mne and docs
  • Loading branch information
teekuningas authored Mar 13, 2024
2 parents ad62422 + 1b7965d commit 2d34019
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 138 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test:
update_docs:
rm -fr docs_updated
cp -fr docs docs_updated
python update_docs.py docs_updated
python scripts/update_docs.py docs_updated

.PHONY: serve_docs
serve_docs: update_docs
Expand Down
32 changes: 32 additions & 0 deletions docs/user-guide/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Plugins

Meggie's capabilities can be extended through the use of plugins. These plugins are developed by the community and allow you to customize and enhance your experience with new features.

## Why Use Plugins?

Plugins let you tailor Meggie to your specific research needs. They can provide new analysis options, data handling capabilities, or help optimize your existing workflows.

## Finding Plugins

Below is a list of available meggie plugins found on PyPi.

{{PLUGIN_INFO}}

## Installing Plugins

To install a plugin, first activate the Python environment in which Meggie is installed. Then, you can simply use pip to install the plugin of your choice:

```bash
$ pip install <plugin_name>
```

For example, if you wanted to install the "meggie_example" plugin, you would run:

```bash
$ pip install meggie_example
```

## Need Help?

If you have questions about selecting or installing plugins, the Meggie community is ready to help. We're all part of making Meggie a versatile and user-friendly tool for everyone.

21 changes: 10 additions & 11 deletions meggie/actions/raw_ica/controller/ica.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ def plot_topographies(ica, n_components):
"""Plots topographies from the ICA solution."""

figs = ica.plot_components(title="")
if not isinstance(figs, list):
figs = [figs]

for fig in figs:
set_figure_title(fig, "ICA topographic maps")

def update_topography_texts():
"""Change texts in the axes to match names in the dialog"""
idx = 0
for fig in figs:
for ax in fig.get_axes():
if idx > n_components:
return

ax.set_title("Component " + str(idx), fontsize=12)
idx += 1
idx = 0
for fig in figs:
for ax in fig.get_axes():
if idx > n_components:
return

update_topography_texts()
ax.set_title("Component " + str(idx), fontsize=12)
idx += 1


def plot_sources(raw, ica):
Expand Down
4 changes: 2 additions & 2 deletions meggie/datatypes/spectrum/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _load_content(self):
def _get_info(self):
"""Gets info from file system."""
info_path = os.path.join(self._directory, self._name + "-info.fif")
info = mne.io.meas_info.read_info(info_path)
info = mne.io.read_info(info_path)

return info

Expand Down Expand Up @@ -115,7 +115,7 @@ def save_content(self):
try:
# save info
info_path = os.path.join(self._directory, self._name + "-info.fif")
mne.io.meas_info.write_info(info_path, self._info)
mne.io.write_info(info_path, self._info)
self._params["info_set"] = True

# save data
Expand Down
16 changes: 7 additions & 9 deletions meggie/mainwindow/dialogs/addSubjectDialogMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import logging

import mne

from PyQt5 import QtWidgets
from PyQt5 import QtCore

Expand All @@ -15,6 +13,7 @@
from meggie.utilities.messaging import messagebox
from meggie.utilities.threading import threaded
from meggie.utilities.names import next_available_name
from meggie.utilities.filemanager import get_supported_formats


class AddSubjectDialog(QtWidgets.QDialog):
Expand Down Expand Up @@ -78,15 +77,14 @@ def on_pushButtonBrowse_clicked(self, checked=None):
if checked is None:
return

mne_supported = mne.io._read_raw.supported
mne_supported = get_supported_formats()

all_ext = [val[0] for val in mne_supported]

all_ext = []
all_items = []
for row in mne_supported.items():
ext = row[0]
name = row[1].__name__.split("_")[-1]
all_ext.append(ext)
all_items.append(name + " files (*" + ext + ")")
for ext, names in mne_supported:
for name in names:
all_items.append(name + " files (*" + ext + ")")

filter_string = "All supported (*" + " *".join(all_ext) + ");" ";"
filter_string = filter_string + ";" ";".join(all_items)
Expand Down
14 changes: 14 additions & 0 deletions meggie/utilities/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import numpy as np
import mne

from mne.io._read_raw import _get_supported as mne_get_supported


def open_raw(fname, preload=True, verbose="info"):
"""Reads a raw from file.
Expand Down Expand Up @@ -266,3 +268,15 @@ def homepath():
return "."

return home


def get_supported_formats():
mne_supported = mne_get_supported()

items = []
for ext_item in mne_supported.items():
ext = ext_item[0]
names = [val[0] for val in ext_item[1].items()]
items.append((ext, names))

return items
9 changes: 0 additions & 9 deletions meggie/utilities/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,6 @@ def setup_experiment(self):

def run_action(self, action_name, handler, data={}, patch_paths=[]):

# patch mne's plt_show to not show plots
utils = importlib.import_module("mne.viz.utils")
epochs = importlib.import_module("mne.viz.epochs")

def patched_plt_show(*args, **kwargs):
utils.plt_show(show=False, fig=None, **kwargs)

self.monkeypatch.setattr(epochs, "plt_show", patched_plt_show)

# patch logger to raise exceptions
logger = logging.getLogger("ui_logger")
self.monkeypatch.setattr(logger, "exception", patched_logger_exception)
Expand Down
9 changes: 9 additions & 0 deletions meggie/utilities/tests/test_filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from meggie.utilities.filemanager import load_csv
from meggie.utilities.filemanager import open_raw
from meggie.utilities.filemanager import save_raw
from meggie.utilities.filemanager import get_supported_formats


def test_create_timestamped_folder():
Expand Down Expand Up @@ -63,3 +64,11 @@ def test_save_and_load_raw():
raw = None

open_raw(path)


def test_supported_formats():
supported_formats = get_supported_formats()
assert isinstance(supported_formats, list)
assert isinstance(supported_formats[0], tuple)
assert isinstance(supported_formats[0][0], str)
assert isinstance(supported_formats[0][1], list)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav:
- Getting Started: user-guide/getting-started.md
- Experiments: user-guide/experiments.md
- Actions: user-guide/actions.md
- Plugins: user-guide/plugins.md
- Developer Guide:
- Architecture: developer-guide/architecture.md
- Development: developer-guide/development.md
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mne==1.3.1
numpy==1.23.5
matplotlib==3.7.3
mne==1.6.1
numpy==1.26.4
matplotlib==3.8.3
scikit-learn
python-json-logger
h5io
Expand Down
Loading

0 comments on commit 2d34019

Please sign in to comment.