GithubHelp home page GithubHelp logo

Comments (14)

mscheltienne avatar mscheltienne commented on May 26, 2024 1

Exactly, in this case to do so, one channel had to be renamed to match the name in the montage.

from mne-icalabel.

adam2392 avatar adam2392 commented on May 26, 2024

Can you use the version on main?

Also, the exemplar = np.mean(data_[similar_pts], axis=0) line is nowhere in mne-icalabel I think? Is there a missing error message?

from mne-icalabel.

mscheltienne avatar mscheltienne commented on May 26, 2024

Indeed a couple of missing error message, can you share the full traceback? Found the lines here

exemplar = np.mean(data_[similar_pts], axis=0)

Also, could you save the ICA decomposition with ica.save and share the ICA decomposition and the Raw file (you can save it with raw_filt.save)?

from mne-icalabel.

mscheltienne avatar mscheltienne commented on May 26, 2024

Arf, the traceback is incomplete because it's a Jupyter notebook, sneaky ... on the left side..

from mne-icalabel.

sjyzhu avatar sjyzhu commented on May 26, 2024

Thanks for your reply!
Below is the complete traceback
error

from mne-icalabel.

sjyzhu avatar sjyzhu commented on May 26, 2024

Can you use the version on main?

Sorry, I don't know what main means... = =

from mne-icalabel.

sjyzhu avatar sjyzhu commented on May 26, 2024

Also, could you save the ICA decomposition with ica.save and share the ICA decomposition and the Raw file (you can save it with raw_filt.save)?

I'm not sure if I can upload raw files, because these are from confidential patient data.

from mne-icalabel.

mscheltienne avatar mscheltienne commented on May 26, 2024

main means the not-yet-released code, i.e. the version available as of today on the GitHub repository. You can install it in an environment by doing pip install git+https://github.com/mne-tools/mne-icalabel. This is to eliminate the possibility of a bug that has already been fixed but has not yet been released.

I'm not sure if I can upload raw files, because these are from confidential patient data.

Unlucky, as it's difficult to debug if we can not reproduce the error.
Pinging @yjmantilla who authored the gdatav4 translation, by any chance does this error look familiar to you?

If you don't mind, I would like to give you a couple of short code snippets that I'd like you to run and return the output here to help us debug the issue further without providing us with the RAW/ICA files. Would that be OK with you?
Do you only use Jupyter or also other IDEs, and especially do you know how to use breakpoints and debug mode?

from mne-icalabel.

sjyzhu avatar sjyzhu commented on May 26, 2024

main means the not-yet-released code, i.e. the version available as of today on the GitHub repository. You can install it in an environment by doing pip install git+https://github.com/mne-tools/mne-icalabel. This is to eliminate the possibility of a bug that has already been fixed but has not yet been released.

The development version has been installed, and the same bug appeared.

If you don't mind, I would like to give you a couple of short code snippets that I'd like you to run and return the output here to help us debug the issue further without providing us with the RAW/ICA files. Would that be OK with you? Do you only use Jupyter or also other IDEs, and especially do you know how to use breakpoints and debug mode?

OK, I can debug locally through your code.
Is it possible to debug using .py files through vscode?

from mne-icalabel.

mscheltienne avatar mscheltienne commented on May 26, 2024

Thanks for the help, yes you could debug using VSCode, but if you are not familiar with breakpoints and debug mode, there is no gain compare to Jupyter.

In the following part, raw designs the Raw recording used to fit the ICA and ica the ICA decomposition. Here are the code snippet:


First let's get some information on your Raw recording, especially about the channels:

  1. MNE information

Paste in this thread the printed information:

from mne import sys_info
print (mne.sys_info())
  1. raw.info

Paste in this thread the printed information:

# remove identification information if present
raw.info["description"] = ""
raw.info["device_info"] = dict()
raw.info["experimenter"] = ""
raw.info["subject_info"] = dict()
raw.info["temp"] = None
# display information
print (raw.info)
  1. Montage

Paste in this thread the figure returned by:

raw.get_montage().plot()
  1. icawinv

Return the file icawinv.npy:

import numpy as np


# Compute icawinv
n_components = ica.n_components_
s = np.sqrt(ica.pca_explained_variance_)[:n_components]
u = ica.unmixing_matrix_ / s
v = ica.pca_components_[:n_components, :]
weights = (u * s) @ v
icawinv = np.linalg.pinv(weights)
del weights
# sanity-check
assert icawinv.shape[-1] == ica.n_components_
assert icawinv.ndim == 2
np.save("icawinv.npy", icawinv, allow_pickle=False)
  1. picks of the topoplot feature

Paste in this thread the printed information:

print (ica.ch_names)
  1. EEG channels coordinates in spherical coordinate system

Return the file rd.npy and th.npy:

import numpy as np

from mne_icalabel.iclabel.utils import _mne_to_eeglab_locs


rd, th = _mne_to_eeglab_locs(raw, ica.ch_names)
np.save("rd.npy", rd, allow_pickle=False)
np.save("th.npy", th, allow_pickle=False)

That should be enough for debug and for me to reproduce the error locally.

from mne-icalabel.

sjyzhu avatar sjyzhu commented on May 26, 2024

Thanks for the help, yes you could debug using VSCode, but if you are not familiar with breakpoints and debug mode, there is no gain compare to Jupyter.

Sorry for not getting back to you for such a long time.
After changing a batch of data, the issue did not occur again. Therefore, it should have been a problem with that particular batch of data.
Thank you very much for your patient guidance !

from mne-icalabel.

GABowers avatar GABowers commented on May 26, 2024

I'm getting this error. Test file is attached, and the test script is here:

import mne, mne_icalabel

if __name__ == "__main__":
    fn = './test_raw.fif'
    raw = mne.io.read_raw_fif(fn, preload=True)
    standard = mne.channels.make_standard_montage(kind = 'biosemi64')
    raw.set_montage(standard, on_missing='ignore')
    raw.set_eeg_reference(['LMA', 'RMA'])
    raw.filter(l_freq=1, h_freq=100, picks=None)
    ica = mne.preprocessing.ICA(n_components=0.999999, method='infomax', fit_params=dict(extended=True), max_iter='auto', random_state=1)
    ica.fit(raw, picks=['eeg'])
    ic_labels = mne_icalabel.label_components(raw, ica, method='iclabel')
    labels = ic_labels["labels"]
    exclude_idx = [idx for idx, label in enumerate(labels) if label not in ["brain", "other"]]
    ica.exclude = exclude_idx

test_raw.zip

from mne-icalabel.

mscheltienne avatar mscheltienne commented on May 26, 2024

Thanks for the reproducible example, it makes debugging way simpler. The error occurs because of a nan in the x and y variables here:

myepsx = np.spacing(0.5 * (np.max(x) - np.min(x))) ** (1 / 3)
myepsy = np.spacing(0.5 * (np.max(y) - np.min(y))) ** (1 / 3)

This is due to raw.set_montage(standard, on_missing='ignore'), which ignored missing entries. But we actually need a montage with ALL electrodes coordinates to compute the topographic map feature. We could ignore missing channels in the interpolation function, further down the road, but I think we should also issue a warning further up the road. Here is a corrected code snippet for your file:

from mne.io import read_raw_fif
from mne.preprocessing import ICA
from mne_icalabel import label_components

fname = r"C:\Users\scheltie\Downloads\test_raw.fif"

raw = read_raw_fif(fname, preload=True)
raw.rename_channels({"Afz": "AFz"})
raw.set_montage("biosemi64")
raw.set_eeg_reference(["LMA", "RMA"])
raw.filter(l_freq=1, h_freq=100, picks=None)
raw.drop_channels(["LMA", "RMA"])
ica = ICA(
    n_components=0.999999,
    method="infomax",
    fit_params=dict(extended=True),
    max_iter="auto",
    random_state=1,
)
ica.fit(raw, picks=["eeg"])
ic_labels = label_components(raw, ica, method="iclabel")

I'll think about it and open a PR to close this issue.

from mne-icalabel.

GABowers avatar GABowers commented on May 26, 2024

Okay great, thanks! So in general, I should try to set the montage without ignoring anything?

It looks like you drop the mastoids before ICA. Any particular reason? I tried it with and without that and it works either way.

from mne-icalabel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.