-
Notifications
You must be signed in to change notification settings - Fork 142
/
timeseries_slicer.py
44 lines (39 loc) · 1.19 KB
/
timeseries_slicer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import numpy as np
import analyze_stats
import matplotlib.pyplot as plt
def slice_timeseries(x, l=128, d=64, max_k = None):
k = (len(x) - l + 1) / d
if not max_k == None:
k = min(k, max_k)
X = np.zeros([k,2,l], dtype=np.float32)
for i in range(0,k):
# Rect Window
w = np.ones([l])
# Sin Window
#w = np.sin(np.arange(0,np.pi,np.pi/l))
x_i = x[i*d:i*d+l] * w
X[i,0,:] = np.real(x_i)
X[i,1,:] = np.imag(x_i)
energy = analyze_stats.calc_vec_energy(X[i])
X[i,0,:] /= energy
X[i,1,:] /= energy
return X
def slice_timeseries_dict(td, l=128, d=64, max_k = None):
nd = {}
for k,v in td.iteritems():
nd[k] = slice_timeseries(v,l,d,max_k)
return nd
def slice_timeseries_real(x, l=128, d=64, max_k = None):
k = (len(x) - l + 1) / d
if not max_k == None:
k = max(k, max_k)
X = np.zeros([k,1,l], dtype=np.float32)
for i in range(0,k):
x_i = x[i*d:i*d+l]
X[i,0,:] = x_i
return X
def slice_timeseries_real_dict(td, l=128, d=64, max_k = None):
nd = {}
for k,v in td.iteritems():
nd[k] = slice_timeseries_real(v,l,d,max_k)
return nd