DOC: metadata must have the same number of rows as events
See original GitHub issueI 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)
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
mne-python/epochs.py at main - GitHub
If duplicate time samples have same event val, "merge" == "drop". # and no new event_id key ... 'The number of epochs and...
Read more >Recording with too little events - MNE Forum - Discourse
I'm now getting this error message → ValueError: metadata must have the same number of rows (176) as events (170). I had one...
Read more >Use content types to manage content consistently on a site
Applying consistent metadata across multiple document libraries is only one benefit of using content types to manage your content.
Read more >Metadata Vocabulary for Tabular Data - W3C
Tabular data MUST conform to the description from [ tabular-data-model ]. In particular note that each row MUST contain the same number of ......
Read more >Events and streams | Datastream | Google Cloud
Streams, objects, and events have data and metadata associated with them. ... This number is used with rs_id and uniquely identifies a row...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, thanks! My point is more that metadata is a super useful feature, which we use more and more, but it is quite difficult to implement for people less proficient with python. Hence, one nice complete tutorial where the above points are made explicit would be great.
I would suggest you trim your
eventsto the ones you plan on using. This could just be a quick mask line like: