Skip to content

Commit

Permalink
Update mne, numpy and matplotlib versions and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teekuningas committed Mar 7, 2024
1 parent ad62422 commit d403508
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
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
14 changes: 7 additions & 7 deletions meggie/mainwindow/dialogs/addSubjectDialogMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 +79,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)
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

0 comments on commit d403508

Please sign in to comment.