-
大小: 7KB文件類型: .py金幣: 1下載: 0 次發(fā)布日期: 2021-05-09
- 語(yǔ)言: Python
- 標(biāo)簽: python??tecplot??二次開(kāi)發(fā)??
資源簡(jiǎn)介
使用tecplot的官方接口,實(shí)現(xiàn)二維流場(chǎng)圖自動(dòng)生成,python語(yǔ)言實(shí)現(xiàn)
代碼片段和文件信息
#?coding:?utf-8
import?logging
import?sys
import?os
import?shutil
import?tecplot?as?tp
import?numpy?as?np
import?pyodbc
import?datetime
from?PIL?import?Image
from?tecplot.constant?import?\
????PlotTypeColorValueLocationArrowheadstyleReadDataOption\
????LinePatternVectorTypeBorderLocationEdgeTypeExportRegion
logging.basicConfig(stream=sys.stdout?level=logging.INFO)
#源數(shù)據(jù)文件所在的根路徑
CONFIGPATH?=?‘D:\TecplotData‘
#查看目錄下是否有新的數(shù)據(jù),并保存路徑和時(shí)間信息
filename?=?[]
filelist?=?[]
timelist?=?[]
images?=?[]?#存儲(chǔ)生成的圖片,用于生成GIF
starttime?=?0
filerootpath?=?‘‘
for?dir?in?os.listdir(CONFIGPATH):
????if?os.path.isdir(os.path.join(CONFIGPATHdir)):
????????if?dir.startswith(‘src-‘):
????????????starttime?=?datetime.datetime.strptime(dir[4:]‘%Y-%m-%d‘)
????????????filerootpath?=?os.path.join(CONFIGPATHdir)
????????????for?file?in?os.listdir(os.path.join(CONFIGPATHdir)):
????????????????if?os.path.splitext(file)[1]?==?‘.dat‘:
????????????????????filename.append(int(os.path.splitext(file)[0]))
filename.sort()
for?file?in?filename:
????filelist.append(os.path.join(filerootpath?str(file)+‘.dat‘))
????time?=?starttime?+?datetime.timedelta(seconds=file)
????timelist.append(time.strftime(“%Y-%m-%d?%H:%M:%S“))
#打開(kāi)數(shù)據(jù)庫(kù)連接
cursor?=?conn.cursor()
#對(duì)每個(gè)數(shù)據(jù)文件執(zhí)行tecplot處理過(guò)程
for?i?in?range(len(filelist)):
????#初始化參數(shù)
????infilepath?=?filelist[i]
????time?=?timelist[i]
????#加載數(shù)據(jù)
????tp.data.load_tecplot(infilepathread_data_option=ReadDataOption.Replace)
????#設(shè)置frame、dataset、plot
????frame?=?tp.active_frame()
????dataset?=?frame.dataset
????plot?=?frame.plot(PlotType.Cartesian2D)
????plot.activate()
????#連接數(shù)據(jù)庫(kù),查詢興趣點(diǎn)POI坐標(biāo),查找對(duì)應(yīng)的屬性值
????cursor.execute(‘select?IDXY?from?hhg_poipoint‘)
????rows?=?cursor.fetchall()
????insertValues?=?[]
????for?row?in?rows:
????????probeat?=?tp.data.query.probe_at_position(row.X?row.Y)
????????value?=?dataset.VariablesNamedTuple(*probeat.data)
????????insertValues.append((row.ID?time?value.bn?value.d?value.u?value.v))
????#保存POI值到數(shù)據(jù)庫(kù)
????
????conn.commit()
????#添加文字--不支持中文
????frame.add_text(time?(2.31406?96.4344)?bold=True)
????frame.add_text(‘CaoFeidian‘(45.3899?86.2237)?bold=True)
????frame.add_text(‘TiJin‘(9.66144?74.8784)?bold=True)
????frame.add_text(‘HuangHua‘(10.958?23.5008)?bold=True)
????frame.add_text(‘BinZhou‘(35.8815?8.10373)?bold=True)
????frame.add_text(‘1m/s‘(2.6022?4.86224)?bold=True)
????#設(shè)置坐標(biāo)軸、視窗
????????#x軸
????xaxis?=?plot.axes.x_axis
????xaxis.title.show?=?False
????xaxis.ticks.show?=?False
????xaxis.tick_labels.show?=?False
????xaxis.min?=?539555.567504
????xaxis.max?=?691335.966177
????????#y軸
????yaxis?=?plot.axes.y_axis
????yaxis.title.show?=?False
????yaxis.ticks.show?=?False
????yaxis.tick_labels.show?=?False
????yaxis.min?=?4209133.69477
????yaxis.max?=?4347647.3623
????????#視窗
????plot.axes.viewport.left?=?0
????plot.axes.viewport.right?=?100
????plot.axes.viewport.top?=?100
????plot.axes.viewport.bottom?=?0
???
評(píng)論
共有 條評(píng)論