# Struggles applying the baseline

**URL:** https://mne.discourse.group/t/struggles-applying-the-baseline/3049
**Category:** Support & Discussions
**Tags:** epochs
**Created:** [April 27, 2021, 2:14pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049 "2021-04-27T14:14:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Nyorunn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/nyorunn/32/455_2.png) [@Nyorunn](https://mne.discourse.group/u/Nyorunn)
#### Post date: [April 27, 2021, 2:14pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/1 "2021-04-27T14:14:57Z")

</div>

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

```python
import pathlib
import matplotlib

import mne
import mne_bids

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

```

### here it works:

```python
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:

```python
<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

```python
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:

```python
<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?

---

<div class="post-metadata">

### Author: ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)
#### Post date: [April 27, 2021, 2:30pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/2 "2021-04-27T14:30:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Nyorunn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/nyorunn/32/455_2.png) [@Nyorunn](https://mne.discourse.group/u/Nyorunn)
#### Post date: [April 27, 2021, 3:19pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/3 "2021-04-27T15:19:38Z")

</div>

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 😕

---

<div class="post-metadata">

### Author: ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)
#### Post date: [April 27, 2021, 4:09pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/4 "2021-04-27T16:09:56Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)
#### Post date: [April 27, 2021, 6:11pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/5 "2021-04-27T18:11:04Z")

</div>

@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!

> [@Nyorunn](#):
>
> Your youtube workshop is awesome btw

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

---

<div class="post-metadata">

### Author: ![Nyorunn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/nyorunn/32/455_2.png) [@Nyorunn](https://mne.discourse.group/u/Nyorunn)
#### Post date: [April 28, 2021, 6:03am UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/6 "2021-04-28T06:03:48Z")

</div>

@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.

 ![Screenshot (218)](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/a44062630893e550240f3e1062240db9f5ee76b2.png)  
`epochs.average().plot()` shows the same time span as in the foto.

---

<div class="post-metadata">

### Author: ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)
#### Post date: [April 28, 2021, 12:37pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/7 "2021-04-28T12:37:38Z")

</div>

Hello,

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

---

<div class="post-metadata">

### Author: ![Nyorunn](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/nyorunn/32/455_2.png) [@Nyorunn](https://mne.discourse.group/u/Nyorunn)
#### Post date: [April 28, 2021, 2:05pm UTC](https://mne.discourse.group/t/struggles-applying-the-baseline/3049/8 "2021-04-28T14:05:11Z")

</div>

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

```python
import pathlib
import matplotlib

import mne
import mne_bids

matplotlib.use('Qt5Agg')

```

```python
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}

```python
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\>

 ![Screenshot (225)](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/09dca829dcb57dae71c2f3f8b082c658856fa9d4.png)

## 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”

 ![Screenshot (226)](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/fc242f7512c9e0819f583fb9d0a20418632ef3a7.jpeg)
