Struggles applying the baseline

Hi all,
I am working with some tutorials on MNE-Python and ran into a problem. I used exactly the same code as in the tutorial, but my output is different when it comes to the baseline.

conda 4.10.1
Python 3.9.2
MNE 0.22.1
Windows 10

import pathlib
import matplotlib

import mne
import mne_bids

matplotlib.use('Qt5Agg')
mne.set_log_level('warning')

here it works:

tmin = -0.25 
tmax = 0.8 
baseline = (-0.2, 0) 
epochs = mne.Epochs(raw, 
                    events=events, 
                    event_id=event_id, 
                    tmin=tmin, 
                    tmax=tmax,
                    baseline=baseline, 
                    preload=True) 
epochs

Output:

<Epochs |  320 events (all good), -0.249744 - 0.799181 sec, baseline [-0.2, 0] sec, ~582.5 MB, data loaded,
 'Auditory/Left': 72
 'Auditory/Right': 73
 'Button': 16
 'Smiley': 15
 'Visual/Left': 73
 'Visual/Right': 71>

But when I try to change it to “None” with…

epochs.apply_baseline((None, 0))

or

tmin = -0.3 
tmax = 0.5
baseline = (None, 0) 
epochs = mne.Epochs(raw, 
                    events=events, 
                    event_id=event_id, 
                    tmin=tmin, 
                    tmax=tmax,
                    baseline=baseline, 
                    preload=True) 
epochs

I get this output:

<Epochs |  320 events (all good), -0.299693 - 0.499488 sec, baseline [-0.299693, 0] sec, ~444.8 MB, data loaded,
 'Auditory/Left': 72
 'Auditory/Right': 73
 'Button': 16
 'Smiley': 15
 'Visual/Left': 73
 'Visual/Right': 71>

What am I doing wrong?

Hello and welcome to the forum!

What did you expect to happen? Based on the code and output you posted, all seems to behave correctly. What were you expecting to see?

Best wishes,

Richard

I expected an output with
…, baseline [None, 0] sec, …
Your youtube workshop is awesome btw! But my graphics are different than yours because of this :confused:

1 Like

the console representation of baseline has recently changed, but the behavior is (I think?) unchanged. Passing (None, 0) as the baseline parameter should still set the baseline as the span from beginning of the epoch to time 0. The only difference now is that when you print(epochs) it will tell you what that beginning-of-the-epoch-time is, instead of saying “none”.

If you plot the data, do they look how you expect? E.g., epochs.average().plot() should show baseline from start of epoch to time zero.

@drammock is right, it’s just the output that looks slightly different now (in fact, we were trying to make it more intuitive by displaying the actual times now instead of just None!) So you should be good!

Thank you! :slight_smile: Good to hear back from people who come across these videos :slight_smile:

@drammock Hmmh but that would imply that my graphics should look the same as the ones in the video where Richard uses (None, 0), doesn’t it? But my graphics have different time spans (see foto: left is the one from Richard, right is mine. I used the same code). I started watching tutorials a week ago and am completely new to EEG data. So maybe this isn’t even a problem…don’t know.


epochs.average().plot() shows the same time span as in the foto.

Hello,

could you please share your entire script so we can have a closer look? Thanks!

Okay. I took this from your “Creating epochs and generating evoked responses (ERP/ERF)” tutorial.

import pathlib
import matplotlib

import mne
import mne_bids

matplotlib.use('Qt5Agg')
bids_root = pathlib.Path('out_data/sample_BIDS')

bids_path = mne_bids.BIDSPath(subject='01',
                              session='01',
                              task='audiovisual',
                              run='01',
                              datatype='meg',
                              root=bids_root)

raw = mne_bids.read_raw_bids(bids_path)
raw.load_data()
raw.filter(l_freq=0.1, h_freq=40)
events, event_id = mne.events_from_annotations(raw)

