热度 3
2023-10-23 10:18
59 次阅读|
0 个评论
import pandas as pd import re import os from tkinter import messagebox #------------------------- update foder path---------------------- folder = r'D:\ 联电自研 \IGBT HH\MAP\ENEPIG_DOE5\FA37-9341@202\trial' rawdata_name= 'rawdataTrans.csv' #------------------------- update foder path---------------------- #------------------------- update filter spec path---------------------- spec_path = r'D:\ 联电自研 \IGBT HH\MAP\ENEPIG_DOE5\spec_filter.csv' #------------------------- update foder path---------------------------- Good = '.' Fail = 'X' wafer_column_name = 'WAFER' Xcord_column = 'X' Ycord_column = 'Y' Filter = 'Filter' file_path =os.path.join(folder , rawdata_name) rawdata = pd.read_csv(file_path , encoding = "utf-8" ) CP_SPC = pd.read_csv(spec_path , index_col = , encoding = "utf-8" ) column_list = list (rawdata.columns) if True : rawdata = 0 for row_index in rawdata.index: for column_index_key in CP_SPC.index: try : if rawdata.loc < CP_SPC.loc or \ rawdata.loc > CP_SPC.loc or \ pd.isna(rawdata.loc ): rawdata.loc = CP_SPC.loc break else : continue except KeyError : continue def caculate_CP_bin (rawdata , split , key , bin , BIN): if rawdata == key) & (rawdata == bin)] is not None : bin_rate = rawdata == key) & (rawdata == bin)] .size / \ rawdata == key] .size else : bin_rate = 0 return bin_rate waferlist = sorted (rawdata .unique()) bin0 = bin1 = bin2 = bin3 = bin4 = bin5 = for Yield_wafer_number in waferlist: bin0.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 0 , BIN = 'BIN' )) bin0_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 0 , BIN =Filter)) bin1.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 1 , BIN = 'BIN' )) bin1_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 1 , BIN =Filter)) bin2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 2 , BIN = 'BIN' )) bin2_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 2 , BIN =Filter)) bin3.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 3 , BIN = 'BIN' )) bin3_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 3 , BIN =Filter)) bin4.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 4 , BIN = 'BIN' )) bin4_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 4 , BIN =Filter)) bin5.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 5 , BIN = 'BIN' )) bin5_2.append(caculate_CP_bin(rawdata , split =wafer_column_name , key =Yield_wafer_number , bin = 5 , BIN =Filter)) yield_key2 = { 'WAFER' : waferlist , 'Yield' : bin0 , 'IGES_Fail' : bin1 , 'ICES_Fail' : bin2 , 'VTH_Fail' : bin3 , 'Delta_Vth fail' : bin4 , 'VCESAT_Fail' : bin5 , 'Yield_filter' : bin0_2 , 'IGES_Fail_filter' : bin1_2 , 'ICES_Fail_filter' : bin2_2 , 'VTH_Fail_filter' : bin3_2 , 'Delta_Vth fail_filter' : bin4_2 , 'VCESAT_Fail_filter' : bin5_2} Yield_key_table2 = pd.DataFrame(yield_key2) yieldTAB = os.path.join(folder , 'yield for compare.csv' ) Yield_key_table2.to_csv(yieldTAB , index = False ) map_file_names = for map_file_name in map_file_names: map_file_path = os.path.join(folder , map_file_name) wafer= int (map_file_name ) with open (map_file_path) as f: raw_list = f.readlines() Map_tables = rawdata == wafer].pivot_table( index =Ycord_column , columns =Xcord_column , values =Filter) new = Map_tables.fillna( ' ' ).replace( 0.0 , Good).replace( 1.0 , Fail).replace( 2.0 , Fail).replace( 3.0 , Fail).replace( 5.0 , Fail).replace( 7.0 , Fail).replace( 4.0 , Fail) filter_list = .astype( str ) filter_list.append( '' .join( list (array))) filter_list.append( 'END MAP' ) n_star = 10 n_end = 29 for t in range (n_star , n_end , 1 ): merged_str = '' for raw , filter in zip (raw_list , filter_list ): if filter== Fail: merged_str += filter else : merged_str += raw raw_list = merged_str + ' \n ' new_failure_count = 0 nof_die = 0 for t in range (n_star , n_end- 1 ): new_failure_count += raw_list .count(Fail) nof_die += raw_list .count(Good)+raw_list .count(Fail) raw_list = 'Failed Die(X) : {}' .format(new_failure_count) + ' \n ' raw_list = 'CP Good Die(.) : {}' .format(nof_die-new_failure_count)+ ' \n ' raw_list = 'CP Good Die(.) : {}' .format(nof_die-new_failure_count) with open (map_file_path , 'w' ) as wr_new: for l in raw_list: wr_new.write(l) output_folder = os.path.join(folder , 'newformat.csv' ) rawdata.to_csv(output_folder , index = False, encoding = "utf-8_sig" ) messagebox.showinfo( 'Status' , 'Map & 数据已成功导出 ' ) else : messagebox.showwarning( ' 注意 ' , 'columns not match,please check rawdata' )