-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1test.py
128 lines (120 loc) · 3.64 KB
/
1test.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
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
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 28 15:15:32 2018
@author: Administrator
"""
import numpy as np
import matplotlib.pyplot as plt
import os
import sys
#import shutil
global count1, count2
count1 = count2 =0
def file_segmentation(lBound, rBound):
dataSet = []
for i in range(lBound, rBound):
if os.path.exists('Shot_%d.txt' % i):
with open('Shot_%d.txt' % i, 'r') as f:
lines = f.readlines()
ls = len(lines)
for j in range(ls):
lineArr = []
line = lines[j].strip().split(' ')
l = len(line)
for k in range(l):
la = line[k].strip()
if la == '':
pass
else:
lineArr.append(np.float32(la))
dataSet.append(lineArr)
else:
pass
length = len(dataSet)
return dataSet, length
def normalization(dataMat):
minVals = dataMat.min(0)
maxVals = dataMat.max(0)
ranges = maxVals - minVals
normDataSet = np.zeros(np.shape(dataMat))
m = dataMat.shape
normDataSet = dataMat - np.tile(minVals, m)
normDataSet = normDataSet/np.tile(ranges, m)
return normDataSet
# def check_filename_available(filename):
# def check_meta(file_name):
# n=[0]
# file_name_new=file_name
# if os.path.isfile(file_name):
# file_name_new=file_name[:file_name.rfind('.')]+'_'+str(n[0])+file_name[file_name.rfind('.'):]
# n[0] += 1
# if os.path.isfile(file_name_new):
# file_name_new=check_meta(file_name)
# return file_name_new
# return_name=check_meta(filename)
# return return_name
def cutout_pictures(firstArrival_point, finalDataMat, stride):
global count1,count2
axis_x = np.array(np.linspace(0, 3500, 876))
for i in range(876-stride):
plt.figure(figsize=(2.99,2.99))
plt.rcParams['savefig.dpi'] = 100
plt.axis('off')
plt.subplots_adjust(top = 1, bottom = 0,
right = 1, left = 0,
hspace = 0, wspace = 0)
plt.margins(0,0)
x = axis_x[i:i+stride+1]
y = finalDataMat[i:i+stride+1]
plt.plot(x, y, color = 'k', linewidth = 1.5)
if firstArrival_point in x:
# plt.savefig(check_filename_available('trainSet1\\1.jpg'))
filename1 = ('trainSet\\1_%d.jpg' %count1)
plt.savefig(filename1)
count1 += 1
else:
filename2 = ('trainSet\\0_%d.jpg' %count2)
#plt.savefig(check_filename_available('trainSet1\\0.jpg'))
plt.savefig(filename2)
count2 += 1
# plt.show()
plt.close("all")
sys.stdout.flush()
#plt.clf()
# for i in range(13378,13538):
# for j in range(20000):
# os.chdir('d:\\1wyh\\2zhenyuan_huizong')
# text = ('{:}_shuchu_{:}.txt'.format(i,j))
# if not os.path.exists(text):
# break
# else:
# file = ('%d' %i)
# shutil.move(text, file)
if __name__ == '__main__':
dataSet, dataSet_len = file_segmentation(13369, 13370)
for i in range(int(dataSet_len/2), dataSet_len):
dataSet_segmentation = dataSet[i][12:]
firstArrival_point = dataSet[i][11]
if firstArrival_point == 0:
pass
else:
dataMat = np.array(dataSet_segmentation)
normDataSet = normalization(dataMat)
cutout_pictures(firstArrival_point, normDataSet, 6)
# dataSet_segmentation = dataSet[0][12:]
# dataMat = np.array(dataSet_segmentation)
# normDataSet = normalization(dataMat)
# # print(dataSet_segmentation)
# # print(dataMat)
# # print(normDataSet)
# plt.figure(figsize=(29.9,2.99))
# plt.axis('off')
# plt.subplots_adjust(top = 1, bottom = 0,
# right = 1, left = 0,
# hspace = 0, wspace = 0)
# plt.margins(0,0)
# axis_x = np.array(np.linspace(0, 3500, 876))
# # x = axis_x[i:i+stride+1]
# # y = finalDataMat[i:i+stride+1]
# plt.plot(axis_x, normDataSet, color = 'k', linewidth = 1.5)
# plt.show()