question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`mne.Epochs` sends wrong log messages (1) on metdata, (2) when `decim` is passed

See original GitHub issue

mne.Epochs sends wrong log messages (1) on metdata, (2) when decim is passed.

MWE:

Try first running this code:

import os
import mne

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).crop(tmax=120)
raw.load_data()
raw.filter(h_freq=40, l_freq=None)

events = mne.find_events(raw, stim_channel='STI 014')
event_dict = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
              'visual/right': 4, 'face': 5, 'button': 32}
epochs = mne.Epochs(raw, events, tmin=-0.2, tmax=0.5, event_id=event_dict,
                    decim=1, preload=True)
print(epochs.times.shape)

This is the logged output, where I can see that the Not setting metadata log is unnecessarily repeated. On the last lines of the log, we see that 421 time points were loaded, and this is indeed the shape of .times

176 events found
Event IDs: [ 1  2  3  4  5 32]
Not setting metadata
Not setting metadata
176 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] sec
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Loading data for 176 events and 421 original time points ...
1 bad epochs dropped
(421,)

Now change decim=1 in the mne.Epochs() call above to decim=2. I would expect the log

Loading data for 176 events and 421 original time points …

to change in terms of “original time points” loaded (should be half as many)

However, this is what we get:

This is the logged output, where the shape of .times has indeed halved as expected, yet the log tells us that 421 time points were loaded.

176 events found
Event IDs: [ 1  2  3  4  5 32]
Not setting metadata
Not setting metadata
176 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] sec
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Loading data for 176 events and 421 original time points ...
1 bad epochs dropped
(211,)

Needed actions

  1. remove duplicate log message on setting metadata. Don’t really know where to fix, maybe around here: https://github.com/mne-tools/mne-python/blob/a3066f6eb3730d13d2dce632ff6cb5d4870fbe7f/mne/utils/mixin.py#L412-L418

  2. adjust logging about loaded time points when creating epochs and decimating. Probably to be fixed somewhere around here: https://github.com/mne-tools/mne-python/blob/a3066f6eb3730d13d2dce632ff6cb5d4870fbe7f/mne/epochs.py#L1388-L1389

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Dec 8, 2021

less unclear?

Yes sorry, I originally wrote “less ambiguous” and went to replace it with “clearer” but only deleted part of the original 😃

I believe the first call can be deleted, WDYT?

I think probably yes? I would try making the change and see if any test breaks. Sometimes in our code we do have more than one assignment like this (where it seems like one is redundant) but it’s necessary for some weird reason like private function calling order… but usually in these cases we try to leave a comment saying “this looks redundant but it’s necessary because …”. If there is no such comment, it’s possibly just cruft / errant double-setting.

It would be good for example for TDD to make it so that you

with catch_logging() as log:
    Epochs(..., verbose=True)
log = log.getvalue()
assert log.count('Setting metadata') == 1

or so

0reactions
larsonercommented, Dec 9, 2021

Or add a msg kwarg to the setter so you can say Adding instead of Replacing

Read more comments on GitHub >

github_iconTop Results From Across the Web

mne.Epochs — MNE 1.2.2 documentation - MNE-Python
If 0 or 1, the data channels (MEG and EEG) will be detrended when loaded. 0 is a constant (DC) detrend, 1 is...
Read more >
Problem with float arithmetic -- creating epochs of same time
I tried to fix this by converting the values from floats to decimals (see: https://www.pythontutorial.net/advanced-python/python-decimal/) but mne throws an ...
Read more >
2 Server Error Message Reference - MySQL :: Developer Zone
Chapter 2 Server Error Message Reference. The MySQL server writes some error messages to its error log, and sends others to client programs....
Read more >
ffmpeg Documentation
4.1.1 Automatic stream selection; 4.1.2 Manual stream selection ... Any message related to possibly incorrect or unexpected events will be shown.
Read more >
System Message Guide for Cisco IOS XE Bengaluru 17.6.x
During operation, the system software sends these messages to the console ... System error messages begin with a percent sign (%) and are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found