mne-tools / mne-tools/mne-python
DOC: metadata must have the same number of rows as events
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.5k
- Forks
- 1.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Description
I am trying to create epochs with metadata from raw, but run into an error with a piece of code that worked fine about 2 months ago (some previous version, likely 0.20.dev).
I updated to the latest master.
I want to use a subset of events of interest, while my raw data contains more events.
Creating epochs without metadata works fine.
(I tried to comment out the size check in _check_metadata, but it breaks later then.)
File "/home/sh254795/anaconda3/lib/python3.7/site-packages/mne/utils/mixin.py", line 358, in _check_metadata
% (len(metadata), len(self.events)))ValueError: metadata must have the same number of rows (38) as events (86)
Have there been any changes to this code that could explain the error?
Example:
import os
import numpy as np
import mne
import pandas as pd
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
raw.crop(tmax=60).load_data()
# find all events
events = mne.find_events(raw, stim_channel='STI 014')
# define events of interest
event_id = dict(A=4, B=3)
tmin = -0.1
tmax = 0.5
#%% create metadata for the events of interest
# count events of interest
n_events = sum(events[:,2] == 3) + sum(events[:,2] == 4)
# create arbitrary metadata
METADATA = np.arange(0,n_events)
META_DF = pd.DataFrame(data=METADATA, columns = ['trial'])
# Epoch the data without metadata - FINE
print('creating epochs...')
epochs = mne.Epochs(raw, events, event_id, tmin, tmax)
# Epoch the data with metadata - BREAKS
print('creating epochs...')
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, metadata=META_DF)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible mne.Epochs call in the issue and inspect _check_metadata in mne/utils/mixin.py, comparing the metadata row count with the selected events. Verify the intended behavior for metadata built only from event codes 3 and 4, then confirm the corrected behavior with a regression test or the provided example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100