资源简介

使用tecplot的官方接口,实现二维流场图自动生成,python语言实现

资源截图

代码片段和文件信息

# 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)
#源数据文件所在的根路径
CONFIGPATH = ‘D:\TecplotData‘
#查看目录下是否有新的数据,并保存路径和时间信息
filename = []
filelist = []
timelist = []
images = [] #存储生成的图片,用于生成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“))
#打开数据库连接

cursor = conn.cursor()
#对每个数据文件执行tecplot处理过程
for i in range(len(filelist)):
    #初始化参数
    infilepath = filelist[i]
    time = timelist[i]
    #加载数据
    tp.data.load_tecplot(infilepathread_data_option=ReadDataOption.Replace)
    #设置frame、dataset、plot
    frame = tp.active_frame()
    dataset = frame.dataset
    plot = frame.plot(PlotType.Cartesian2D)
    plot.activate()
    #连接数据库,查询兴趣点POI坐标,查找对应的属性值
    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值到数据库
    
    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)
    #设置坐标轴、视窗
        #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
   

评论

共有 条评论