moabb icon indicating copy to clipboard operation
moabb copied to clipboard

Error loading Schirrmeister2017

Open AlexandreBleuze opened this issue 3 years ago • 2 comments

Hi, I'm currently trying to load dataset Schirrmeister2017 for my research and got the following error :

Traceback (most recent call last):
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\JetBrains\PyCharmCE2022.1\scratches\scratch_1.py", line 39, in <module>
    X, y, _ = paradigm.get_data(dataset=dataset, subjects=[subject])
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\Python\Python39\site-packages\moabb\paradigms\base.py", line 243, in get_data
    proc = self.process_raw(raw, dataset, return_epochs=return_epochs)
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\Python\Python39\site-packages\moabb\paradigms\base.py", line 143, in process_raw
    raw_f = raw.copy().filter(
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\Python\Python39\site-packages\mne\io\base.py", line 1036, in filter
    return super().filter(
  File "<decorator-gen-108>", line 22, in filter
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\Python\Python39\site-packages\mne\filter.py", line 1988, in filter
    _check_preload(self, 'inst.filter')
  File "\\filesrv4\home$\bleuzea\.windows\Application Data\Python\Python39\site-packages\mne\utils\check.py", line 223, in _check_preload
    raise RuntimeError(
RuntimeError: By default, MNE does not load data into main memory to conserve resources. inst.filter requires raw data to be loaded. Use preload=True (or string) in the constructor or raw.load_data().

The error happens for 0.24.1 and 1.0.3 versions of MNE.

A simple code to reproduce the error is :

from moabb.datasets import Schirrmeister2017
from moabb.paradigms import MotorImagery
MotorImagery().get_data(Schirrmeister2017(), subjects=[1])

AlexandreBleuze avatar Jun 10 '22 09:06 AlexandreBleuze

The best way I found to deal with this error is to as MNE to preload the data during loading. In order to do so, it is possible to modify "moabb\datasets\schirrmeister2017.py" at line 84 from :

        train_raw, test_raw = [
            mne.io.read_raw_edf(path, infer_types=True)
            for path in self.data_path(subject)
        ]

to :

        train_raw, test_raw = [
            mne.io.read_raw_edf(path, infer_types=True, preload=True)
            for path in self.data_path(subject)
        ]

However, I don't know if there was a reason not to preload the raw already. So tell me if it was the case and I can search another way to correct it.

AlexandreBleuze avatar Jun 10 '22 09:06 AlexandreBleuze

Thank you for the fix suggestion! I am not familiar with this dataset in particular, but in general, this would load the data at a point where you may or may not want to have it already in memory. We could also fix this more generally in case other dataset wrappers have issues in the future.

@sylvchev I would simply add raw_f.load_data() just before line 143 here:

https://github.com/NeuroTechX/moabb/blob/fe38df891bc9535d5b71c8510eb4ae82cab147df/moabb/paradigms/base.py#L142-L145

If the data is not yet loaded it will load it now, if it is already loaded it will do nothing.

jsosulski avatar Jun 29 '22 07:06 jsosulski

Fixed with #290

sylvchev avatar Jan 04 '23 00:01 sylvchev