我有一个来自STDF文件格式的数据,它是测试半导体制造行业使用的机器输出文件格式,我需要读取python中的文件,分析机器输出停机时间和上载在Github和其他平台中寻找解决方案的文件中的其他细节,python中没有没有bug的模块,也没有适当的文档来实现现有模块的代码。
发布于 2022-08-19 00:47:12
我建议皮斯杜夫。
根据我的经验,这个库完全没有bug,尽管在大文件上性能有点慢。为了数据分析的目的,你仍然需要理解和整理所有的记录。
下面的示例使用(此片段将多个stdf文件读取到熊猫的每种记录类型的数据中)。
import os
import pandas as pd
from io import StringIO
import pystdf.V4 as v4
from pystdf.IO import Parser
from pystdf.Writers import TextWriter
def stdf_to_dfs(filelist):
''' Takes a list of stdf files, and returns individual dataframes for each record type, separated per file.
Also, prepends the line number from the atdf (as well as the source file).'''
record_dfs = {}
for file in filelist:
filename = os.path.basename(file)
p = Parser(inp=open(file, 'rb'))
captured_std_out = StringIO()
p.addSink(TextWriter(captured_std_out))
p.parse()
atdf = captured_std_out.getvalue()
# prepend line number and source file name to captured_std_out so it can be sorted later
# line number is 2nd field... 1st field is record_type
atdf = atdf.split('\n')
for n, l in enumerate(atdf):
atdf[n] = l[:4] + str(n) + '|' + filename + '|' + l[4:]
# read each record type into a seperate dataframe
for record_type in v4.records:
record_name = record_type.name.split('.')[-1].upper()
curr = [line for line in atdf if line.startswith(record_name)]
curr = '\n'.join(curr)
if curr not in '':
header_names = ['Record', 'LineNum', 'SourceFile'] + list(list(zip(*record_type.fieldMap))[0])
if record_name not in record_dfs:
record_dfs[record_name] = pd.DataFrame()
record_dfs[record_name] = pd.concat([record_dfs[record_name], pd.read_csv(
StringIO(curr), header=None, names=header_names, delimiter='|')])
# drop empty record dataframes
record_dfs = {k: v for k, v in record_dfs.items() if (v is not None)}
return record_dfs发布于 2022-08-12 11:55:12
我编写了一个商业模块STDF QuickChange,它将把STDF转换成更有用的格式,比如CSV。主输出格式每个单元有一行,每个测试有一列。它不是python,但是您可以从python执行它,然后用python加载csv。如果您正在加载数据模拟数据,并且也需要限制,则有一些选项可以将限制存储在第一行中。
https://stackoverflow.com/questions/72897110
复制相似问题