In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import pyrem as pr
import numpy as np
import pylab as pl
import pandas as pd


/home/quentin/.virtualenvs/pyrem/lib/python2.7/site-packages/pandas/io/excel.py:626: UserWarning: Installed openpyxl is not supported at this time. Use >=1.6.1 and <2.0.0.
  .format(openpyxl_compat.start_ver, openpyxl_compat.stop_ver))

In [3]:
data = pd.read_csv("/home/quentin/Desktop/mouseB.txt", engine="c", header=None, dtype=np.float32)
sig = pr.Signal(data,200)
to_remove =5 * int(sig.ntimepoints / 100.0)
sig = sig[to_remove: -to_remove]
print sig.duration
# sig = sig.resample(256)
print sig.duration
sig


1 day, 13:22:10.595000
1 day, 13:22:10.595000
/usr/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: 'module' object has no attribute 'get_facecolor'
  FormatterWarning,
Out[3]:
Signal([ (2.5204837322235107, -1.004422664642334, 1.0716506242752075, -0.4326341152191162),
       (3.469744920730591, -1.1875991821289062, 0.9196248650550842, -0.504472553730011),
       (2.995114326477051, -1.1914161443710327, 0.7899583578109741, -0.3320504426956177),
       ...,
       (0.09458082169294357, -1.0464001893997192, -0.6140303611755371, 0.4007721543312073),
       (0.09458082169294357, -1.0464001893997192, -0.6140303611755371, 0.343298077583313),
       (0.09458082169294357, -1.0464001893997192, -0.6140303611755371, 0.6450490355491638)], 
      dtype=[('c0', '<f8'), ('c1', '<f8'), ('c2', '<f8'), ('c3', '<f8')])

In [8]:
plot(sig[0:30000]["c3"])


Out[8]:
[<matplotlib.lines.Line2D at 0x7f89fab2e190>]

In [1]:
img = []

for c,s in sig.embed_seq(sig.sampling_freq * 200, sig.sampling_freq * 200 /2 ):

    ff_trans = np.fft.fft(s,  1024*8)
    freqs = np.fft.fftfreq(ff_trans.size, 1/sig.sampling_freq)
    power = np.abs(ff_trans)**2
    idx = np.argsort(freqs)

    out_powers = power[idx][freqs[idx] > 0]
    out_freqs = freqs[idx][freqs[idx] > 0]
    out_powers = out_powers / sum(out_powers)
    
    #print out_freqs[argmax(out_powers)]
    N = 1e5
    out_powers = np.round(out_powers * N).astype(np.int32)
    freqs_vec = []

    for  o,f in zip(out_powers, out_freqs):
        freqs_vec.extend([f] * o)
    n, bins = np.histogram(freqs_vec, sig.sampling_freq, range = (0,sig.sampling_freq))
    img.append(n)
    
    
img = np.array(img)
print img.shape
pl.imshow(np.log10(img+1).T[:,:])


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-1e450811533a> in <module>()
      1 img = []
      2 
----> 3 for c,s in sig.embed_seq(sig.sampling_freq * 200, sig.sampling_freq * 200 /2 ):
      4 
      5     ff_trans = np.fft.fft(s,  1024*8)

NameError: name 'sig' is not defined

In [12]:
pl.imshow(np.log10(img+1).T[0:50,:])


Out[12]:
<matplotlib.image.AxesImage at 0x7f06793beb90>

In [68]:
pl.figure()
print len(ff_trans)
out_powers = power[idx][freqs[idx] > 0]
out_freqs = freqs[idx][freqs[idx] > 0]
plot(out_freqs, out_powers)


65536
Out[68]:
[<matplotlib.lines.Line2D at 0x7f9f3b338290>]

In [53]:
ff_trans = np.fft.fft(sig[30000:90000])
freqs = np.fft.fftfreq(ff_trans.size, 1/sig.sampling_freq)

In [53]:


In [54]:
power = np.abs(ff_trans)**2

In [54]:


In [57]:
plot(out_freqs, np.log10(out_powers), '.')
print out_freqs[np.argmax(out_powers)]


0.0

In [ ]: