I would like to downsample by half my data to speed up computation. I am trying to use the mne.filter.resample() method, though I get a weird error:
rawDown = mne.filter.resample(raw, down=2, npad='auto')
Traceback (most recent call last):
File "<ipython-input-5-82bba6e4fb03>", line 1, in <module>
rawDown = mne.filter.resample(raw, down=2, npad='auto')
File "<decorator-gen-118>", line 24, in resample
File "/opt/anaconda3/lib/python3.8/site-packages/mne/filter.py", line 1443, in resample
x = _check_filterable(x, 'resampled')
File "/opt/anaconda3/lib/python3.8/site-packages/mne/filter.py", line 1377, in _check_filterable
x = np.asanyarray(x)
File "/opt/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py", line 138, in asanyarray
return array(a, dtype, copy=False, order=order, subok=True)
File "/opt/anaconda3/lib/python3.8/site-packages/mne/io/base.py", line 770, in __getitem__
sel, start, stop = self._parse_get_set_params(item)
File "/opt/anaconda3/lib/python3.8/site-packages/mne/io/base.py", line 705, in _parse_get_set_params
sel = _picks_to_idx(self.info, item[0])
File "/opt/anaconda3/lib/python3.8/site-packages/mne/io/pick.py", line 1032, in _picks_to_idx
raise ValueError('All picks must be < n_channels (%d), got %r'
ValueError: All picks must be < n_channels (256), got 256
I don’t understand this – is it not the method I need? Thanks!
Hello @robpetrosino, actually I’ve never used mne.filter.resample() – instead I’d always go with Raw.resample(). Mind checking this out to see if it works for you?
I was just saying – without your message, I could not have found the method in the API page one can access from the MNE webpage, so I was wondering where one could have found it without asking you guys here. (Also, the search engine of the website does not work for me for some reason).
I always go to the documentation of the data type I’m working with – in your case, Raw – and check out the available attributes and methods. Or I simply use the search function, which unfortunately seems to be broken for you (actually, is that still the case? We deployed a fix yesterday I believe…)
I have notice a potential bug in the resample() method. I have noticed that that, after resampling raw data together with event onsets, the usual attributes are no longer available. The helper of the function advises to call the events argument to ensure that event triggers are resampled together with the data and to avoid jitter on the event onsets.
rawDown1 = raw.resample(sfreq=raw.info['sfreq']/2, events=events)
rawDown1.info
Traceback (most recent call last):
File "<ipython-input-22-a1b523d4836c>", line 1, in <module>
rawDown1.info
AttributeError: 'tuple' object has no attribute 'info'
If the events argument of the function is not called, the attributes are still available.
If you pass events, Raw.resample() will return a tuple of the resampled raw data and the respective events. Also there was a mistake in my solution above: Raw.resample() works in-place, so you should run it on a copy.
Putting this all together, the correct approach for you would be: