-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
36 lines (27 loc) · 1.09 KB
/
utils.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
from scipy.signal import resample
import numpy as np
def resampling(inp, window_size, sampling_rate=50):
"""
Return an array with the same structure but the data is now sampled with the chosen rate.
"""
samples_per_window = sampling_rate * window_size
resampled = [[resample(window, samples_per_window)
for window in patient] for patient in inp]
return resampled
def check_dimension(inp, window_size, sampling_rate=50):
"""
Boolean. Check whether the array is correctly preprocessed.
"""
samples_per_window = sampling_rate * window_size
return all(window.shape == (samples_per_window, ) for patient in inp for window in patient)
def stack(inp, mode="vstack"):
"""
Stack the array to make the dimension to 3D (# windows, # data points, 1)
where # data points = samples_per_window. The input should be resampled beforehand.
"""
_stack = getattr(np, mode)
if mode == "vstack":
return _stack(inp).reshape(-1, np.shape(inp[0][0])[0], 1)
if mode == "hstack":
return _stack(inp).reshape(-1, 1)
raise KeyError