-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProceRawDataVelocity.py
More file actions
183 lines (122 loc) · 5.1 KB
/
ProceRawDataVelocity.py
File metadata and controls
183 lines (122 loc) · 5.1 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import os
import json
import csv
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
Work_Path = "F:\\PlantarPressurePredictExperiment"
os.chdir(Work_Path)
def getDic():
with open("subjectConfig.json", "r",encoding= "utf-8") as f:
subjectConfigDict = json.load(f)
return subjectConfigDict
def GetKeyPoint(dic,subject,item,step):
HC = dic[subject]["ResultData"][item][step].split(",")[0]
SC = dic[subject]["ResultData"][item]["{0}SCValue".format(step)].split("_")[0]
HL = dic[subject]["ResultData"][item]["{0}HLValue".format(step)].split("_")[0]
TO = dic[subject]["ResultData"][item][step].split(",")[1]
return int(HC),int(SC),int(HL),int(TO)
def GetVelocityArr(subject,detailItemName,eachStep,HC,SC,HL,TO):
file = "1"
if(eachStep == "BTS" or eachStep == "TS"):
file = open("ProcessedData\\subject{0}\\{1}-L.csv".format(subject,detailItemName),encoding="utf-8")
elif(eachStep == "BAP" or eachStep == "AP" or eachStep == "DS"):
file = open("ProcessedData\\subject{0}\\{1}-R.csv".format(subject,detailItemName),encoding="utf-8")
else:
print("Error",subject,detailItemName)
Arr = np.loadtxt(file,delimiter = ",")
HCVelocityArr = Arr[HC-1:SC-1,:] - Arr[HC-2:SC-2,:]
MSVelocityArr = Arr[SC:HL-1,:] - Arr[SC - 1:HL-2,:]
TOVelocityArr = Arr[HL:TO-1,:] - Arr[HL - 1:TO- 2,:]
file.close()
return HCVelocityArr,MSVelocityArr,TOVelocityArr
def GetLabel(dic,subjectName,detailItemName):
angle = dic[subjectName]["ResultData"][detailItemName]["angle"]
strategy = dic[subjectName]["ResultData"][detailItemName]["strategy"]
return angle,strategy
def GetFileIterator(dic):
for subject in subjects:
for item in items:
for sub_item in sub_items:
detailItemName = "{0}-{1}".format(item, sub_item)
subjectName = "subject{}".format(subject)
if (dic[subjectName]["ResultData"].__contains__(detailItemName)):
for eachStep in Step:
HC, SC, HL, TO = GetKeyPoint(dic, subjectName, detailItemName, eachStep)
HCVelocityArr, MSVelocityArr, TOVelocityArr = GetVelocityArr(subject, detailItemName, eachStep, HC, SC, HL, TO)
angle,strategy = GetLabel(dic,subjectName,detailItemName)
#if(angle != "0°") : continue #不要30°和120°变化
for k in range(len(TOVelocityArr)):
#yield subjectName,detailItemName,angle,strategy,eachStep,HCArr,MSArr,TOArr
yield subjectName, detailItemName, angle, strategy, eachStep,TOVelocityArr[k]
print(subjectName,"---",detailItemName)
def switchLabelClass(label):
if label == 0:
return 0
if label ==30:
return 1
if label ==60:
return 2
if label == 90:
return 3
if label == 120:
return 4
#标准化
def normalization(Arr):
mean = Arr.mean()
std = Arr.std()
Arr = (Arr - mean) / std # 标准化数据
return Arr
if __name__ == '__main__':
subjects = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
items = ["1", "2", "3", "4", "5"]
sub_items = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"]
#Step = ["BAP", "BTS", "AP", "TS", "DS"]
Step = ["AP"]
SaveTrainDataFilePath = "Pytorch\\data\\angle\\TrainData.csv"
SaveTrainLabelFilePath = "Pytorch\\data\\angle\\TrainLabel.csv"
SaveTestDataFilePath = "Pytorch\\data\\angle\\TestData.csv"
SaveTestLabelFilePath = "Pytorch\\data\\angle\\TestLabel.csv"
dic = getDic()
TrainArr = []
TrainAngle = []
TestArr = []
TestAngle = []
#region 图像展示
'''
fig = plt.figure()
plt.ion()
f = GetFileIterator(dic)
for eachItem in GetFileIterator(dic):
a = f.__next__()
Arr = normalization(a[5])
Arr = np.reshape(Arr,(60,21))
plt.imshow(Arr,cmap="Greys")
plt.title(a[1])
plt.pause(0.02)
plt.ioff()
'''
#endregion
#region 图像输出
i= 0
for eachItem in GetFileIterator(dic):
Arr = eachItem[5]
label = int(eachItem[2].split("°")[0])
label = switchLabelClass(label)
Arr = normalization(Arr) #数据标准化
i +=1
if(i % 5 != 0):
TrainArr.append(Arr)
TrainAngle.append(label)
else:
TestArr.append(Arr)
TestAngle.append(label)
TrainArr = np.array(TrainArr)
TrainAngle = np.array(TrainAngle)
TestArr = np.array(TestArr)
TestAngle = np.array(TestAngle)
np.savetxt(SaveTrainDataFilePath,TrainArr,delimiter=",")
np.savetxt(SaveTrainLabelFilePath, TrainAngle,fmt="%d", delimiter=",")
np.savetxt(SaveTestDataFilePath, TestArr, delimiter=",")
np.savetxt(SaveTestLabelFilePath, TestAngle,fmt="%d", delimiter=",")
#endregion