Skip to content

Schirrmeister2017 dataset #153

Closed

Description

@PierreGtch

Hi All,
When loading the Schirrmeister2017 dataset, I think that the events are not stored properly in the mne.Info object at this line :

cnt.info["events"] = np.array(event_arr).T

In the MNE doc, it is said that the "events" parameter of mne.Info objects is a list of dicts with "channels" and "list" keys.
The "list" key points to the ndarray containing the events.

So I think that this line could be replaced by something like :

cnt.info["events"] = [dict(list=np.array(event_arr).T, channels=None), ] 

This issue creates problems when trying to save the dataset :

  File "<decorator-gen-183>", line 20, in save
  File "/home/pguetsch/.local/lib/python3.8/site-packages/mne/epochs.py", line 1638, in save
    _save_split(this_epochs, fname, part_idx, n_parts, fmt)
  File "/home/pguetsch/.local/lib/python3.8/site-packages/mne/epochs.py", line 104, in _save_split
    write_meas_info(fid, info)
  File "/home/pguetsch/.local/lib/python3.8/site-packages/mne/io/meas_info.py", line 1507, in write_meas_info
    if event.get('channels') is not None:
AttributeError: 'numpy.ndarray' object has no attribute 'get'

Activity

  1. jsosulski commented on Mar 18, 2021

    @jsosulski
    Collaborator

    What do you mean with saving the dataset? When the results are created or when saving raw data?

  2. PierreGtch commented on Mar 18, 2021

    @PierreGtch
    CollaboratorAuthor

    What do you mean with saving the dataset? When the results are created or when saving raw data?

    I mean when saving raw data

    Here is a minimal example :

    from moabb.datasets import Schirrmeister2017                                                                                                                                                                                          
    ds = Schirrmeister2017().get_data([1])
    print(ds)
    ds[1]['session_1']['train'].save('temp-raw.fif', overwrite=True)

    And the output :

    Creating RawArray with float64 data, n_channels=128, n_times=1225545
        Range : 0 ... 1225544 =      0.000 ...  2451.088 secs
    Ready.
    Creating RawArray with float64 data, n_channels=128, n_times=616535
        Range : 0 ... 616534 =      0.000 ...  1233.068 secs
    Ready.
    {1: {'session_1': {'train': <RawArray | 129 x 1225545 (2451.1 s), ~1.18 GB, data loaded>,
       'test': <RawArray | 129 x 616535 (1233.1 s), ~606.9 MB, data loaded>}}}
    Overwriting existing file.
    Writing /home/pguetsch/arpe/eeg-embeddings/temp-raw.fif
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-13-96409ccfbc1a> in <module>
    ----> 1 ds[1]['session_1']['train'].save('temp-raw.fif', overwrite=True)
    
    <decorator-gen-174> in save(self, fname, picks, tmin, tmax, buffer_size_sec, drop_small_buffer, proj, fmt, overwrite, split_size, split_naming, verbose)
    
    /home/pguetsch/.local/lib/python3.8/site-packages/mne/io/base.py in save(self, fname, picks, tmin, tmax, buffer_size_sec, drop_small_buffer, proj, fmt, overwrite, split_size, split_naming, verbose)
       1402         _validate_type(split_naming, str, 'split_naming')
       1403         _check_option('split_naming', split_naming, ('neuromag', 'bids'))
    -> 1404         _write_raw(fname, self, info, picks, fmt, data_type, reset_range,
       1405                    start, stop, buffer_size, projector, drop_small_buffer,
       1406                    split_size, split_naming, 0, None, overwrite)
    
    /home/pguetsch/.local/lib/python3.8/site-packages/mne/io/base.py in _write_raw(fname, raw, info, picks, fmt, data_type, reset_range, start, stop, buffer_size, projector, drop_small_buffer, split_size, split_naming, part_idx, prev_fname, overwrite)
       1882 
       1883     picks = _picks_to_idx(info, picks, 'all', ())
    -> 1884     fid, cals = _start_writing_raw(use_fname, info, picks, data_type,
       1885                                    reset_range, raw.annotations)
       1886     with ctx, fid:
    
    /home/pguetsch/.local/lib/python3.8/site-packages/mne/io/base.py in _start_writing_raw(name, info, sel, data_type, reset_range, annotations)
       2086         cals.append(info['chs'][k]['cal'] * info['chs'][k]['range'])
       2087 
    -> 2088     write_meas_info(fid, info, data_type=data_type, reset_range=reset_range)
       2089 
       2090     #
    
    /home/pguetsch/.local/lib/python3.8/site-packages/mne/io/meas_info.py in write_meas_info(fid, info, data_type, reset_range)
       1501     for event in info['events']:
       1502         start_block(fid, FIFF.FIFFB_EVENTS)
    -> 1503         if event.get('channels') is not None:
       1504             write_int(fid, FIFF.FIFF_EVENT_CHANNELS, event['channels'])
       1505         if event.get('list') is not None:
    
    AttributeError: 'numpy.ndarray' object has no attribute 'get'
    

    Also, here are the version I have installed :

    mne                           0.22.0
    moabb                         0.2.1
    
  3. jsosulski commented on Mar 18, 2021

    @jsosulski
    Collaborator

    I see. Definitely an issue, but I wonder whether mne is only complaining when writing the data to a file or there are also issues during epoching or other processing in the core MOABB application.

  4. PierreGtch commented on Mar 18, 2021

    @PierreGtch
    CollaboratorAuthor

    yes I don't know either
    But this seems to fix the saving part at least :

    def _fix_markers(raw):
        events = mne.find_events(raw)
        raw.info['events'] = [dict(list=events, channels=None)]
    
    ds = Schirrmeister2017().get_data([1])
    raw = ds[1]['session_1']['train'] 
    _fix_markers(raw)
    raw.save('temp-raw.fif', overwrite=True)
    Creating RawArray with float64 data, n_channels=128, n_times=1225545
        Range : 0 ... 1225544 =      0.000 ...  2451.088 secs
    Ready.
    Creating RawArray with float64 data, n_channels=128, n_times=616535
        Range : 0 ... 616534 =      0.000 ...  1233.068 secs
    Ready.
    320 events found
    Event IDs: [1 2 3 4]
    Overwriting existing file.
    Writing /home/pguetsch/arpe/eeg-embeddings/temp-raw.fif
    Closing /home/pguetsch/arpe/eeg-embeddings/temp-raw.fif
    [done]
    
  5. sylvchev commented on Mar 18, 2021

    @sylvchev
    Member

    Thanks for the investigation! I'll check, but I think this occur only for Schirrmeister dataset. Could you confirm @PierreGtch ?

  6. PierreGtch commented on Mar 18, 2021

    @PierreGtch
    CollaboratorAuthor
  7. AliAbdulHussain commented on Mar 18, 2021

    @AliAbdulHussain
    Contributor

    I have a look as well. What is causing this error is lines 249-252 of schirrmeister2017 when commented everything works (currently check whether removing/commenting these lines will effect moabb, I'll update you soon). However, raw.info['events'] is empty (i.e. []). I tried to see whether this is caused by raw.add_channels. However, this is not the case as even when adding it directly while creating RawArray creates an empty list in raw.info['events']. Does anyone know what mne uses raw.info['events']? Maybe when using Annotations, not stim channels.

    Update: commenting/removing 249-252 lines, do not change the Evaluation results for WithSessionEvaluation and CrossSubjectEvaluation (Note that CrossSessionEvaluation can't be done since this dataset contain only one session).

  8. sylvchev commented on Jan 21, 2022

    @sylvchev
    Member

    Ok, I tried the fix from @PierreGtch that works well. No need to comment out lines 249-252 as you proposed @AliAbdulHussain. Even if it does not change the outcomes of evaluation, the code fix from @PierreGtch allows a better handling of the events that could be useful in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions