In [1]:
import mne
import sqlite3
%pylab inline
mne.set_log_level('WARNING')
In [2]:
#raw = mne.io.read_raw_brainvision('/Volumes/Store/Avner/POUYAN-BRAIN/pouyan.vhdr')
#raw = mne.io.read_raw_brainvision('/home/avnerus/Code/eegtest/EEG/test2.vhdr')
#raw = mne.io.read_raw_eeglab('/home/avnerus/Code/eegtest/MATTI/matti_rs_cl_fl.set')
#raw = mne.io.read_raw_brainvision('/Volumes/Store/Avner/MATTI-BRAIN/matti.vhdr')
raw = mne.io.read_raw_eeglab('/Volumes/Store/Avner/MATTI-BRAIN/matti_rs_cl_fl.set')
print(raw.info)
In [3]:
print((raw.ch_names))
In [5]:
events = mne.find_events(raw)
In [4]:
print (events)
In [4]:
# Pick the centro-parietal channels
raw.preload = True
centro_parietal_channels = ['C3','Cz','C4','CP1','CP2','CP5','CP6','P3','Pz','P4']
specific_chans = raw.pick_channels(centro_parietal_channels, copy=True)
print(specific_chans)
In [5]:
first_event_sec = specific_chans.times[36118]
last_event_sec = specific_chans.times[1613461]
print("Experiment times %f --> %f" % (first_event_sec, last_event_sec))
In [6]:
start, stop = specific_chans.time_as_index([first_event_sec,last_event_sec])
print(start,stop)
In [12]:
#last_event_sec = specific_chans.times[1490754]
#FIRST INDEX WORK AROUND
#pouyan_sec = 48 * 60 + 30.16
#first_event_sec = last_event_sec - pouyan_sec
#print("Total Pouyan time: %f" % (pouyan_sec))
#pouyan_start = indexes[0] - pouyanMs
#first_event_sec = 72.235800
#last_event_sec = 3226.920800
#start, stop = specific_chans.time_as_index([first_event_sec,last_event_sec])
start = events[0][0]
stop = events[1][0]
print(start,stop)
In [7]:
specific_chans = specific_chans.load_data()
specific_chans.preload = False
data, times = specific_chans[:, start:stop]
print(specific_chans)
In [8]:
print(len(data[0]))
In [9]:
def get_lpp(index):
first_index = int(index + raw.info['sfreq'] * 0.4)
last_index = int(index + raw.info['sfreq'] * 0.7)
if last_index < len(data[0]):
#print("Will get maximum value between index %d and %d" % (first_index, last_index))
max_amplitude = data[:,first_index:last_index + 1].sum(axis=0).max()
present_value = data[:,index].sum()
lpp = max_amplitude - present_value
return lpp
else:
return 0
lpp_values = []
for i in range(len(data[0])):
lpp_values.append(get_lpp(i))
In [10]:
plt.rcParams["figure.figsize"] = [20.0,8.0]
#%pylab qt
a = hist(lpp_values, bins=500)
In [1]:
print(a[1][174])
In [12]:
conn = sqlite3.connect('matti_eeg.db')
c = conn.cursor()
In [13]:
# Create table
c.execute('''CREATE TABLE data
(
id INTEGER PRIMARY KEY ASC,
channel0 real,
channel1 real,
channel2 real,
channel3 real,
channel4 real,
channel5 real,
channel6 real,
channel7 real,
channel8 real,
channel9 real,
lpp real)''')
Out[13]:
In [14]:
channels = []
for value_index in range(len(data[0])):
all_channels = []
all_channels.append(value_index)
for channel_index in range(10):
all_channels.append(data[channel_index][value_index])
all_channels.append(lpp_values[value_index])
channels.append(tuple(all_channels))
#channel0 = map(lambda x: (0,x), data[0])
In [15]:
#print(data[1][1])
In [16]:
c.executemany('INSERT INTO data VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', channels)
Out[16]:
In [17]:
conn.commit()
conn.close()
In [ ]: