-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_transformations.py
57 lines (48 loc) · 1.6 KB
/
data_transformations.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
57
import numpy as np
def meaner(array, window=20):
size = array.shape[0]
return np.hstack([np.mean(array[i:i + window]) for i in range(0, size, window)])
def scalling(array):
array = array.copy()
min_ = np.min(array)
array -= min_
max_ = np.max(array)
array /= max_
return array
def smoothing(row, win=5):
"""
Smooth given row in window with width = win.
"""
array = np.array(row).ravel()
new_array = np.empty(array.shape)
offset1 = win // 2
offset2 = win - offset1
array_size = len(array)
for i in range(array_size):
if i < offset1:
new_array[i] = np.mean(array[:i + offset2])
elif i > array_size - offset2:
new_array[i] = np.mean(array[i - offset1:])
else:
new_array[i] = np.mean(array[i - offset1:i + offset2])
return new_array
def reduce_point_number(array: np.array, window: int, shift: int = None) -> np.array:
"""This function reduce the number of points in the scaling maner.
Cause of that, needed information may be lost.
Input: array : 1-D np.array to convert
window : int
shift : int
Returns: 1-D np.array
Comment: shape = window * steps"""
data = array.copy()
data = data.ravel()
if shift:
if shift >= window:
raise Exception("Shift must be less than window")
else:
shift = 0
steps = data.shape[0] // window # aka number of points to return
to_return = np.empty((steps,))
for i in range(steps):
to_return[i] = data[i * window + shift]
return to_return