Stimic - Analysis - Artifact Carac

jeu. 08 novembre 2018 by Martin Deudon

Download the notebook : stimic_artefact_carac.py

Caracterization of the stimulation artefact

In [1]:
%matplotlib inline
import mne
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sys
import seaborn as sns
sys.path.append('../stimic_main/')
import utils_stimic
import utils_eeg_cleaning
from stim_analysis_fun import *
sns.set()
sns.set_context('paper')
plt.rcParams['figure.figsize'] = (14, 14)

Set the path of the epoch and stim event list :

In [2]:
stim_epoch_path = r'C:\\Users\\deudon\\Desktop\\Stimic\\_Data\\STIMS\\P53_CD25\\P53_CD25_stim_mne_epoch-resync-epo.fif'
stim_spreadsheet_path = r'C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53_CD25\p53_CD25_stimulations_all.xlsx'

Read mne epoch structure :

In [3]:
stim_epoch = mne.read_epochs(stim_epoch_path)
print(stim_epoch)
Reading C:\\Users\\deudon\\Desktop\\Stimic\\_Data\\STIMS\\P53_CD25\\P53_CD25_stim_mne_epoch-resync-epo.fif ...
Isotrak not found
    Found the data of interest:
        t =   -5000.00 ...   24998.05 ms
        0 CTF compensation matrices available
182 matching events found
182 matching events found
0 projection items activated
<EpochsFIF  |  n_events : 182 (all good), tmin : -5.0 (s), tmax : 24.998046875 (s), baseline : None, ~2.44 GB, data loaded>

Load stim spreadsheet :

In [4]:
df = pd.read_excel(stim_spreadsheet_path)
df.head()
Out[4]:
ID file type time channelind channelname freq intensity duration effect channelname_bipolar time-micro channelname-micro channelind-micro filepath-micro
0 P53_CD25 CD25_stim1_clean_clean_raw Stim 1 Hz 174.4736 96 EEG GC1 1 1.5 10 RAS EEG GC1-EEG GC2 217.1523 [] [] C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53...
1 P53_CD25 CD25_stim1_clean_clean_raw Stim 1 Hz 174.4834 97 EEG GC2 1 1.5 10 RAS EEG GC1-EEG GC2 217.1621 [] [] C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53...
2 P53_CD25 CD25_stim1_clean_clean_raw Stim 1 Hz 234.5498 97 EEG GC2 1 2.0 10 RAS EEG GC2-EEG GC3 277.2285 [] [] C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53...
3 P53_CD25 CD25_stim1_clean_clean_raw Stim 1 Hz 234.5566 98 EEG GC3 1 2.0 10 RAS EEG GC2-EEG GC3 277.2353 [] [] C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53...
4 P53_CD25 CD25_stim1_clean_clean_raw Stim 1 Hz 274.1533 98 EEG GC3 1 3.0 20 RAS EEG GC3-EEG GC4 316.8320 [] [] C:\Users\deudon\Desktop\Stimic\_Data\STIMS\P53...

Plot the mean artefact for 1Hz stimulation :

We will use the plot_mean_artefact function.

The first two arguments are respectively the MNE epoch structure containing the stimulation data and the pandas DataFrame df listing all the stimulations.

The 3rd argument is optional, if specified it must be a column name (key) of the df dataframe. It will separate the different conditions, and plot each one of them is a different color.

The function can be called with optionnal selection arguments which must be column names of the stimulation data frame df. For instance :

  • plot_mean_artefact(stim_epoch, df, 1freq=1) will select only the 1Hz stimulations
  • plot_mean_artefact(stim_epoch, df, 1, freq=1, intensity=1.5) will select only the 1Hz stimulations at 1.5 mA intensity
  • plot_artefact_ev_with_electrode_distance(stim_epoch, df, 1, freq=50, channelname='EEG A3') will select the 50Hz stimulation located in EEG A3
In [5]:
plot_mean_artefact(stim_epoch, df, color_by='intensity', freq=1)

See the effect of intensity on the shape of the 50Hz stimulation artifact :

In [9]:
plot_mean_artefact(stim_epoch, df, plot_traces=0, freq=50, color_by='intensity')