In [21]:
%matplotlib inline
from matplotlib import pylab as pl
import cPickle as pickle
import pandas as pd
import numpy as np
import os
import random

In [17]:
import sys
sys.path.append('..')
import seizure.tasks
seizure.tasks.task_predict = True

from seizure.tasks import load_mat_data, count_mat_data
data_dir='../filtered-seizure-data'

In [6]:
from IPython.parallel import Client
while Ncores < 8:
    !sleep 10
    try:
        client = Client()
        lv = client.load_balanced_view()
        #lv.set_flags(block = False, retries = 0)
        clients=client[:]
        Ncores = len(clients)
    except:
        Ncores = 0


Out[6]:
8

In [7]:
%%px
import numpy as np
import sys
sys.path.append('..')
import seizure.tasks
seizure.tasks.task_predict = True

from seizure.tasks import load_mat_data, count_mat_data
data_dir='../filtered-seizure-data'

In [8]:
def work(task):
    target = task[0]
    data_type = task[1]
    mat_data = load_mat_data(data_dir, target, data_type)
    c = 0
    v = None
    for segment in mat_data:
        for key in segment.keys():
            if not key.startswith('_'):
                break
        data = segment[key]['data'][0,0]
        c += data.shape[1]
        if v is None:
            v = np.sum(data*data, axis=1)
        else:
            v += np.sum(data*data, axis=1)
    return (target, data_type, c, np.sqrt(v/c).astype(int))

In [9]:
data_types = ['preictal', 'interictal', 'test']
targets = ['Dog_1', 'Dog_2', 'Dog_3', 'Dog_4', 'Dog_5', 'Patient_1', 'Patient_2']

In [10]:
results = lv.map(work, [(t,d) for t in targets for d in data_types])

In [11]:
for r in results:
    print r


('Dog_1', 'preictal', 5754384, array([33, 30, 21, 23, 32, 17, 16, 16, 26, 18, 15, 18, 20, 18, 16, 20]))
('Dog_1', 'interictal', 115087680, array([31, 28, 20, 22, 43, 16, 16, 18, 25, 18, 18, 17, 21, 19, 21, 20]))
('Dog_1', 'test', 120362532, array([36, 34, 22, 24, 27, 19, 18, 19, 27, 19, 16, 18, 22, 19, 18, 21]))
('Dog_2', 'preictal', 10070172, array([23, 28, 23, 24, 20, 17, 15, 19, 16, 16, 19, 17, 15, 15, 23, 19]))
('Dog_2', 'interictal', 119883000, array([28, 31, 28, 27, 22, 22, 22, 30, 25, 17, 24, 20, 19, 18, 26, 25]))
('Dog_2', 'test', 239766000, array([29, 34, 28, 27, 24, 23, 21, 29, 19, 20, 22, 19, 18, 18, 25, 24]))
('Dog_3', 'preictal', 17263152, array([30, 27, 29, 24, 39, 38, 32, 30, 38, 29, 27, 26, 35, 33, 31, 33]))
('Dog_3', 'interictal', 345263040, array([33, 29, 27, 26, 46, 39, 37, 32, 46, 31, 30, 29, 40, 39, 33, 39]))
('Dog_3', 'test', 217467762, array([27, 20, 18, 23, 22, 24, 22, 24, 17, 17, 13, 15, 21, 28, 23, 26]))
('Dog_4', 'preictal', 23257302, array([ 97,  81,  96,  98,  92,  78, 102, 115,  78,  67,  73,  91,  96,
        72,  89, 110]))
('Dog_4', 'interictal', 192771864, array([113,  93, 108, 113, 110,  90, 111, 128,  91,  80,  84, 103, 115,
        85, 103, 119]))
('Dog_4', 'test', 237368340, array([120,  94, 113, 125, 116,  96, 113, 142,  96,  86,  94, 117, 131,
        91, 104, 128]))
('Dog_5', 'preictal', 7192980, array([30, 36, 27, 34, 27, 28, 26, 31, 30, 39, 29, 30, 27, 29, 30]))
('Dog_5', 'interictal', 107894700, array([34, 35, 34, 37, 35, 36, 37, 36, 28, 39, 33, 39, 34, 34, 35]))
('Dog_5', 'test', 45795306, array([140,  71,  57,  59,  65,  63,  80,  74,  60,  62,  60,  63,  66,
        59, 324]))
('Patient_1', 'preictal', 4315788, array([5652, 5556, 5640, 5506, 5588, 5546, 5520, 5246, 5245, 5222, 5225,
       5238, 5222, 5250, 5247]))
('Patient_1', 'interictal', 11988300, array([162, 339, 267, 713, 586, 619, 548, 343, 342, 575, 567, 728, 681,
       840, 416]))
('Patient_1', 'test', 46754370, array([1011, 1314, 1373, 1216, 1217, 1244, 1245, 1586, 1532, 1401, 1406,
       1436, 1287, 1364, 1497]))
('Patient_2', 'preictal', 4315788, array([351, 358, 355, 321, 319, 314, 318, 314, 334, 335, 332, 354, 337,
       334, 314, 317, 316, 315, 338, 341, 320, 323, 312, 316]))
('Patient_2', 'interictal', 10070172, array([217, 234, 241, 181, 166, 159, 155, 154, 224, 201, 241, 212, 200,
       203, 166, 152, 165, 162, 187, 201, 169, 167, 155, 151]))
('Patient_2', 'test', 35964900, array([ 509,  510,  492,  560,  575,  558,  526,  517,  698,  707,  684,
       2115, 2602,  710,  700,  682,  684, 2740, 3602, 2306, 1193,  703,
        684,  669]))

In [13]:
def show(task):
    target = task[0]
    data_type = task[1]
    mat_data = load_mat_data(data_dir, target, data_type)
    v = []
    for segment in mat_data:
        for key in segment.keys():
            if not key.startswith('_'):
                break
        data = segment[key]['data'][0,0]
        v.append(np.mean(data*data, axis=1))
    return np.array(v)

In [27]:
p = show(('Patient_2', 'preictal'))

In [29]:
p.shape


Out[29]:
(18, 24)

In [28]:
n = show(('Patient_2', 'interictal'))

In [30]:
n.shape


Out[30]:
(42, 24)

In [18]:
t = show(('Patient_2', 'test'))

In [19]:
t.shape


Out[19]:
(150, 24)

In [31]:
pl.imshow(np.log(p.T))


Out[31]:
<matplotlib.image.AxesImage at 0x117faf290>

In [47]:
p.T[:,0]


Out[47]:
array([ 132334.09319614,  136523.22716347,  144632.61821325,
        112193.54692027,  109946.49408476,  107728.82723203,
        107215.31893018,  106043.85837203,  118023.03439789,
        119168.36620483,  117846.51296863,  118990.58551008,
        121611.29328359,  119236.29338047,  107251.30906783,
        108325.60651226,  107042.20451789,  107942.29934768,
        123163.6694901 ,  127106.61289095,  110715.22108387,
        112171.82636525,  105601.48180095,  105211.18206958])

In [32]:
pl.imshow(np.log(n.T))


Out[32]:
<matplotlib.image.AxesImage at 0x119549650>

In [25]:
pl.imshow(np.log(t.T))


Out[25]:
<matplotlib.image.AxesImage at 0x115302910>

In [26]:
t=s

In [ ]: