Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Error: "IndexError: index 0 is out of bounds for axis 0 with size 0" #8085

Closed
balandongiv opened this issue Aug 4, 2020 · 9 comments

Comments

@balandongiv
Copy link

balandongiv commented Aug 4, 2020

Describe the bug

While executing ica.plot_properties(raw, picks=ecg_indices), the compiler return an error

IndexError: index 0 is out of bounds for axis 0 with size 0

The full error trail:

    ica.plot_properties(raw, picks=ecg_indices)
  File "lib\site-packages\mne\preprocessing\ica.py", line 1746, in plot_properties
    figsize=figsize, show=show, reject=reject)
  File "\lib\site-packages\mne\viz\ica.py", line 427, in plot_ica_properties
    psds, freqs = psd_multitaper(epochs_src, picks=picks, **psd_args)
  File "<decorator-gen-61>", line 21, in psd_multitaper
  File "\lib\site-packages\mne\time_frequency\psd.py", line 334, in psd_multitaper
    n_jobs=n_jobs, verbose=verbose)
  File "<decorator-gen-48>", line 21, in psd_array_multitaper
  File "\lib\site-packages\mne\time_frequency\multitaper.py", line 422, in psd_array_multitaper
    n_times, sfreq, bandwidth, low_bias, adaptive)
  File "<decorator-gen-47>", line 21, in _compute_mt_params
  File "\lib\site-packages\mne\time_frequency\multitaper.py", line 350, in _compute_mt_params
    interp_from=interp_from)
  File "lib\site-packages\mne\time_frequency\multitaper.py", line 95, in dpss_windows
    dpss = _get_dpss()(N, half_nbw, Kmax)
  File "\lib\site-packages\scipy\signal\windows\windows.py", line 1938, in dpss
    if w[w * w > thresh][0] < 0:
IndexError: index 0 is out of bounds for axis 0 with size 0

Steps to reproduce

filename = r'S17_3.mff' # can be downloaded via the link: https://drive.google.com/drive/folders/14R_2A-ceqOFvRkDZH6Skm4CqF5B-K7Co?usp=sharing
raw = mne.io.read_raw_egi(filename, preload=True)
montage = mne.channels.make_standard_montage('GSN-HydroCel-129')
montage.ch_names[-1] = 'E129'
raw.set_montage(montage, match_case=False)
raw.filter(1., 40.)
raw.crop(0, 595)  # crop huge artifact at the end
filt_raw = raw.copy()

ica = ICA(n_components=30, random_state=97)
ica.fit(filt_raw)
ica.exclude = []

# find which ICs match the ECG pattern
ecg_indices, ecg_scores = ica.find_bads_ecg(raw)
ica.exclude = ecg_indices

# barplot of ICA component "ECG match" scores
ica.plot_scores(ecg_scores)

# plot diagnostics
ica.plot_properties(raw, picks=ecg_indices)

# plot ICs applied to raw data, with ECG matches highlighted
ica.plot_sources(raw)

Additional information

System:

Windows 10
anaconda3
mne-0.21.dev0
Python 3.7
Link to download S17_3.mff

@larsoner
Copy link
Member

larsoner commented Aug 4, 2020

I can't replicate on Linux, it's possible that this is a windows issue. Before I boot a VM to look into it, when you hit the error can you try:

>>> import pdb; pdb.pm()
(Pdb) p (NW, Kmax, sym, norm, M, thresh, np.abs(m).max())
...

and let us know the output? It can help with debugging

@balandongiv
Copy link
Author

Thanks for the response @larsoner . Im using PyCharm and I am not familiar with pdb for troubleshooting. May I know other approach to capture specific output that you have in mind?

@larsoner
Copy link
Member

larsoner commented Aug 4, 2020

Can you run Python from a standard terminal instead? Copy-pasting your code (with an import mne at the top) into some file then do:

python -i whatever.py

and you should end up dropped to a prompt where you can import pdb; pdb.pm(). But really I'm surprised Pycharm doesn't give you a way to interact with the Python terminal once a script completes. It's standard Python behavior if you pass python -i or use "interactive mode".

It's also likely that pycharm has some built-in debugging capability where you can have it drop to a prompt if it hits an error.

@balandongiv
Copy link
Author

balandongiv commented Aug 5, 2020

Thanks for the clear instruction @larsoner . Surprisingly, the plot was rendered without any hiccup when executing the commands using "interactive mode". However, there is a catch whereby the figure was plotted properly only during the first execution (i.e., execute only the ica.plot_properties(raw, picks=ecg_indices)). But, after I close the pop figure and execute the line ica.plot_properties(raw, picks=ecg_indices) , the same error "IndexError: index 0 is out of bounds for axis 0 with size 0" was shot.
The same error also was given if executing the line ica.plot_properties(raw, picks=ecg_indices) while the first figure is still open.

Also, the blank figure outputted is accessible via the link: https://imgur.com/gallery/7F44vsE

For some reason, PyCharm does not show any prompt to input the import pdb; pdb.pm() whenever the error exist. There is maybe some setting that I am not aware off.I will try to figure this up and update it back here

@larsoner
Copy link
Member

Hopefully this was fixed by #8103, let's reopen if not

@behinger
Copy link

behinger commented Dec 3, 2020

I still have the same problem with todays 0.22dev version, also on windows 10. If I run it through debugger it works. Somtimes it works one time and not the second

If I run your post-mortem debugging thingy I get this:

(Pdb) p (NW, Kmax, sym, norm, M, thresh, np.abs(M).max())
 (4.0, 8, True, 2, 2048, 0.00048828125, 2048)

(note that I changed the np.abs(m) to np.abs(M) hope that was intended)

@larsoner
Copy link
Member

larsoner commented Dec 4, 2020

@behinger do you have NumPy 1.19.4? I wonder if it's this Windows bug:

https://developercommunity2.visualstudio.com/t/fmod-after-an-update-to-windows-2004-is-causing-a/1207405
numpy/numpy#16744

For now the workaround is to install NumPy 1.19.3 on Windows.

@behinger
Copy link

behinger commented Dec 4, 2020

edit:Oh no. It didnt resolve it after all, for some reason it worked for the first component, but not a seocnd one - also not if I rerun the same cell

nice! yes indeed I had Numpy 1.19.2 installed. With 1.19.3 it works now.

Thanks alot! it might also explain random SVD errors I got :)

@LMBooth
Copy link

LMBooth commented Dec 10, 2020

Is there a specific Scipy library we should maybe be using too?

I've got a similar error when trying to open multiple figures from my epochs object and have tried installing my Numpy to version 1.19.3 and have MNE 0.21.2 installed. I'm using a Windows machine too.

My initial epochs['Visual/easy'].plot_psd() works but the second creates the error seen in the prompt output.

Python code:

import os
import mne
import matplotlib
matplotlib.use('Qt5Agg',warn=False, force=True)
import matplotlib.pyplot as plt
from mne.preprocessing import (ICA, create_eog_epochs, create_ecg_epochs,corrmap)

raw_corrected = mne.io.read_raw_fif('Raw_Test_data_Filtered_&_ICA.fif')
events = mne.find_events(raw_corrected, stim_channel='Status')

mapping = {'Visual/easy':1,'Visual/hard':2,'Audiotry/easy':3,
           'Auditory/hard':4,'V/E':5,'V/H':6,'A/E':7,'A/H':8,
           'Start':9,'Stop':10}

epochs = mne.Epochs(raw_corrected, events, tmin=-0.2, tmax=0.5, event_id=mapping, preload=True)


epochs['Visual/easy'].plot_psd() 
epochs['Visual/hard'].plot_psd()

Prompt:

C:\Users\Liam\Documents\python\EEG_process\adam_math2.py:8: RuntimeWarning: This filename (Raw_Test_data_Filtered_&_ICA.fif) does not conform to MNE naming conventions. All raw files should end with raw.fif, raw_sss.fif, raw_tsss.fif, raw.fif.gz, raw_sss.fif.gz, raw_tsss.fif.gz or _meg.fif
  raw_corrected = mne.io.read_raw_fif('Raw_Test_data_Filtered_&_ICA.fif')
    Range : 0 ... 699629 =      0.000 ...  2798.516 secs
Ready.
486 events found
Event IDs: [ 1  2  3  4  5  6  7  8  9 10]
Not setting metadata
Not setting metadata
486 matching events found
Applying baseline correction (mode: mean)
0 projection items activated
Loading data for 486 events and 176 original time points ...
0 bad epochs dropped
    Using multitaper spectrum estimation with 7 DPSS windows
Traceback (most recent call last):
  File "C:\Users\Liam\Documents\python\EEG_process\adam_math2.py", line 19, in <module>
    epochs['Visual/hard'].plot_psd()
  File "C:\python37\lib\site-packages\mne\epochs.py", line 1096, in plot_psd
    verbose=verbose)
  File "<decorator-gen-147>", line 24, in plot_epochs_psd
  File "C:\python37\lib\site-packages\mne\viz\epochs.py", line 955, in plot_epochs_psd
    n_jobs=n_jobs)
  File "<decorator-gen-65>", line 24, in psd_multitaper
  File "C:\python37\lib\site-packages\mne\time_frequency\psd.py", line 330, in psd_multitaper
    n_jobs=n_jobs, verbose=verbose)
  File "<decorator-gen-50>", line 24, in psd_array_multitaper
  File "C:\python37\lib\site-packages\mne\time_frequency\multitaper.py", line 422, in psd_array_multitaper
    n_times, sfreq, bandwidth, low_bias, adaptive)
  File "<decorator-gen-49>", line 24, in _compute_mt_params
  File "C:\python37\lib\site-packages\mne\time_frequency\multitaper.py", line 350, in _compute_mt_params
    interp_from=interp_from)
  File "C:\python37\lib\site-packages\mne\time_frequency\multitaper.py", line 95, in dpss_windows
    dpss = _get_dpss()(N, half_nbw, Kmax)
  File "C:\python37\lib\site-packages\scipy\signal\windows\windows.py", line 1938, in dpss
    if w[w * w > thresh][0] < 0:
IndexError: index 0 is out of bounds for axis 0 with size 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants