In [ ]:
import sys
sys.path.append('..')

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

In [3]:
from seizure.tasks import load_mat_data
import seizure.tasks
seizure.tasks.task_predict = True

In [9]:
itr = load_mat_data('../seizure-data','Dog_2','preictal')

In [10]:
for f in itr:
    for key in f.keys():
        if not key.startswith('_'):
            break
    #print f[key].dtype.fields.keys()
    print key,f[key]['data'][0][0].shape,f[key]['channels'][0][0].shape[1],
    for k in f[key].dtype.fields:
        if k != 'data' and k != 'channels':
            print k,f[key][k][0][0][0][0],
    print


preictal_segment_1 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_2 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_3 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_4 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_5 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_6 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_7 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_8 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_9 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_10 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_11 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_12 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_13 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_14 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_15 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_16 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_17 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_18 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_19 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_20 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_21 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_22 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_23 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_24 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_25 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_26 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_27 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_28 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_29 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_30 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_31 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_32 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_33 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_34 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_35 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_36 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6
preictal_segment_37 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 1
preictal_segment_38 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 2
preictal_segment_39 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 3
preictal_segment_40 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 4
preictal_segment_41 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 5
preictal_segment_42 (16, 239766) 16 data_length_sec 600 sampling_frequency 399.609756098 sequence 6

In [22]:
f[key]['sequence'][0,0][0,0]


Out[22]:
6

In [6]:
for f in load_mat_data('../seizure-data','Patient_2','preictal'):
    for key in f.keys():
        if not key.startswith('_'):
            break
    print ' '.join([str(v[0]) for v in f[key]['channels'][0][0][0].ravel()])


LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24
LTG_01 LTG_02 LTG_03 LTG_04 LTG_05 LTG_06 LTG_07 LTG_08 LTG_09 LTG_10 LTG_11 LTG_12 LTG_13 LTG_14 LTG_15 LTG_16 LTG_17 LTG_18 LTG_19 LTG_20 LTG_21 LTG_22 LTG_23 LTG_24

In [7]:
f[key]


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-7-861f93e132f0> in <module>()
----> 1 f[key]

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
    250             self.start_displayhook()
    251             self.write_output_prompt()
--> 252             format_dict, md_dict = self.compute_format_data(result)
    253             self.write_format_data(format_dict, md_dict)
    254             self.update_user_ns(result)

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    152 
    153         """
--> 154         return self.shell.display_formatter.format(result)
    155 
    156     def write_format_data(self, format_dict, md_dict=None):

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
    198             md = None
    199             try:
--> 200                 data = formatter(obj)
    201             except:
    202                 # FIXME: log the exception

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in warn_format_error(method, self, *args, **kwargs)
    231     """decorator for warning on failed format call"""
    232     try:
--> 233         r = method(self, *args, **kwargs)
    234     except NotImplementedError as e:
    235         # don't warn on NotImplementedErrors

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    685                 type_pprinters=self.type_printers,
    686                 deferred_pprinters=self.deferred_printers)
--> 687             printer.pretty(obj)
    688             printer.flush()
    689             return stream.getvalue()

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    441                             if callable(meth):
    442                                 return meth(obj, self, cycle)
--> 443             return _default_pprint(obj, self, cycle)
    444         finally:
    445             self.end_group()

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    561     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    562         # A user-provided repr. Find newlines and replace them with p.break_()
--> 563         output = _safe_repr(obj)
    564         for idx,output_line in enumerate(output.splitlines()):
    565             if idx:

/Users/udi/anaconda/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _safe_repr(obj)
    166     """Don't assume repr is not broken."""
    167     try:
--> 168         return repr(obj)
    169     except Exception as e:
    170         return _failed_repr(obj, e)

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/numeric.pyc in array_repr(arr, max_line_width, precision, suppress_small)
   1551     if arr.size > 0 or arr.shape==(0,):
   1552         lst = array2string(arr, max_line_width, precision, suppress_small,
-> 1553                            ', ', "array(")
   1554     else: # show zero-length shape unless it is (0,)
   1555         lst = "[], shape=%s" % (repr(arr.shape),)

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter)
    452     else:
    453         lst = _array2string(a, max_line_width, precision, suppress_small,
--> 454                             separator, prefix, formatter=formatter)
    455     return lst
    456 

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in _array2string(a, max_line_width, precision, suppress_small, separator, prefix, formatter)
    326     lst = _formatArray(a, format_function, len(a.shape), max_line_width,
    327                        next_line_prefix, separator,
--> 328                        _summaryEdgeItems, summary_insert)[:-1]
    329     return lst
    330 

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in _formatArray(a, format_function, rank, max_line_len, next_line_prefix, separator, edge_items, summary_insert)
    527         s += _formatArray(a[-1], format_function, rank-1, max_line_len,
    528                           " " + next_line_prefix, separator, edge_items,
--> 529                           summary_insert).rstrip()+']\n'
    530     return s
    531 

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in _formatArray(a, format_function, rank, max_line_len, next_line_prefix, separator, edge_items, summary_insert)
    498             s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)
    499 
--> 500         word = format_function(a[-1])
    501         s, line = _extendLine(s, line, word, max_line_len, next_line_prefix)
    502         s += line + "]\n"

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in repr_format(x)
    229 
    230 def repr_format(x):
--> 231     return repr(x)
    232 
    233 def _array2string(a, max_line_width, precision, suppress_small, separator=' ',

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/numeric.pyc in array_str(a, max_line_width, precision, suppress_small)
   1613 
   1614     """
-> 1615     return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
   1616 
   1617 def set_string_function(f, repr=True):

/Users/udi/anaconda/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter)
    446             if isinstance(x, tuple):
    447                 x = _convert_arrays(x)
--> 448             lst = style(x)
    449     elif reduce(product, a.shape) == 0:
    450         # treat as a null array if any of shape elements == 0

KeyboardInterrupt: 

In [10]:
400*600


Out[10]:
240000

In [14]:
from seizure.transforms import Resample
r = Resample(100)
data = np.sin(np.linspace(0.,2.*np.pi,500))
pl.plot(r.apply(data));



In [15]:
np.linspace(0.,2.,5)


Out[15]:
array([ 0. ,  0.5,  1. ,  1.5,  2. ])

In [17]:
239766 / 600.


Out[17]:
399.61

In [73]:
a = np.array([[[10,2,3],[4,5,6]],[[7,8,9],[2,11,12]],[[3,12,5],[2,11,12]],[[7,8,9],[2,11,12]]])

In [77]:
np.sort(a,axis=0)[0,:,:]


Out[77]:
array([[3, 2, 3],
       [2, 5, 6]])

In [ ]: