In [1]:
%matplotlib inline
from matplotlib import pylab as pl
import cPickle as pickle
import pandas as pd
import numpy as np
import os
import random
www.ieeg.org follow videos https://www.youtube.com/watch?v=Q0jSTaWQtMs and https://www.youtube.com/watch?v=GvfnSY5tk2Y for setting up an account
search for Dog EEG
found 7 cases but only 3 are annotated I004_A0001_D001, I004_A0002_D002 and I004_A0003_D001
In [2]:
!ls -l ~/Downloads/I004_A0001_D001.csv
In [3]:
!wc -l ~/Downloads/I004_A0001_D001-annotiations.csv
In [4]:
!head ~/Downloads/I004_A0001_D001-annotiations.csv
In [10]:
!cut -d, -f2 ~/Downloads/I004_A0001_D001-annotiations.csv | sort -n -u | wc -l
In [11]:
!cut -d, -f2 ~/Downloads/I004_A0001_D001-annotiations.csv | sort -n -u
use the Annot. buttons at the bottom to jump to next seizure
First seizure 12:20:24.341709
In [17]:
(((12*60) + 20)*60+24.341709)*1000000
Out[17]:
In [ ]:
which match exactly the CSV file
In [18]:
44424340820 - _
Out[18]:
end time is seizure start
In [19]:
44424340820/1000000
Out[19]:
width (in seconds)
In [22]:
70*60
Out[22]:
start time is 1:10:00 before that (in seconds)
In [23]:
44424340820/1000000 - 4200
Out[23]:
enter value at the tool bar in the "Start (s)" and "Width (s)" text box. Make sure you erase any previous values you had in does boxes
use the hamburger icon in the toolbar to download CSV
In [2]:
Fs=399.61
In [26]:
!wc -l ~/Downloads/I004_A0001_D001.csv
it looks like first ine is header and then each channel is in a single line
In [4]:
!head -n 1 ~/Downloads/I004_A0001_D001.csv
In [8]:
!head -n 2 ~/Downloads/I004_A0001_D001.csv | tail -n 1 | dd count=1
Number of channels in each line
In [3]:
ieegdata = []
with open('/Users/udi/Downloads/I004_A0001_D001.csv') as fp:
fp.next()
for l in fp:
l = l.split(',')
N = len(l)-4
print l[0],l[1],l[2],l[3],N,N/Fs
ieegdata.append(map(int,l[4:]))
ieegdata = np.array(ieegdata)
In [4]:
ieegdata.shape
Out[4]:
In [5]:
data_type = 'preictal' # preictal interictal test
In [6]:
import scipy.io
import scipy.signal
for target in ['Dog_1', 'Dog_2', 'Dog_3', 'Dog_4', 'Dog_5']:
segment = 1 # start segment
all_data = last_sequence = last_data_length_sec = last_Fs = last_channels = last_d_shape = None
while True:
fname = '../seizure-data/%s/%s_%s_segment_%04d.mat'%(target,target,data_type,segment)
try:
data = scipy.io.loadmat(fname)
except:
break
k = '%s_segment_%d'%(data_type,segment)
# for k1 in data.keys():
# if k1 != k:
# print data[k1],
# print
data_length_sec = data[k]['data_length_sec'][0,0][0,0]
sequence = data[k]['sequence'][0,0][0,0]
Fs = float(data[k]['sampling_frequency'][0,0][0,0])
channels = [t[0] for t in data[k]['channels'][0,0][0]]
d = data[k]['data'][0,0]
assert len(channels) == d.shape[0]
assert int(Fs*data_length_sec + 0.5) == d.shape[1],int(Fs*data_length_sec + 0.5)
assert last_data_length_sec is None or last_data_length_sec == data_length_sec
last_data_length_sec = data_length_sec
assert last_Fs is None or last_Fs == Fs
last_Fs = Fs
assert last_channels is None or all(c1==c2 for c1,c2 in zip(last_channels, channels))
last_channels = channels
assert last_d_shape is None or last_d_shape == d.shape
last_d_shape = d.shape
if sequence == 3:
print target, channels[0]
for ieegchan in ieegdata:
c = scipy.signal.fftconvolve(ieegchan,d[0,::-1],mode='valid')
score = (c.max()-c.mean())/c.std()
if score > 10:
print target,score
last_sequence = sequence
segment += 1
# print data_length_sec, sequence, Fs, d.shape
In [ ]: