-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessing.py
100 lines (84 loc) · 3.99 KB
/
preprocessing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import numpy as np
import os , sys , glob
#ep-ap error
def get_trainingData(folder_path , seq_length=7 , seq_width=3 ,save_is=True):
debug_flag = True
debug_flag_lv1 = True
debug_flag_lv2 = False
if __debug__ == debug_flag:
print '### debug | preprocessing.py | get_trainingData ###'
print 'hidden param state: seq_length=',seq_length,'save_is=',save_is
print 'folder path=',folder_path
#type(ep).__moduel__ == __name__.np
leafs = np.load(os.path.join(folder_path,'leaf.npy'))
heads = np.load(os.path.join(folder_path, 'head.npy'))
n_length , n_leaf , n_param = np.shape(leafs)
head_height, head_width= np.shape(heads)
print 'leafs shape : n_length: {} n_leaf: {} n_param :{} '.format(n_length , n_leaf , n_param) # ( 1489 60 4 )
print 'header shape : head height : {} head width : {}'.format(head_height, head_width) # ( 1489 14 )
ep_ = leafs[:,:,0]#1489 60
ap_ = leafs[:,:,1]#1489 60
x_data=np.zeros([n_length-seq_length-1 , n_leaf-seq_width+1 , seq_length , seq_width])
x_BCG_data=np.zeros([n_length-seq_length-1 , n_leaf-seq_width+1 , seq_length , seq_width+3]) # +3 --> BeamOfOff , Colimator , Gantry
y_data=np.zeros([n_length-seq_length-1 , n_leaf-seq_width+1])
y1_data = np.zeros([n_length - seq_length - 1, n_leaf - seq_width + 1])
for r in range(n_length-seq_length-1):
x=ep_[r:r+seq_length] #(7,60)
y=ap_[r+seq_length] #(7,60)
y1= ap_[r + seq_length-1] #(7,60)
head_x=heads[r:r+seq_length]
for c in range(n_leaf-seq_width+1):
x_data[r, c,:,:]=x[:,c:c+seq_width]
x_BCG_data[r,c,:,:seq_width]=x[:,c:c+seq_width]
x_BCG_data[r, c, :, seq_width :]
x_BCG_data[r, c, :, seq_width:seq_width + 1] = head_x[:, 3:4] # BeamOfOff
x_BCG_data[r, c, :, seq_width+1:seq_width + 2] = head_x[:, 6:7] #Colimator
x_BCG_data[r, c, :, seq_width + 2:seq_width + 3] = head_x[:, 7:8] #Gantry
y_data[r,c]=y[c+1] #
y1_data[r, c] = y1[c + 1]#
"""
seq_width=3
________
1 |1 2 3 | |
2 |4 5 6 | |
3 |7 8 9 | |
4 |10 11 12| seq_length = 7
4 |13 14 15| |
4 |16 17 18| |
4 |19 20 21| |
4 |22 23 24| <--y_1 | exactly we want to know c+1 porin at y_1
5 |________|
6 c c+1 c+2 <-- y | exactly we want to know c+1 point at y
** if you want to chang seq_width , you should change [c + 1 ]
"""
print 'x with B C G data shape : {} '.format(np.shape(x_BCG_data))
#print x_BCG_data[0, 0, :, 3]
#print x_BCG_data[1, 0, :, 3]
#print x_BCG_data[0, 1, :, 3]
#print heads[:14, 3:4]
np.save(os.path.join(folder_path, 'x_data_BCG.npy'), x_BCG_data)
np.save(os.path.join(folder_path ,'x_data.npy'), x_data)
np.save(os.path.join(folder_path, 'y_data.npy'), y_data)
np.save(os.path.join(folder_path, 'y1_data.npy'), y1_data)
assert len(x_data) == len(y_data) == len(y1_data)
if __debug__ == debug_flag_lv1:
print 'x_data , and y_data was saved'
if __debug__ == debug_flag_lv2:
print 'x data length :,',np.shape(x_data)
print 'y data length :,',np.shape(y_data)
print 'y1 data length :,', np.shape(y1_data)
print 'leaf shape :',np.shape(leafs)
print 'ap shape :', np.shape(ep_)
print 'ep shape :', np.shape(ap_)
print '###check###'
print 'y1 sample data : ',y1_data[0]
print 'y sample data : ', y_data[0]
print 'x sample data : ',x_data[0]
return x_data , y_data , y1_data
if __name__ =='__main__':
root_dir='./divided_log'
path, subfolders , files=os.walk(root_dir).next()
print '# subfolders ' , len(subfolders)
for subfolder in subfolders:
target_folder_path=os.path.join('./divided_log' , subfolder)
x_data , y_data, y1_data = get_trainingData(target_folder_path)