-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_test.py
56 lines (43 loc) · 1.72 KB
/
class_test.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
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import matplotlib.pyplot as plt
from lib.math import resample_timeseries
def generate_fake_tracks(savename):
"""The nth class will always be no signal"""
data = []
for cls in ["a", "b", "c"]:
for i in range(1000):
if cls == "a":
clath = [1, 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 6, 5, 4, 2, 1]
auxln = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 2, 1, 1, 1]
elif cls == "b":
clath = np.flip([1, 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 6, 5, 4, 2, 1])
auxln = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 2, 1, 1, 1]
elif cls == "c":
clath = [1, 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 6, 5, 4, 2, 1]
auxln = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
else:
raise ValueError
x = np.column_stack((clath, auxln))
# initial length
length = np.random.randint(50, 150)
x = resample_timeseries(x, new_length=length)
noise = np.random.normal(1, 0.2, len(x))
# Add noise
x[:, 0] *= noise
x[:, 1] *= noise
# Add intensities
x[:, 0] *= np.random.uniform(300, 900)
x[:, 1] *= np.random.uniform(300, 600)
data.append(x)
data = np.array(data)
np.savez("data/preprocessed/{}.npz".format(savename), data=data)
return data
def main(savename):
data = generate_fake_tracks(savename = savename)
fig, ax = plt.subplots(nrows=4, ncols=4)
ax = ax.ravel()
for i in range(len(ax)):
ax[i].plot(data[i])
plt.show()
if __name__ == "__main__":
main(savename = "3classtraces")