-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsplit_test_file.py
55 lines (40 loc) · 1.5 KB
/
split_test_file.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
import os
import pandas as pd
import numpy as np
step_size = 10
save_path = './new_tests'
df_x = pd.read_csv("./test_x/0001in.csv")
df_y = pd.read_csv("./test_y/0001out.csv")
def strided_axis0(a, L):
# Length of 3D output array along its axis=0
nd0 = a.shape[0] - L + 1
# Store shape and strides info
m, n = a.shape
s0, s1 = a.strides
# Finally use strides to get the 3D array view
return np.lib.stride_tricks.as_strided(a, shape=(nd0, L, n), strides=(s0, s0, s1))
if __name__ == '__main__':
results = []
for name, group in df_x.groupby('TurbID'):
x = group.values
x = strided_axis0(x, L=288)
inputs = x[::step_size]
outputs = x[288::step_size]
n = outputs.shape[0]
inputs = inputs[:n]
results.append([inputs, outputs])
results = np.transpose(np.array(results), axes=[2, 1, 0, 3, 4])
results = results.reshape(n, 2, -1, 13)
if not os.path.exists(save_path):
os.mkdir(save_path)
os.mkdir(os.path.join(save_path, 'test_x'))
os.mkdir(os.path.join(save_path, 'test_y'))
for i in range(n):
print('Saving', i)
test_x = results[i][0]
test_y = results[i][1]
test_x = pd.DataFrame(test_x, columns=df_x.columns)
test_y = pd.DataFrame(test_y, columns=df_y.columns)
test_x.to_csv(os.path.join(save_path, 'test_x', f"{i:04}in.csv"), index=False)
test_y.to_csv(os.path.join(save_path, 'test_y', f"{i:04}out.csv"), index=False)
print('done')