External Email - Use Caution
Dear Group,
The objective is to calculate the number of eye blink at each epoch.
One of the dirty workaround to achieve the objective is by using the module
find_eog_events on the continuous signal. Then, calculate the number of eye
blink event at each epoch, as shown in the code snippet below.
import numpy as np
import pandas as pd
filename = r'S17_3.mff'
raw = mne.io.read_raw_egi(filename, preload=True)
raw.crop(0, 595) # crop huge artifact at the end
time_secs = int(raw.times[-1])
montage = mne.channels.make_standard_montage('GSN-HydroCel-129')
montage.ch_names[-1] = 'E129'
raw.set_montage(montage, match_case=False)
raw.filter(1., 40.)
raw.resample(100, npad="auto")
raw.set_channel_types({'E15': 'eog'})
# Create epoch of 30s
event_id = 1 # This is used to identify the events.
duration = 30 # Divide continuous signal into an epoch of 30 seconds
events = mne.make_fixed_length_events(raw, event_id, duration=duration)
epochs = mne.Epochs(raw, events=events, event_id=event_id, baseline=None,
verbose=True, tmin=0, tmax=duration)
# Dirty workaround to find eog at each epoch
eog_events = mne.preprocessing.find_eog_events(raw)
## Obtain the time when the amplitude is the highest
df_time_high_peak = pd.DataFrame(np.vstack(eog_events[:, 0] /
raw.info['sfreq'] - 0.25))
## Set the beginning and end time of each epoch
duration_epoch = 30
total_epoch = round(time_secs / duration_epoch)
df_start_end = pd.DataFrame(
{'start': range(0, time_secs, duration_epoch), 'end':
range(duration_epoch, time_secs + 30, duration_epoch),
'epoch': range(0, total_epoch)})
rule_assign = pd.Series(df_start_end['epoch'].values,
pd.IntervalIndex.from_arrays(df_start_end['start'], df_start_end['end']))
df_time_high_peak['id'] = df_time_high_peak[0].map(rule_assign)
freq_blink_epoch = df_time_high_peak['id'].value_counts()
However, I am curious whether there is mne build-in module to find
eog_events by considering the epoch directly.
I am thinking something like
Eog_event=[ eog_events = mne.preprocessing.find_eog_events(epoch) for epoch
in epochs]
However, using such a line would produce an error of
TypeError: get_data() got an unexpected keyword argument
'reject_by_annotation'
Appreciate for tips about this.
Regards
Rodney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20200821/87243418/attachment-0001.html