我正在对CFD数据进行后期处理(对坐标应用旋转)。为此,我做了以下工作:
-读取文件
-将数据存储到结构化数组中
-操作数据(进行计算)
-写入新文件
它可以工作,但每个文件需要7秒。我还有(15000*4)个文件要处理。。。你知道吗
for i in range(0,len(file_count)):
#Source folder with original files
os.chdir(path+'\\'+folder_source_location)
#Generate file names
file_name = file_source_begin+("%0"+str(ndigit)+"d") % file_count[i]+"_tec.dat"
#Read the file
Data = read_tecUNS(file_name)
#New data set modified
Data_new = Data
#Translation
Data["node"]["X"]+=translator_plane2RotCenter[0] #The += is important or the Data won't be affected by the translation
Data["node"]["Y"]+=translator_plane2RotCenter[1]
Data["node"]["Z"]+=translator_plane2RotCenter[2]
#Rotation
Y_temp = Data["node"]["Y"]*cos(theta_rot_rad)-Data["node"]["Z"]*sin(theta_rot_rad)
Z_temp = Data["node"]["Y"]*sin(theta_rot_rad)+Data["node"]["Z"]*cos(theta_rot_rad)
Data_new["node"]["Y"]=Y_temp
Data_new["node"]["Z"]=np.mean(Z_temp) #Due to rounding, the Z values are not exactly the same. The mean avoid that.
#Write the new file
os.chdir(path+'\\'+folder_source_location+'\\'+"Output")
write_tecplot(file_name,Data_new)
你有什么改进的办法吗?我曾考虑过将文字穿插进去,但我不确定这是否会有什么改进。你知道吗
下面是一个读取/计算/写入时间的示例:
The output folder already exists. The data in it will be erased
StartReading B--0.000018_tec.dat in progress. - 0.001s elapsed
EndReading B--0.000018_tec.dat in progress. - 0.433s elapsed
StartWriting B--0.000018_tec.dat in progress. - 0.435s elapsed
EndWriting B--0.000018_tec.dat in progress. - 7.585s elapsed
StartReading B--0.000036_tec.dat in progress. - 7.586s elapsed
EndReading B--0.000036_tec.dat in progress. - 7.697s elapsed
StartWriting B--0.000036_tec.dat in progress. - 7.697s elapsed
EndWriting B--0.000036_tec.dat in progress. - 13.472s elapsed
还有脚本和一个样本,让你更鲁莽地尝试一下:
http://s000.tinyupload.com/index.php?file_id=80589646527340633700
问题不在于写入本身,而在于如何为写入准备和格式化数据。你知道吗
如果您使用
python -m cProfile -s cumtime Plane_modifier_rev4-multiple_files.py > out.txt
之类的工具来分析脚本,您将看到大部分时间都花在数组格式化上例如
这个
可以像这样重写(而且必须更快)
编辑
写技术上的一些变化
相关问题 更多 >
编程相关推荐