import os
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import math
import xlwt
from six.moves import xrange
np.set_printoptions(suppress=True)
np.set_printoptions(threshold=np.inf) #输出全部矩阵不带省略号
data = np.load('data/good05.npy')
def fenzhi(data):
data = data.reshape(-1,3,60)
data = data[0:1000,:,0:60]
final = []
for i in range(len(data)):
zhu_x = data[i][0][0:30]
zhu_y = data[i][0][30:60]
zuo_x = data[i][1][0:30]
zuo_y = data[i][1][30:60]
you_x = data[i][2][0:30]
you_y = data[i][2][30:60]
###########################################
#找到端点,让它之后的值都跟这个端点相等
#处理左分支
zuo_index = [] #列表中存的是数组,第一个即为第一个端点 列表中存放的是判断为是插值点的点,a值越小说明,列表中的值越少,索引值,
#a值越大,列表中的值越多,但是真实点就越少,甚至真实点为0,所以需要判断
for j in range(1,len(zuo_x)-1):
threshold = 0.05 # 不能太大也不能太小,太大真实值的索引就会变小,一般索引应大于等于2,(0.05的时候效果比较好)
if abs(zuo_x[j-1]-zuo_x[j])<threshold and abs(zuo_x[j]-zuo_x[j+1])<threshold:
if abs(zuo_y[j-1]-zuo_y[j])<threshold and abs(zuo_y[j]-zuo_y[j+1])<threshold:
zuo_index.append((j-1,zuo_x[j-1],zuo_y[j-1]))
#限制左分支条件
if len(zuo_index) < 2:#continue语句满足条件结束本次循环
continue
zuo_duan_index = zuo_index[0][0]
if zuo_duan_index < 2:
continue
zuo_duan_x = zuo_index[0][1]
zuo_duan_y = zuo_index[0][2]
zuo_x = np.array(zuo_x) #变为数组,以便于替换
zuo_y = np.array(zuo_y)
zuo_x[zuo_duan_index::] = zuo_duan_x
zuo_y[zuo_duan_index::] = zuo_duan_y
#处理右分支
you_index = []
for j in range(1,len(you_x)-1):
threshold = 0.05
if abs(you_x[j-1]-you_x[j])<threshold and abs(you_x[j]-you_x[j+1])<threshold:
if abs(you_y[j-1]-you_y[j])<threshold and abs(you_y[j]-you_y[j+1])<threshold:
you_index.append((j-1,you_x[j-1],you_y[j-1]))
#限制右分支 条件
if len(you_index) < 2:
continue
you_duan_index = you_index[0][0]
if you_duan_index < 2:
continue
you_duan_x = you_index[0][1]
you_duan_y = you_index[0][2]
you_x = np.array(you_x)
you_y = np.array(you_y)
you_x[you_duan_index::] = you_duan_x
you_y[you_duan_index::] = you_duan_y
#处理主分支
zhu_index = []
for j in range(1,len(zhu_x)-1):
threshold = 0.05
if abs(zhu_x[j-1]-zhu_x[j])< threshold and abs(zhu_x[j]-zhu_x[j+1])<threshold:
if abs(zhu_y[j-1]-zhu_y[j])<threshold and abs(zhu_y[j]-zhu_y[j+1]<threshold):
zhu_index.append((j+1,zhu_x[j+1],zhu_y[j+1]))
#限制主分支条件
if len(zhu_index) < 2 :
continue
zhu_duan_index = zhu_index[-1][0] #主分支不同于左右分支,它再最后一个
if zhu_duan_index > 27:
continue
zhu_duan_x = zhu_index[-1][1]
zhu_duan_y = zhu_index[-1][2]
zhu_x = np.array(zhu_x)
zhu_y = np.array(zhu_y)
zhu_x[0:zhu_duan_index] = zhu_duan_x
zhu_y[0:zhu_duan_index] = zhu_duan_y
###############################################
# plt.scatter(zhu_x,zhu_y,color='red')
# plt.scatter(zuo_x,zuo_y,color='blue')
# plt.scatter(you_x,you_y,color='green')
# plt.show()
###############################################
zhu = np.concatenate((zhu_x,zhu_y))
zuo = np.concatenate((zuo_x,zuo_y))
you = np.concatenate((you_x,you_y))
fencha = np.concatenate((zhu,zuo,you))
final.append(fencha)
final = np.array(final)
final = final.reshape(-1,3,60)
return final
final = fenzhi(data)
print(final.shape)
np.save('处理后wgan.npy',final)