Exemplo n.º 1
0
 def test_classic_sta_lta_c_python(self):
     """
     Test case for ctypes version of recursive_sta_lta
     """
     nsta, nlta = 5, 10
     c1 = classic_sta_lta(self.data, nsta, nlta)
     c2 = classic_sta_lta_py(self.data, nsta, nlta)
     self.assertTrue(np.allclose(c1, c2, rtol=1e-10))
     ref = np.array([0.38012302, 0.37704431, 0.47674533, 0.67992292])
     self.assertTrue(np.allclose(ref, c2[99:103]))
Exemplo n.º 2
0
trace.normalize()
trace.plot()

samp_rate = trace.stats.sampling_rate
N = int(samp_rate)

df = pd.DataFrame(trace.data)
# df = pd.DataFrame(np.random.randn(35000))

CMA = df.rolling(N, center=True).mean()
CMA = normalized(CMA)

POW = df.rolling(N, center=True).apply(lambda x: (x**2).mean())
POW = normalized(POW)

STALTA = classic_sta_lta_py(df, int(5 * samp_rate), int(10 * samp_rate))
STALTA = pd.DataFrame(STALTA)
STALTA = normalized(STALTA)

idx = range(len(df))

X = pd.concat([CMA, POW, STALTA], axis=1)
X = X.dropna()
kmeans_fit = cluster.KMeans(n_clusters=3).fit(X)
cluster_labels = kmeans_fit.labels_

fig = plt.figure()
ax = plt.axes(projection="3d")
ax.scatter(CMA,
           POW,
           STALTA,