#!/usr/bin/env python
"""
Requirements:
#add by tzf
y_offset_buf_00 = []
x_offset_buf_00 = []
yx_offset_buf_00 = []
y_offset_buf_01 = []
x_offset_buf_01 = []
yx_offset_buf_01 = []
y_offset_buf_10 = []
x_offset_buf_10 = []
yx_offset_buf_10 = []
y_offset_buf_11 = []
x_offset_buf_11 = []
yx_offset_buf_11 = []
Items = {'y_offset':0, 'x_offset':0, 'ch':3, 'cs':0, 'phase':0, 'byte':1, 'bit':0, 'value':0}
y_offset = {'y_offset_Max':0, 'y_offset_Min':0, 'y_offset_Median':0,'y_offset_Sum':0}
x_offset = {'x_offset_Max':0, 'x_offset_Min':0, 'x_offset_Median':0}
#求每个x元素的(x元素相同时),最大值和最小值的差值
def y_offset_diff_max(x_element,x_offset_buf,yx_offset_buf):
"
:param x_element: 每个不同的x值
:param x_offset_buf: x_offset的所有值
:param yx_offset_buf: yx_offset的所有制
:return: 差值
"
x_offset_same_yx_buf = []
for j in range(len(x_offset_buf)):
if yx_offset_buf[j][1] == x_element:
x_offset_same_yx_buf.append(yx_offset_buf[j])
x_offset_same_array = np.array(x_offset_same_yx_buf)
print()
#x_offset_same_yx_buf.clear()
y_offset_array = x_offset_same_array[:, 0]
y_offset_min = np.min(y_offset_array)
y_offset_max = np.max(y_offset_array)
#y_offset_diff_max = abs(y_offset_max - y_offset_min)
return y_offset_min,y_offset_max
def draw_eye_data(x_offset_set,x_offset_buf,yx_offset_buf):
x_offset_list = list(x_offset_set)
x_offset_list.sort()
y_offset_min_list=[]
y_offset_max_list=[]
x_element_list=[]
for x_element in x_offset_list:
y_offset_min, y_offset_max = y_offset_diff_max(x_element, x_offset_buf, yx_offset_buf)
y_offset_min_list.append(y_offset_min)
y_offset_max_list.append(y_offset_max)
x_element_list.append(x_element)
return y_offset_min_list,y_offset_max_list,x_element_list
def get_max_min_onebyte(Data,img_path):
"
CH, bit, Byte取值已定是解析眼图数据,1/64
:param Data:输入的所有行数据,不带表头
:return:每组数据解析的结果
"
for Row in Data:
if (int(Row[6]) == Items['bit']) and (int(Row[5]) == Items['byte']) and (int(Row[2]) == Items['ch']) and (int(Row[7]) == 0):
if (int(Row[3]) == 0) and (int(Row[4]) == 0):
yx_offset_buf_00.append([int(Row[0]), int(Row[1])])
y_offset_buf_00.append(int(Row[0]))
x_offset_buf_00.append(int(Row[1]))
if (int(Row[3]) == 0) and (int(Row[4]) == 1):
yx_offset_buf_01.append([int(Row[0]), int(Row[1])])
y_offset_buf_01.append(int(Row[0]))
x_offset_buf_01.append(int(Row[1]))
if (int(Row[3]) == 1) and (int(Row[4]) == 0):
yx_offset_buf_10.append([int(Row[0]), int(Row[1])])
y_offset_buf_10.append(int(Row[0]))
x_offset_buf_10.append(int(Row[1]))
if (int(Row[3]) == 1) and (int(Row[4]) == 1):
yx_offset_buf_11.append([int(Row[0]), int(Row[1])])
y_offset_buf_11.append(int(Row[0]))
x_offset_buf_11.append(int(Row[1]))
x_offset_set_00 = set(x_offset_buf_00)
x_offset_set_01 = set(x_offset_buf_01)
x_offset_set_10 = set(x_offset_buf_10)
x_offset_set_11 = set(x_offset_buf_11)
print("绘制图片")
y_offset_min_list_00,y_offset_max_list_00,x_element_list_00 = draw_eye_data(x_offset_set_00,x_offset_buf_00,yx_offset_buf_00)
y_offset_min_list_01,y_offset_max_list_01,x_element_list_01 = draw_eye_data(x_offset_set_01,x_offset_buf_01,yx_offset_buf_01)
y_offset_min_list_10,y_offset_max_list_10,x_element_list_10 = draw_eye_data(x_offset_set_10,x_offset_buf_10,yx_offset_buf_10)
y_offset_min_list_11,y_offset_max_list_11,x_element_list_11 = draw_eye_data(x_offset_set_11,x_offset_buf_11,yx_offset_buf_11)
#cs=0,phase=0红色,cs=0,phase=1蓝色,cs=1,phase=0绿色,cs=1,phase=1黑色
plt.plot(x_element_list_00, y_offset_min_list_00,'r-')
plt.plot(x_element_list_00, y_offset_max_list_00,'r-')
plt.plot(x_element_list_01, y_offset_min_list_01,'b-')
plt.plot(x_element_list_01, y_offset_max_list_01,'b-')
plt.plot(x_element_list_10, y_offset_min_list_10,'g-')
plt.plot(x_element_list_10, y_offset_max_list_10,'g-')
plt.plot(x_element_list_11, y_offset_min_list_11,'k-')
plt.plot(x_element_list_11, y_offset_max_list_11,'k-')
plt.xlabel("x_offset")
plt.ylabel("y_offset")
title_str='bit='+str(Items['bit'])+',byte='+str(Items['byte'])+',ch='+str(Items['ch'])
plt.title(title_str)
plt.savefig(img_path+'/'+title_str+".png")
plt.cla()
print("绘制图片结束")
x_min = max(min(x_offset_set_00),min(x_offset_set_01),min(x_offset_set_10),min(x_offset_set_11))
x_max = min(max(x_offset_set_00),max(x_offset_set_01), max(x_offset_set_10), max(x_offset_set_11))
width = x_max-x_min
#change by gray 20210912
width2 = x_max+x_min
x_offset_set_00_filter = {x for x in x_offset_set_00 if x <= x_max and x >= x_min}
x_offset_set_01_filter = {x for x in x_offset_set_01 if x <= x_max and x >= x_min}
x_offset_set_10_filter = {x for x in x_offset_set_10 if x <= x_max and x >= x_min}
x_offset_set_11_filter = {x for x in x_offset_set_11 if x <= x_max and x >= x_min}
y_offset_max_diff_dict = {}
#add by gray 20210912
y_offset_diff_dict = {}
if operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_01_filter).sort()) and operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_10_filter).sort()) and operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_11_filter).sort()):
x_offset_list_00_filter = list(x_offset_set_00_filter)
x_offset_list_00_filter.sort()
for x_element in x_offset_list_00_filter:
y_offset_min_00,y_offset_max_00 = y_offset_diff_max(x_element, x_offset_buf_00, yx_offset_buf_00) #y_offset_max_diff_00\
y_offset_min_01,y_offset_max_01 = y_offset_diff_max(x_element, x_offset_buf_01, yx_offset_buf_01)
y_offset_min_10,y_offset_max_10 = y_offset_diff_max(x_element, x_offset_buf_10, yx_offset_buf_10)
y_offset_min_11,y_offset_max_11 = y_offset_diff_max(x_element, x_offset_buf_11, yx_offset_buf_11)
y_offset_min=max(y_offset_min_00,y_offset_min_01,y_offset_min_10,y_offset_min_11)
y_offset_max=min(y_offset_max_00,y_offset_max_01,y_offset_max_10,y_offset_max_11)
y_offset_max_diff_dict[x_element] = abs(y_offset_max-y_offset_min)
y_offset_diff_dict[x_element] = abs(y_offset_max+y_offset_min)
print('done')
else:
print('Data problem')
os._exit()
y_offset_buf_00.clear()
x_offset_buf_00.clear()
yx_offset_buf_00.clear()
y_offset_buf_01.clear()
x_offset_buf_01.clear()
yx_offset_buf_01.clear()
y_offset_buf_10.clear()
x_offset_buf_10.clear()
yx_offset_buf_10.clear()
y_offset_buf_11.clear()
x_offset_buf_11.clear()
yx_offset_buf_11.clear()
#change by gray 20210912
height = max(y_offset_max_diff_dict.values())
height2 = max(y_offset_diff_dict.values())
area = sum(y_offset_max_diff_dict.values())
center_x = width2 / 2
center_y = height2 / 2
center = '('+str(center_x)+','+str(center_y)+')'
#change by gray 20210913
#result_list = [Items['ch'], Items['byte'], Items['bit'], width, height, center, area]
result_list = [Items['ch'], Items['byte'], Items['bit'], width, height, str(center_x),str(center_y), area]
return result_list
def Data_process(filename,img_path):
"
读取数据
:param filename:输入文件
:return:解析结果
"
print("CH: %(ch)d, bit: %(bit)d, Byte: %(byte)d" %Items)
with open(filename, newline='') as csvfile:
Data = csv.reader(csvfile, delimiter=',')
Header = next(Data)
result_list = get_max_min_onebyte(Data,img_path)
return result_list
def Data_process_all_64(filename,save_path,img_path):
"
遍历64个不同的取值,并进行结果保存
:param filename:输入文件
:param save_path:输出文件
:return:
"
result = []
#change by gray 20210913
#name = ['ch', 'byte', 'bit','width','height','center','open area']
name = ['ch', 'byte', 'bit', 'width', 'height', 'center_x', 'center_y','open area']
for channel in range(0,4):
Items['ch'] = channel
for byte in range(0, 2):
Items['byte'] = byte
for bit in range(0, 8):
Items['bit'] = bit
result_list=Data_process(filename,img_path)
result.append(result_list)
width_list = [m[3] for m in result]
#print(width_list)
average_width = np.mean(width_list)
height_list = [n[4] for n in result]
#print(height_list)
average_height = np.mean(height_list)
average_list=['','','',average_width,average_height,'','','']
result.append(average_list)
test = pd.DataFrame(columns=name, data=result)
test.to_csv(save_path, encoding='gbk', index=False)
def main(file,save_path,img_path):
#parser = argparse.ArgumentParser()
# parser.add_argument("-c", "--channel", choices=[0,1,2,3], help="channel",type=int, default=0)
# parser.add_argument("-v", "--value", choices=[0,1], help="value",type=int, default=0)
# parser.add_argument("-b", "--byte", choices=[0,1], help="byte",type=int, default=0)
# parser.add_argument("-p", "--phase", choices=[0,1], help="phase",type=int, default=0)
# parser.add_argument("-s", "--chipselect", choices=[0,1], help="chipselect",type=int, default=0)
# parser.add_argument("-a", "--all", action="store_true", help="parse all data")
# parser.add_argument("-f", "--filename", help="file name",type=str, default="./plot.csv")
# args = parser.parse_args()
# file = args.filename
Data_process_all_64(file,save_path,img_path)
if name == "main":
#注意:路径尽量使用'/'分割,不要使用''
#file = './error/DDR_OFFLine_230YJ03C7W005V_Write_20210911021443971.csv'
file = 'C:/Users/charlie.cheng/Desktop/ddrr/SXR2150P_LP5_Eye_Plot_x_step_1_y_step_1_Write_2736000.csv'##输入解析文件路径
save_path = 'C:/Users/charlie.cheng/Desktop/ddrr/Writeresult.csv' #输出csv结果保存路径
img_path='C:/Users/charlie.cheng/Desktop/ddrr/Plot' #输出眼图的保存路径
if not os.path.exists(img_path):
os.mkdir(img_path) # 如果不存在这个img_path文件夹,就自动创建一个
main(file, save_path, img_path)
#os.system('pause')
#!/usr/bin/env python
"""
Requirements:
#add by tzf
y_offset_buf_00 = []
x_offset_buf_00 = []
yx_offset_buf_00 = []
y_offset_buf_01 = []
x_offset_buf_01 = []
yx_offset_buf_01 = []
y_offset_buf_10 = []
x_offset_buf_10 = []
yx_offset_buf_10 = []
y_offset_buf_11 = []
x_offset_buf_11 = []
yx_offset_buf_11 = []
Items = {'y_offset':0, 'x_offset':0, 'ch':3, 'cs':0, 'phase':0, 'byte':1, 'bit':0, 'value':0}
y_offset = {'y_offset_Max':0, 'y_offset_Min':0, 'y_offset_Median':0,'y_offset_Sum':0}
x_offset = {'x_offset_Max':0, 'x_offset_Min':0, 'x_offset_Median':0}
#求每个x元素的(x元素相同时),最大值和最小值的差值
def y_offset_diff_max(x_element,x_offset_buf,yx_offset_buf):
'''
:param x_element: 每个不同的x值
:param x_offset_buf: x_offset的所有值
:param yx_offset_buf: yx_offset的所有制
:return: 差值
'''
x_offset_same_yx_buf = []
for j in range(len(x_offset_buf)):
if yx_offset_buf[j][1] == x_element:
x_offset_same_yx_buf.append(yx_offset_buf[j])
x_offset_same_array = np.array(x_offset_same_yx_buf)
print()
#x_offset_same_yx_buf.clear()
y_offset_array = x_offset_same_array[:, 0]
y_offset_min = np.min(y_offset_array)
y_offset_max = np.max(y_offset_array)
#y_offset_diff_max = abs(y_offset_max - y_offset_min)
return y_offset_min,y_offset_max
def draw_eye_data(x_offset_set,x_offset_buf,yx_offset_buf):
x_offset_list = list(x_offset_set)
x_offset_list.sort()
y_offset_min_list=[]
y_offset_max_list=[]
x_element_list=[]
for x_element in x_offset_list:
y_offset_min, y_offset_max = y_offset_diff_max(x_element, x_offset_buf, yx_offset_buf)
y_offset_min_list.append(y_offset_min)
y_offset_max_list.append(y_offset_max)
x_element_list.append(x_element)
return y_offset_min_list,y_offset_max_list,x_element_list
def get_max_min_onebyte(Data,img_path):
'''
CH, bit, Byte取值已定是解析眼图数据,1/64
:param Data:输入的所有行数据,不带表头
:return:每组数据解析的结果
'''
for Row in Data:
if (int(Row[6]) == Items['bit']) and (int(Row[5]) == Items['byte']) and (int(Row[2]) == Items['ch']) and (int(Row[7]) == 0):
if (int(Row[3]) == 0) and (int(Row[4]) == 0):
yx_offset_buf_00.append([int(Row[0]), int(Row[1])])
y_offset_buf_00.append(int(Row[0]))
x_offset_buf_00.append(int(Row[1]))
if (int(Row[3]) == 0) and (int(Row[4]) == 1):
yx_offset_buf_01.append([int(Row[0]), int(Row[1])])
y_offset_buf_01.append(int(Row[0]))
x_offset_buf_01.append(int(Row[1]))
if (int(Row[3]) == 1) and (int(Row[4]) == 0):
yx_offset_buf_10.append([int(Row[0]), int(Row[1])])
y_offset_buf_10.append(int(Row[0]))
x_offset_buf_10.append(int(Row[1]))
if (int(Row[3]) == 1) and (int(Row[4]) == 1):
yx_offset_buf_11.append([int(Row[0]), int(Row[1])])
y_offset_buf_11.append(int(Row[0]))
x_offset_buf_11.append(int(Row[1]))
x_offset_set_00 = set(x_offset_buf_00)
x_offset_set_01 = set(x_offset_buf_01)
x_offset_set_10 = set(x_offset_buf_10)
x_offset_set_11 = set(x_offset_buf_11)
print("绘制图片")
y_offset_min_list_00,y_offset_max_list_00,x_element_list_00 = draw_eye_data(x_offset_set_00,x_offset_buf_00,yx_offset_buf_00)
y_offset_min_list_01,y_offset_max_list_01,x_element_list_01 = draw_eye_data(x_offset_set_01,x_offset_buf_01,yx_offset_buf_01)
y_offset_min_list_10,y_offset_max_list_10,x_element_list_10 = draw_eye_data(x_offset_set_10,x_offset_buf_10,yx_offset_buf_10)
y_offset_min_list_11,y_offset_max_list_11,x_element_list_11 = draw_eye_data(x_offset_set_11,x_offset_buf_11,yx_offset_buf_11)
#cs=0,phase=0红色,cs=0,phase=1蓝色,cs=1,phase=0绿色,cs=1,phase=1黑色
plt.plot(x_element_list_00, y_offset_min_list_00,'r-')
plt.plot(x_element_list_00, y_offset_max_list_00,'r-')
plt.plot(x_element_list_01, y_offset_min_list_01,'b-')
plt.plot(x_element_list_01, y_offset_max_list_01,'b-')
plt.plot(x_element_list_10, y_offset_min_list_10,'g-')
plt.plot(x_element_list_10, y_offset_max_list_10,'g-')
plt.plot(x_element_list_11, y_offset_min_list_11,'k-')
plt.plot(x_element_list_11, y_offset_max_list_11,'k-')
plt.xlabel("x_offset")
plt.ylabel("y_offset")
title_str='bit='+str(Items['bit'])+',byte='+str(Items['byte'])+',ch='+str(Items['ch'])
plt.title(title_str)
plt.savefig(img_path+'/'+title_str+".png")
plt.cla()
print("绘制图片结束")
x_min = max(min(x_offset_set_00),min(x_offset_set_01),min(x_offset_set_10),min(x_offset_set_11))
x_max = min(max(x_offset_set_00),max(x_offset_set_01), max(x_offset_set_10), max(x_offset_set_11))
width = x_max-x_min
#change by gray 20210912
width2 = x_max+x_min
x_offset_set_00_filter = {x for x in x_offset_set_00 if x <= x_max and x >= x_min}
x_offset_set_01_filter = {x for x in x_offset_set_01 if x <= x_max and x >= x_min}
x_offset_set_10_filter = {x for x in x_offset_set_10 if x <= x_max and x >= x_min}
x_offset_set_11_filter = {x for x in x_offset_set_11 if x <= x_max and x >= x_min}
y_offset_max_diff_dict = {}
#add by gray 20210912
y_offset_diff_dict = {}
if operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_01_filter).sort()) and operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_10_filter).sort()) and operator.eq(list(x_offset_set_00_filter).sort(),list(x_offset_set_11_filter).sort()):
x_offset_list_00_filter = list(x_offset_set_00_filter)
x_offset_list_00_filter.sort()
for x_element in x_offset_list_00_filter:
y_offset_min_00,y_offset_max_00 = y_offset_diff_max(x_element, x_offset_buf_00, yx_offset_buf_00) #y_offset_max_diff_00\
y_offset_min_01,y_offset_max_01 = y_offset_diff_max(x_element, x_offset_buf_01, yx_offset_buf_01)
y_offset_min_10,y_offset_max_10 = y_offset_diff_max(x_element, x_offset_buf_10, yx_offset_buf_10)
y_offset_min_11,y_offset_max_11 = y_offset_diff_max(x_element, x_offset_buf_11, yx_offset_buf_11)
y_offset_min=max(y_offset_min_00,y_offset_min_01,y_offset_min_10,y_offset_min_11)
y_offset_max=min(y_offset_max_00,y_offset_max_01,y_offset_max_10,y_offset_max_11)
y_offset_max_diff_dict[x_element] = abs(y_offset_max-y_offset_min)
y_offset_diff_dict[x_element] = abs(y_offset_max+y_offset_min)
print('done')
else:
print('Data problem')
os._exit()
y_offset_buf_00.clear()
x_offset_buf_00.clear()
yx_offset_buf_00.clear()
y_offset_buf_01.clear()
x_offset_buf_01.clear()
yx_offset_buf_01.clear()
y_offset_buf_10.clear()
x_offset_buf_10.clear()
yx_offset_buf_10.clear()
y_offset_buf_11.clear()
x_offset_buf_11.clear()
yx_offset_buf_11.clear()
#change by gray 20210912
height = max(y_offset_max_diff_dict.values())
height2 = max(y_offset_diff_dict.values())
area = sum(y_offset_max_diff_dict.values())
center_x = width2 / 2
center_y = height2 / 2
center = '('+str(center_x)+','+str(center_y)+')'
#change by gray 20210913
#result_list = [Items['ch'], Items['byte'], Items['bit'], width, height, center, area]
result_list = [Items['ch'], Items['byte'], Items['bit'], width, height, str(center_x),str(center_y), area]
return result_list
def Data_process(filename,img_path):
'''
读取数据
:param filename:输入文件
:return:解析结果
'''
print("CH: %(ch)d, bit: %(bit)d, Byte: %(byte)d" %Items)
with open(filename, newline='') as csvfile:
Data = csv.reader(csvfile, delimiter=',')
Header = next(Data)
result_list = get_max_min_onebyte(Data,img_path)
return result_list
def Data_process_all_64(filename,save_path,img_path):
'''
遍历64个不同的取值,并进行结果保存
:param filename:输入文件
:param save_path:输出文件
:return:
'''
result = []
#change by gray 20210913
#name = ['ch', 'byte', 'bit','width','height','center','open area']
name = ['ch', 'byte', 'bit', 'width', 'height', 'center_x', 'center_y','open area']
for channel in range(0,4):
Items['ch'] = channel
for byte in range(0, 2):
Items['byte'] = byte
for bit in range(0, 8):
Items['bit'] = bit
result_list=Data_process(filename,img_path)
result.append(result_list)
width_list = [m[3] for m in result]
#print(width_list)
average_width = np.mean(width_list)
height_list = [n[4] for n in result]
#print(height_list)
average_height = np.mean(height_list)
average_list=['','','',average_width,average_height,'','','']
result.append(average_list)
test = pd.DataFrame(columns=name, data=result)
test.to_csv(save_path, encoding='gbk', index=False)
def main(file,save_path,img_path):
#parser = argparse.ArgumentParser()
# parser.add_argument("-c", "--channel", choices=[0,1,2,3], help="channel",type=int, default=0)
# parser.add_argument("-v", "--value", choices=[0,1], help="value",type=int, default=0)
# parser.add_argument("-b", "--byte", choices=[0,1], help="byte",type=int, default=0)
# parser.add_argument("-p", "--phase", choices=[0,1], help="phase",type=int, default=0)
# parser.add_argument("-s", "--chipselect", choices=[0,1], help="chipselect",type=int, default=0)
# parser.add_argument("-a", "--all", action="store_true", help="parse all data")
# parser.add_argument("-f", "--filename", help="file name",type=str, default="./plot.csv")
# args = parser.parse_args()
# file = args.filename
Data_process_all_64(file,save_path,img_path)
if name == "main":
#注意:路径尽量使用'/'分割,不要使用''
#file = './error/DDR_OFFLine_230YJ03C7W005V_Write_20210911021443971.csv'
file = 'C:/Users/charlie.cheng/Desktop/ddrr/SXR2150P_LP5_Eye_Plot_x_step_1_y_step_1_Write_2736000.csv'##输入解析文件路径
save_path = 'C:/Users/charlie.cheng/Desktop/ddrr/Writeresult.csv' #输出csv结果保存路径
img_path='C:/Users/charlie.cheng/Desktop/ddrr/Plot' #输出眼图的保存路径
if not os.path.exists(img_path):
os.mkdir(img_path) # 如果不存在这个img_path文件夹,就自动创建一个
main(file, save_path, img_path)
#os.system('pause')
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。