帮我优化以下代码,使其简单易修改,且提高运行效率:# --coding:utf-8--
import openpyxl
import re
import os
import linecache
# 判断字符串中是否含有特殊标点符号
def has_punctuation(str, punctuation={"-", "."}):
for char in str:
if char in punctuation:
return True
return False
# 获取die的相关信息,坐标和bin
def Die_manage(openfile):
die = 0
Bin = 0
x = 0
y = 0
site = []
Die_dic = {}
with open(openfile, 'r+') as f:
for num, line in enumerate(f.readlines()):
line_data = line.split()
if 'Device#:' in line_data:
if has_punctuation(line_data[1]):
pass
else:
die = int(line_data[1])
if 'Site' in line_data and 'Bin' in line_data:
# bin = re.findall(r"\d+\.?\d*", (linecache.getline(openfile, num + 3)))
bin = linecache.getline(openfile, num + 3).split()
# print(f'{bin=}')
if len(bin) < 3:
pass
else:
if bin[2].casefold() == 'N/A'.casefold():
Bin = 1
else:
Bin = int(bin[2])
if 'Site' in line_data and 'X_Coord' in line_data:
x = int(re.findall(r"\d+\.?\d*", (linecache.getline(openfile, num + 3)))[1])
y = int(re.findall(r"\d+\.?\d*", (linecache.getline(openfile, num + 3)))[2])
if Bin != 0 and x != 0 and y != 0:
site.append(x)
site.append(y)
site.append(Bin)
Die_dic[die] = site
site = []
Bin = 0
x = 0
y = 0
return Die_dic
def unit_conversion(value: str, from_unit: str, to_unit: str = None) -> float:
"""
通用单位转换函数,支持电流、电压、频率等单位的相互转换
Args:
value: 要转换的数值字符串
from_unit: 原始单位(不区分大小写)
to_unit: 目标单位(不区分大小写),默认为None表示自动选择常用单位
Returns:
转换后的数值
Raises:
ValueError: 如果输入单位不支持或转换不兼容
"""
# 定义单位转换基准和转换因子
UNIT_CONVERSION = {
# 电流单位
'a': 1e6, # 安培 -> 微安
'ma': 1e3, # 毫安 -> 微安
'ua': 1, # 微安
'na': 1e-3, # 纳安 -> 微安
'pa': 1e-6, # 皮安 -> 微安
'fa': 1e-9, # 飞安 -> 微安
# 电压单位
'v': 1e3, # 伏特 -> 毫伏
'mv': 1, # 毫伏
'uv': 1e-3, # 微伏 -> 毫伏
'kv': 1e6, # 千伏 -> 毫伏
# 频率单位
'hz': 1e-6, # 赫兹 -> 兆赫
'khz': 1e-3, # 千赫 -> 兆赫
'mhz': 1, # 兆赫
'ghz': 1e3, # 千兆赫 -> 兆赫
}
# 自动选择目标单位
if to_unit is None:
if any(u in from_unit.lower() for u in ['a', 'ma', 'ua', 'na', 'pa', 'fa']):
to_unit = 'ua' # 电流默认转微安
elif any(u in from_unit.lower() for u in ['v', 'mv', 'uv', 'kv']):
to_unit = 'mv' # 电压默认转毫伏
elif any(u in from_unit.lower() for u in ['hz', 'khz', 'mhz', 'ghz']):
to_unit = 'mhz' # 频率默认转兆赫
from_unit = from_unit.lower()
to_unit = to_unit.lower()
# 验证单位是否支持
if from_unit not in UNIT_CONVERSION or to_unit not in UNIT_CONVERSION:
raise ValueError(f"不支持的转换单位: {from_unit} -> {to_unit}")
# 检查单位类型是否一致
from_type = 'current' if 'a' in from_unit else 'voltage' if 'v' in from_unit else 'frequency'
to_type = 'current' if 'a' in to_unit else 'voltage' if 'v' in to_unit else 'frequency'
if from_type != to_type:
raise ValueError(f"单位类型不匹配: 不能将{from_type}单位转换为{to_type}单位")
try:
num_value = float(value)
except ValueError:
raise ValueError(f"无效的数值格式: {value}")
# 执行转换: 先转为基础单位,再转为目标单位
base_value = num_value * UNIT_CONVERSION[from_unit]
converted_value = base_value / UNIT_CONVERSION[to_unit]
return converted_value
DataDir = input('Input file path:')
# DataDir = r'Z:\01 raw data\02 BCD120_New\GPIO\HT150'
Files = os.listdir(DataDir)
file_need_list = []
Files = os.listdir(DataDir)
for Filename in Files:
SrcFile = os.path.join(Filename)
file_need_list.append(SrcFile)
file_need_list_txt = []
for index_txt in file_need_list:
if '.txt' in index_txt and '.xlsx' not in index_txt:
file_need_list_txt.append(index_txt)
num = 0
# supply_voltage_list = ["D12", "D25_12", "D33_12"]
# supply_voltage_list = ["D18", "D5_18", "D2"]
supply_voltage_list = ["D5"]
open_and_short_test_item = ["os", "power_os", "leakage", "leakage_in", "leakage_out", "hz", "input0", "input1",
"output0", "output1", "fail_safe", "v18_hz", "v18_in0", "v18_in1", "v18_out0",
"v18_out1", "v2.5_hz", "v2.5_in0", "v2.5_in1", "v2.5_out0", "v2.5_out1",
"V33_Hz", "V33_In0", "V33_In1", "V33_Out0", "V33_Out1"
]
tolerance_vdd_item = ["tolerance_hz", "tolerance_input", "onlyvdd"]
drive_item = ["PDrive", "NDrive"]
vi_item = ["VIH", "VIL", "VIH_ECOMS_H", "VIL_ECOMS_H"]
pull_item = ["Pull_Down", "Pull_Up"]
shmoo_item = ["power_onlyvdd25", "out0_shmoo",
"out1_shmoo", "in0_shmoo", "in1_shmoo", "hz_shmoo"]
function_item = ["Function_Output", "Function_Input", "Function_Input_ECOMSH", "OD_Function_Output", "OD_Function_Input"]
function_shmoo_item = ["shmoo_output", "shmoo_input"]
rate_site_dict = {"EDR00": 0, "EDR01": 1, "EDR10": 2, "EDR11": 3, "EDR000": 0, "EDR001": 1, "EDR010": 2, "EDR011": 3,
"EDR100": 0, "EDR101": 1, "EDR110": 2, "EDR111": 3}
for index in file_need_list_txt:
print('开始处理文件:', index)
openfile1 = DataDir + '/' + index
if os.path.exists(DataDir + '/' + index.replace('.txt','')) == False:
os.mkdir(DataDir + '/' + index.replace('.txt',''))
outputfile_1D8 = DataDir + '/' + index.replace('.txt','') + '/' + index.replace('.txt','_D18.xlsx')
# outputfile1_3D3 = DataDir + '/' + index.replace('.txt','') + '/' + index.replace('.txt','_D5.xlsx')
outputfile1_1D8_3D3 = DataDir + '/' + index.replace('.txt','') + '/' + index.replace('.txt','_D5_18.xlsx')
filename = index.split('.txt')[0].split('_')
for element in filename:
if element.startswith('CL') or element.startswith('AL'):
Lot_ID = element
if element.startswith('#'):
Wafer_ID = element
print('Wafer_ID=', Wafer_ID)
print('Lot_ID=', Lot_ID)
# 获取die相关信息
Die_dic = Die_manage(openfile1)
for supply_voltage in supply_voltage_list:
writefile = os.path.join(DataDir, index.replace('.txt', ''), index.replace('.txt', f"_{supply_voltage}.xlsx"))
locals()[supply_voltage] = openpyxl.Workbook()
# 创建Summary'
Summary = locals()[supply_voltage].active
Summary.title = 'Summary'
for key in Die_dic:
x = Die_dic[key][0]
y = Die_dic[key][1]
bin = Die_dic[key][2]
Summary.cell(1, 1, "Lot_ID")
Summary.cell(1, 2, "Wafer_ID")
Summary.cell(1, 3, "Die_ID")
Summary.cell(1, 4, "X")
Summary.cell(1, 5, "Y")
Summary.cell(1, 6, 'Bin')
Summary.cell(key + 1, 1, Lot_ID)
Summary.cell(key + 1, 2, Wafer_ID)
Summary.cell(key + 1, 6, bin)
Summary.cell(key + 1, 3, key)
Summary.cell(key + 1, 4, x)
Summary.cell(key + 1, 5, y)
Summary.cell(key + 1, 6, bin)
Device_num = 0
detect_item_list = []
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
# print(line_data)
if r'Device#:' in ' '.join(line_data):
Device_num = Device_num + 1
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and supply_voltage in ''.join(line_data) \
and len(line_data) == 1 and Device_num == 1:
detect_item = re.findall(r'[<](.*?)[>]', line_data[0])[0]
detect_item_list.append(detect_item)
if Device_num > 1:
break
print(detect_item_list)
for detect_item in detect_item_list:
item_start = 0
for test_item in open_and_short_test_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "open and short"
for test_item in tolerance_vdd_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "tolerance"
for test_item in drive_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "drive"
for test_item in vi_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "vi"
for test_item in pull_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "pull"
for test_item in shmoo_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "shmoo"
for test_item in function_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "function"
for test_item in function_shmoo_item:
if test_item.casefold() in detect_item.casefold():
test_classification = "function_shmoo"
print(f"{detect_item=} {test_classification=}")
if test_classification == "open and short":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(1, 2, "wafer_ID")
ws.cell(1, 3, "Die_ID")
ws.cell(1, 4, "X")
ws.cell(1, 5, "Y")
ws.cell(1, 6, "Pin")
row_index = 1
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data or "Site" in line_data:
continue
if len(line_data) < 5:
continue
row_index += 1
pin = line_data[3]
if 'N/A' in line_data:
current_data = line_data[6]
current_unit = line_data[7]
else:
current_data = line_data[7]
current_unit = line_data[8]
# print(line_data)
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
ws.cell(1, 7, f"{detect_item}({unit})")
ws.cell(row_index, 1, Lot_ID)
ws.cell(row_index, 2, Wafer_ID)
ws.cell(row_index, 3, die)
ws.cell(row_index, 4, Die_dic[die][0])
ws.cell(row_index, 5, Die_dic[die][1])
ws.cell(row_index, 6, pin)
ws.cell(row_index, 7, value)
elif item_start == 0:
continue
if test_classification == "tolerance":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(1, 2, "wafer_ID")
ws.cell(1, 3, "Die_ID")
ws.cell(1, 4, "X")
ws.cell(1, 5, "Y")
ws.cell(1, 6, "Pin")
ws.cell(1, 7, "Voltage(V)")
row_index = 1
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data or "Site" in line_data:
continue
if len(line_data) < 5:
continue
row_index += 1
pin = line_data[3]
if 'N/A' in line_data and ("(A)" in line_data or "(F)" in line_data):
current_data = line_data[6]
current_unit = line_data[7]
voltage_data = line_data[10]
voltage_unit = line_data[11]
elif 'N/A' in line_data:
current_data = line_data[6]
current_unit = line_data[7]
voltage_data = line_data[9]
voltage_unit = line_data[10]
elif "(A)" in line_data or "(F)" in line_data:
current_data = line_data[6]
current_unit = line_data[7]
voltage_data = line_data[12]
voltage_unit = line_data[13]
else:
current_data = line_data[7]
current_unit = line_data[8]
voltage_data = line_data[11]
voltage_unit = line_data[12]
# print(voltage_data, voltage_unit)
value = unit_conversion(current_data, current_unit)
voltage = unit_conversion(voltage_data, voltage_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
ws.cell(1, 8, f"{detect_item}({unit})")
ws.cell(row_index, 1, Lot_ID)
ws.cell(row_index, 2, Wafer_ID)
ws.cell(row_index, 3, die)
ws.cell(row_index, 4, Die_dic[die][0])
ws.cell(row_index, 5, Die_dic[die][1])
ws.cell(row_index, 6, pin)
ws.cell(row_index, 7, voltage)
ws.cell(row_index, 8, value)
elif item_start == 0:
continue
if test_classification == "vdd":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(1, 2, "wafer_ID")
ws.cell(1, 3, "Die_ID")
ws.cell(1, 4, "X")
ws.cell(1, 5, "Y")
ws.cell(1, 6, "Pin")
row_index = 1
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) == 1:
continue
row_index += 1
pin = line_data[3]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
ws.cell(1, 7, f"{detect_item}({unit})")
ws.cell(row_index, 1, Lot_ID)
ws.cell(row_index, 2, Wafer_ID)
ws.cell(row_index, 3, die)
ws.cell(row_index, 4, Die_dic[die][0])
ws.cell(row_index, 5, Die_dic[die][1])
ws.cell(row_index, 6, pin)
ws.cell(row_index, 7, value)
elif item_start == 0:
continue
if test_classification == "shmoo":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(1, 2, "wafer_ID")
ws.cell(1, 3, "Die_ID")
ws.cell(1, 4, "X")
ws.cell(1, 5, "Y")
ws.cell(1, 6, "Pin")
ws.cell(1, 7, "Voltage(V)")
row_index = 1
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) == 1:
continue
row_index += 1
pin = line_data[3]
voltage = line_data[2].split("_")[-1]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
ws.cell(1, 8, f"{detect_item}({unit})")
ws.cell(row_index, 1, Lot_ID)
ws.cell(row_index, 2, Wafer_ID)
ws.cell(row_index, 3, die)
ws.cell(row_index, 4, Die_dic[die][0])
ws.cell(row_index, 5, Die_dic[die][1])
ws.cell(row_index, 6, pin)
ws.cell(row_index, 7, voltage)
ws.cell(row_index, 8, value)
elif item_start == 0:
continue
if test_classification == "drive":
if "pdrive" in detect_item.casefold():
test_method = f"{supply_voltage}_PDrive"
elif "ndrive" in detect_item.casefold() and "edr1" in detect_item.casefold() and "D33_12" in detect_item:
test_method = f"{supply_voltage}_NDrive_EDR1"
elif "ndrive" in detect_item.casefold() and "D33_12" in detect_item:
test_method = f"{supply_voltage}_NDrive_EDR0"
elif "ndrive" in detect_item.casefold():
test_method = f"{supply_voltage}_NDrive"
if test_method not in locals()[supply_voltage].sheetnames:
ws = locals()[supply_voltage].create_sheet(test_method)
ws.cell(1, 1, "Lot_ID")
ws.cell(2, 1, "wafer_ID")
ws.cell(3, 1, "Die_ID")
ws.cell(4, 1, "X")
ws.cell(5, 1, "Y")
ws.cell(6, 1, "Pin")
ws.cell(7, 1, f"{test_method}(A)")
ws.cell(8, 1, "VDDIO")
ws.cell(8, 2, "PAD")
rate = detect_item.split("_")[-1]
rate_site = rate_site_dict[rate]
if supply_voltage == "D33_12" and "NDrive_EDR1" in test_method:
pin_type_num = 2
elif supply_voltage == "D33_12" and "NDrive" in test_method:
pin_type_num = 5
elif supply_voltage == "D33_12":
pin_type_num = 3
elif supply_voltage == "D18":
pin_type_num = 4
elif supply_voltage == "D5_18":
pin_type_num = 6
else:
pin_type_num = 2
# if supply_voltage == "D33_12" and "NDrive" in test_method:
# rate_type_num = 8
# else:
rate_type_num = 4
total_pin = 0
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
if f"<{detect_item}>" in ''.join(line_data):
item_start = 1
row_index = 9
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) == 1:
continue
total_pin += 1
VDDIO = line_data[2].split("_")[-1]
if "V" not in VDDIO:
VDDIO = f"{VDDIO}V"
PAD = f"{line_data[9]}{line_data[10]}"
pin = line_data[3]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
# EDR类型个数 * pin类型个数 * (die-1)+ 起始位置
column_start = rate_type_num * pin_type_num * (int(die) - 1) + 2
if total_pin % pin_type_num == 0:
column_index = column_start + (rate_site * pin_type_num) + pin_type_num
else:
column_index = column_start + (rate_site * pin_type_num) + total_pin % pin_type_num
ws.cell(row_index, 1, VDDIO)
ws.cell(row_index, 2, PAD)
ws.cell(8, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
if total_pin % pin_type_num == 0:
row_index += 1
elif item_start == 0:
continue
if test_classification == "vi":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(2, 1, "wafer_ID")
ws.cell(3, 1, "Die_ID")
ws.cell(4, 1, "X")
ws.cell(5, 1, "Y")
ws.cell(6, 1, "Pin")
ws.cell(7, 1, f"{detect_item}(V)")
total_pin = 0
if supply_voltage == "D33_12" and "ECOMS" in detect_item:
pin_type_num = 1
elif supply_voltage == "D33_12":
pin_type_num = 5
elif supply_voltage == "D5_18":
pin_type_num = 6
elif supply_voltage == "D18":
pin_type_num = 4
else:
pin_type_num = 2
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
# EDR类型个数 * pin类型个数 * (die-1)+ 起始位置
column_start = pin_type_num * (int(die) - 1) + 1
if f"<{detect_item}>" in ''.join(line_data):
item_start = 1
row_index = 8
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data or "Site" in line_data:
continue
if len(line_data) < 6:
continue
total_pin += 1
# print(line_data)
pin = line_data[3]
voltage = re.split(r"_H|_L", line_data[2])[1]
# print(f"{voltage=} {line_data[2]=}")
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
if total_pin % pin_type_num == 0:
column_index = column_start + pin_type_num
else:
column_index = column_start + total_pin % pin_type_num
ws.cell(row_index, 1, voltage)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
if total_pin % pin_type_num == 0:
row_index += 1
elif item_start == 0:
continue
if test_classification == "pull":
ws = locals()[supply_voltage].create_sheet(detect_item)
ws.cell(1, 1, "Lot_ID")
ws.cell(2, 1, "wafer_ID")
ws.cell(3, 1, "Die_ID")
ws.cell(4, 1, "X")
ws.cell(5, 1, "Y")
ws.cell(6, 1, "Pin")
ws.cell(7, 1, detect_item)
total_pin = 0
if supply_voltage == "D33_12":
pin_type_num = 5
elif supply_voltage == "D18":
pin_type_num = 4
elif supply_voltage == "D5_18":
pin_type_num = 6
else:
pin_type_num = 2
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
# EDR类型个数 * pin类型个数 * (die-1)+ 起始位置
column_start = pin_type_num * (int(die) - 1) + 1
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
row_index = 8
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) < 10:
continue
if "Site" in line_data:
continue
# print(line_data)
total_pin += 1
pin = line_data[3]
voltage = line_data[2].split("_")[-1]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
if "V" in current_unit:
unit = "V"
if "A" in current_unit:
unit = "A"
if total_pin % pin_type_num == 0:
column_index = column_start + pin_type_num
else:
column_index = column_start + total_pin % pin_type_num
ws.cell(row_index, 1, voltage)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
if total_pin % pin_type_num == 0:
row_index += 1
elif item_start == 0:
continue
if test_classification == "function":
if "function_output" in detect_item.casefold():
test_method = f"{supply_voltage}_Function_Output"
elif "function_input" in detect_item.casefold():
test_method = f"{supply_voltage}_Function_Input"
elif "function_input_ecomsh" in detect_item.casefold():
test_method = f"{supply_voltage}_Function_Input_ECOMSH"
elif "od_function_output" in detect_item.casefold():
test_method = f"{supply_voltage}_OD_Function_Output"
elif "od_function_input" in detect_item.casefold():
test_method = f"{supply_voltage}_OD_Function_Input"
if test_method not in locals()[supply_voltage].sheetnames:
ws = locals()[supply_voltage].create_sheet(test_method)
ws.cell(1, 1, "Lot_ID")
ws.cell(2, 1, "wafer_ID")
ws.cell(3, 1, "Die_ID")
ws.cell(4, 1, "X")
ws.cell(5, 1, "Y")
ws.cell(6, 1, "Pin")
ws.cell(7, 1, f"{test_method}(Mhz)")
ws.cell(8, 1, "VDDIO")
ws.cell(8, 2, "PAD")
rate = detect_item.split("_")[-1]
rate_site = rate_site_dict[rate]
if (supply_voltage == "D33_12" and test_method != "D33_12_OD_Function_Input" and test_method != "D33_12_OD_Function_Output")\
or supply_voltage == "D2":
pin_type_num = 5
elif supply_voltage == "D18":
pin_type_num = 6
elif supply_voltage == "D5_18":
pin_type_num = 7
else:
pin_type_num = 4
if test_method == "D33_12_Function_Input_ECOMSH" or test_method == "D33_12_Function_Input" \
or test_method == "D33_12_OD_Function_Input" or test_method == "D12_Function_Input" \
or test_method == "D25_12_Function_Input":
rate_type_num = 1
else:
rate_type_num = 4
total_pin = 0
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
# EDR类型个数 * pin类型个数 * (die-1)+ 起始位置
column_start = rate_type_num * pin_type_num * (int(die) - 1) + 1
test_seq = 0
row_index = 7
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) <= 1:
continue
if detect_item in ''.join(line_data):
test_seq += 1
total_pin += 1
row_index += 1
if "(F)" in line:
result = "Fail"
else:
result = "Pass"
column_index = column_start + (rate_site * pin_type_num) + 1
ws.cell(row_index, 1, test_seq)
ws.cell(7, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, "Result")
ws.cell(row_index, column_index, result)
elif "Id_A" in ''.join(line_data) or "Id_B" in ''.join(line_data) \
or "Id_C" in ''.join(line_data) or "Id_D" in ''.join(line_data):
total_pin += 1
if total_pin % pin_type_num == 0:
column_index = column_start + (rate_site * pin_type_num) + pin_type_num
else:
column_index = column_start + (rate_site * pin_type_num) + total_pin % pin_type_num
pin = line_data[3]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
ws.cell(row_index, 1, test_seq)
ws.cell(7, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
elif "-->" in ''.join(line_data):
# print(line_data)
total_pin += 1
if total_pin % pin_type_num == 0:
column_index = column_start + (rate_site * pin_type_num) + pin_type_num
else:
column_index = column_start + (rate_site * pin_type_num) + total_pin % pin_type_num
pin = line_data[1].split(":")[0]
value = float(re.findall(r'[:](.*?)[H]', line_data[1])[0]) / (1e6)
ws.cell(row_index, 1, test_seq)
ws.cell(7, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
else:
continue
elif item_start == 0:
continue
if test_classification == "function_shmoo":
if "vdd5_shmoo_output" in detect_item.casefold():
test_method = f"{supply_voltage}_VDD5_Shmoo_Output"
elif "vdd5_shmoo_input" in detect_item.casefold():
test_method = f"{supply_voltage}_VDD5_Shmoo_Input"
elif "vdd18_shmoo_output" in detect_item.casefold():
test_method = f"{supply_voltage}_VDD18_Shmoo_Output"
elif "vdd18_shmoo_input" in detect_item.casefold():
test_method = f"{supply_voltage}_VDD18_Shmoo_Input"
if test_method not in locals()[supply_voltage].sheetnames:
ws = locals()[supply_voltage].create_sheet(test_method)
ws.cell(1, 1, "Lot_ID")
ws.cell(2, 1, "wafer_ID")
ws.cell(3, 1, "Die_ID")
ws.cell(4, 1, "X")
ws.cell(5, 1, "Y")
ws.cell(6, 1, "Pin")
ws.cell(7, 1, f"{test_method}(Mhz)")
ws.cell(8, 1, "VDDIO")
ws.cell(8, 2, "PAD")
rate = detect_item.split("_")[-1]
rate_site = rate_site_dict[rate]
if supply_voltage == "D5_18" or supply_voltage == "D2":
pin_type_num = 2
else:
pin_type_num = 4
if supply_voltage == "D5_18" or supply_voltage == "D2":
rate_type_num = 1
else:
rate_type_num = 4
total_pin = 0
with open(openfile1, "r+") as f:
for line in f.readlines():
line_data = line.split()
if r'Device#:' in ' '.join(line_data):
die = int(line_data[1])
print(f"正在处理第{die}颗die的{detect_item}")
# EDR类型个数 * pin类型个数 * (die-1)+ 起始位置
column_start = rate_type_num * pin_type_num * (int(die) - 1) + 1
test_seq = 0
row_index = 7
if "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item in ''.join(line_data):
item_start = 1
elif "<" in ''.join(line_data) and ">" in ''.join(line_data) and detect_item not in ''.join(line_data):
item_start = 0
if item_start == 1:
if "ALARM" in line_data:
continue
if len(line_data) <= 1:
continue
if detect_item in ''.join(line_data):
test_seq += 1
total_pin += 1
row_index += 1
if "(F)" in line:
result = "Fail"
else:
result = "Pass"
column_index = column_start + (rate_site * pin_type_num) + 1
ws.cell(row_index, 1, test_seq)
ws.cell(7, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, "Result")
ws.cell(row_index, column_index, result)
elif "Id_A" in ''.join(line_data) or "Id_B" in ''.join(line_data) \
or "Id_C" in ''.join(line_data) or "Id_D" in ''.join(line_data):
total_pin += 1
column_index = column_start + (rate_site * pin_type_num) + 2
pin = line_data[3]
current_data = line_data[6]
current_unit = line_data[7]
value = unit_conversion(current_data, current_unit)
force = f"{line_data[9]}{line_data[10]}"
ws.cell(row_index, 1, test_seq)
ws.cell(row_index, 2, force)
ws.cell(7, column_index, rate)
ws.cell(1, column_index, Lot_ID)
ws.cell(2, column_index, Wafer_ID)
ws.cell(3, column_index, die)
ws.cell(4, column_index, Die_dic[die][0])
ws.cell(5, column_index, Die_dic[die][1])
ws.cell(6, column_index, pin)
ws.cell(row_index, column_index, value)
else:
continue
elif item_start == 0:
continue
locals()[supply_voltage].save(writefile)
locals()[supply_voltage].close()
最新发布