SCR截面速度、氨氮比等标准及相对标准偏差计算
"""
联系QQ:3123575367,专业SCR脱硝仿真。
Created on Wed Sep 20 20:40:30 2023
该程序用来处理fluent通过xyplot导出的数据,可计算标准偏差SD、相对标准偏差RSD,适用于求解平面的相对均匀度
@author: PS
"""
"""
Created on Wed Sep 20 20:40:30 2023
该程序用来处理fluent通过xyplot导出的数据,可计算标准偏差SD、相对标准偏差RSD,适用于求解平面的相对均匀度
@author: PS
"""
import chardet
def check_code(text):
with open(text, 'rb') as f:
adchar = chardet.detect(f.read())
if adchar['encoding'] == 'gbk' or adchar['encoding'] == 'GBK' or adchar['encoding'] == 'GB2312':
return 'GB2312'
else:
return 'utf-8'
def read_file_text(file_url):
with open(file_url, 'r',encoding=check_code(file_url)) as f0:
row_nul = 4
for i in range(row_nul):
next(f0)
f0_word = f0.readlines()
ls = []
x=[]
y=[]
for line in f0_word:
line = line.strip('\n')
line = line.replace(')','')
words = line.split()
ls.append(words)
for lin in ls:
for l in range(len(lin)):
lin[l] = lin[l].strip('(')
while '' in lin:
lin.remove('')
if lin == ls[-1]:
break
x.append(float(lin[0]))
y.append(float(lin[1]))
mean = sum(y)/len(y)
qh =[]
for num in y:
qh.append(pow(num-mean,2))
qv = pow(sum(qh)/(len(qh)-1),0.5)
cv = qv/mean
print('+++++++未操作数据 +++++++')
print(f'平均值为:{round(mean,4)}')
print(f'标准偏差(SD)为:{round(qv*100,4)} %\n相对标准偏差(RSD)为:{round(cv*100,4)} %')
y_no_zero = [i for i in y if i!= 0]
mean_no_zero = sum(y_no_zero)/len(y_no_zero)
qh_no_zero = [pow(num-mean_no_zero,2) for num in y_no_zero]
qv_no_zero = pow(sum(qh_no_zero)/(len(qh_no_zero)-1),0.5)
cv_no_zero = qv_no_zero/mean_no_zero
print('------------去除 0 数据------------')
print(f'平均值为:{round(mean_no_zero,4)}')
print(f'标准偏差(SD)为:{round(qv_no_zero*100,4)} %\n相对标准偏差(RSD)为:{round(cv_no_zero*100,4)} %')
read_file_text(r'F:\20231230-scr-1.2\1231\5000\n1.xy')
+++++++未操作数据 +++++++
标准偏差(SD)为:103.293 %
相对标准偏差(RSD)为:29.7022 %
------------去除 0 数据------------
标准偏差(SD)为:32.7746 %
相对标准偏差(RSD)为:8.7266 %
计算公式见:
适用于fluent通过该途径导出的文件处理。