Opening raw data file out_data\sample_BIDS\sub-01\ses-01\meg\sub-01_ses-01_task-audiovisual_run-01_meg.fif…
Read a total of 3 projection items:
PCA-v1 (1 x 102) idle
PCA-v2 (1 x 102) idle
PCA-v3 (1 x 102) idle
Range : 25800 … 192599 = 42.956 … 320.670 secs
Ready.
Reading events from out_data\sample_BIDS\sub-01\ses-01\meg\sub-01_ses-01_task-audiovisual_run-01_events.tsv.
Reading channel info from out_data\sample_BIDS\sub-01\ses-01\meg\sub-01_ses-01_task-audiovisual_run-01_channels.tsv.
Reading 0 … 166799 = 0.000 … 277.714 secs…

C:\Users\S_Hei\AppData\Roaming\Python\Python39\site-packages\mne_bids\read.py:406: RuntimeWarning: The unit for channel(s) STI 001, STI 002, STI 003, STI 004, STI 005, STI 006, STI 014, STI 015, STI 016 has changed from V to NA.
raw.set_channel_types(channel_type_dict)

Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 0.1 - 40 Hz

FIR filter parameters
Designing a one-pass, zero-phase, non-causal bandpass filter:

  • Windowed time-domain design (firwin) method
  • Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
  • Lower passband edge: 0.10
  • Lower transition bandwidth: 0.10 Hz (-6 dB cutoff frequency: 0.05 Hz)
  • Upper passband edge: 40.00 Hz
  • Upper transition bandwidth: 10.00 Hz (-6 dB cutoff frequency: 45.00 Hz)
  • Filter length: 19821 samples (33.001 sec)

Used Annotations descriptions: [‘Auditory/Left’, ‘Auditory/Right’, ‘Button’, ‘Smiley’, ‘Visual/Left’, ‘Visual/Right’]

event_id
{‘Auditory/Left’: 1,
‘Auditory/Right’: 2,
‘Button’: 3,
‘Smiley’: 4,
‘Visual/Left’: 5,
‘Visual/Right’: 6}

tmin = -0.3 
tmax = 0.5 
baseline = (None, 0) 
epochs = mne.Epochs(raw, 
                    events=events, 
                    event_id=event_id, 
                    tmin=tmin, 
                    tmax=tmax,
                    baseline=baseline, 
                    preload=True) 
epochs

Not setting metadata
Not setting metadata
320 matching events found
Setting baseline interval to [-0.2996928197375818, 0.0] sec
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Loading data for 320 events and 481 original time points …
0 bad epochs dropped

<Epochs | 320 events (all good), -0.299693 - 0.499488 sec, baseline [-0.299693, 0] sec, ~444.8 MB, data loaded,
‘Auditory/Left’: 72
‘Auditory/Right’: 73
‘Button’: 16
‘Smiley’: 15
‘Visual/Left’: 73
‘Visual/Right’: 71>

epochs.plot()
<MNEBrowseFigure size 1040x741 with 4 Axes>

Selecting epochs based on experimental conditions

epochs['Auditory/Right']
<Epochs | 73 events (all good), -0.299693 - 0.499488 sec, baseline [-0.299693, 0] sec, ~104.0 MB, data loaded,
‘Auditory/Right’: 73>

epochs['Auditory']
<Epochs | 145 events (all good), -0.299693 - 0.499488 sec, baseline [-0.299693, 0] sec, ~203.4 MB, data loaded,
‘Auditory/Left’: 72
‘Auditory/Right’: 73>

epochs['Left']
<Epochs | 145 events (all good), -0.299693 - 0.499488 sec, baseline [-0.299693, 0] sec, ~203.4 MB, data loaded,
‘Auditory/Left’: 72
‘Visual/Left’: 73>

epochs['Visual'].plot_image()
Not setting metadata
Not setting metadata
144 matching events found
No baseline correction applied
0 projection items activated
0 bad epochs dropped
Not setting metadata
Not setting metadata
144 matching events found
No baseline correction applied
0 projection items activated
0 bad epochs dropped
Not setting metadata
Not setting metadata
144 matching events found
No baseline correction applied
0 projection items activated
0 bad epochs dropped
combining channels using “gfp”
combining channels using “gfp”
combining channels using “gfp”