In [4]:
%pylab
import pandas as pd
from scipy.fftpack import *


Using matplotlib backend: Qt4Agg
Populating the interactive namespace from numpy and matplotlib

In [5]:
file = "D:\gingivere\data\Dog_1_interictal_segment_0001.h5"
store = pd.HDFStore(file)

In [6]:
store.keys()


Out[6]:
['/data']

In [7]:
data = store['data']

In [23]:
store.close()

In [24]:
# data.apply(rfft, axis=1)

In [25]:
def pl_power_spectrum(datum):
    plt.subplot(311)
    plt.plot(range(len(datum)), datum, 'r')
    xlabel("Time")
    F = rfft(datum)
    N = datum.shape[0]
    dt = 1/400
    w = rfftfreq(N, dt)
    plt.subplot(312)
    plt.plot(w, F, 'b-')
    ylabel("POWER")
    subplot(313)
    plot(w, F, 'b-')
    xlim([0, 50])          # replot but zoom in on freqs 0-50 Hz
    ylabel("POWER")
    xlabel("FREQUENCY (Hz)")
    plt.show()
    return w

In [26]:
def window_generator(datum):
    window_size = 400*60
    size = len(datum)
    i = 0
    while(i <= size):
        yield datum[i:i+window_size]
        i += int(window_size/2)

datum = data[:1].values[0]
windowed = np.asarray([x for x in window_generator(datum)])

In [27]:
windowed


Out[27]:
array([array([  0.,  13.,  15., ...,  11.,  28.,  27.]),
       array([ 18.,  17.,  22., ...,  14.,  21.,  26.]),
       array([ 15.,  -3., -10., ...,  32.,  20.,  27.]),
       array([ 27.,  27.,  25., ...,  63.,  64.,  55.]),
       array([ 31.,  22.,  21., ...,  11., -11., -43.]),
       array([ 45.,  29.,  13., ...,  17.,   2., -14.]),
       array([ -88., -114., -126., ...,   -6.,  -15.,  -19.]),
       array([-24., -32., -48., ...,  -4.,   0.,  29.]),
       array([-23., -20.,  -6., ..., -30.,  -9.,   1.]),
       array([ 65.,  82.,  83., ..., -10., -22., -21.]),
       array([ -6., -24., -30., ..., -13., -14.,  -4.]),
       array([-20., -21., -30., ..., -52., -45., -33.]),
       array([ -5.,   4.,   8., ...,   8.,  21.,  26.]),
       array([-20., -20., -17., ..., -23., -26., -28.]),
       array([ 22.,  23.,  23., ..., -13., -25., -25.]),
       array([-30., -28., -24., ..., -36., -36., -38.]),
       array([-19.,  -4.,   9., ..., -33., -43., -56.]),
       array([-43., -34., -19., ...,  23.,  12.,   4.]),
       array([-62., -52., -35., ..., -25., -21., -12.]),
       array([  0.,   3.,   6., ..., -25., -21., -12.])], dtype=object)

In [28]:
w


Out[28]:
array([  0.00000000e+00,   1.66666667e-02,   1.66666667e-02, ...,
         1.99983333e+02,   1.99983333e+02,   2.00000000e+02])

In [29]:
len(w)


Out[29]:
24000

In [30]:
def plot_all(data):
    num_rows = len(data)
    for i, row in enumerate(data):
        plt.subplot(num_rows, 1, i+1)
        plt.plot(range(len(row)), row, 'g')

In [31]:
plot_all(data.values)

In [35]:
data.values


Out[35]:
array([[  0.,  13.,  15., ..., -25., -21., -12.],
       [-26.,  -4.,  11., ..., -39., -32., -21.],
       [-42., -35., -19., ..., -16., -16., -18.],
       ..., 
       [ 45.,  30.,  25., ...,  43.,  28.,  17.],
       [ 15.,   8.,  -6., ...,  14.,  13.,   6.],
       [-18., -20., -19., ...,   9.,   9.,   3.]])

In [37]:
data.index


Out[37]:
Index(['NVC1202_32_002_Ecog_c001', 'NVC1202_32_002_Ecog_c002', 'NVC1202_32_002_Ecog_c003', 'NVC1202_32_002_Ecog_c004', 'NVC1202_32_002_Ecog_c005', 'NVC1202_32_002_Ecog_c006', 'NVC1202_32_002_Ecog_c007', 'NVC1202_32_002_Ecog_c008', 'NVC1202_32_002_Ecog_c009', 'NVC1202_32_002_Ecog_c010', 'NVC1202_32_002_Ecog_c011', 'NVC1202_32_002_Ecog_c012', 'NVC1202_32_002_Ecog_c013', 'NVC1202_32_002_Ecog_c014', 'NVC1202_32_002_Ecog_c015', 'NVC1202_32_002_Ecog_c016'], dtype='object')

In [ ]:
data