def load_layout_save(layout_path,save_path,annotation=''): """ Load a layout and save the image. Option to add an annotation in the upper left corner of the figure. Useful when the layout references a file with relative paths. E.G. if the layout loads a file called "./data.plt" then you can copy the layout into any directory which has a file named "./data.plt". Then use this function to make a plot of that data. The function will save images as EPS or PNG depending on the file extension used in save_path. The default is PNG. Keyword Arguments --- layout_path: the path to the layout file save_path : the pathname of the image to save annotation : (optional) a string which will be printed in the upper left corner of the plot """ tecplot.load_layout(layout_path) frame = tecplot.active_frame() frame.add_text(annotation,position=(7,93), size=20) ext = save_path.split('.')[-1] if ext == 'eps': tecplot.export.save_eps(save_path) else: tecplot.export.save_png(save_path,width=1200,supersample=8) print('Saved '+save_path)
def initialize_process(layout_file): # !!! IMPORTANT !!! # Must register stop at exit to ensure Tecplot cleans # up all temporary files and does not create a core dump atexit.register(tp.session.stop) # Set the Load-On-Demand strategy to minimize memory use to keep the RAM low tp.macro.execute_command( "$!FileConfig LoadOnDemand { UNLOADSTRATEGY = MinimizeMemoryUse }") tp.load_layout(layout_file)
def generateinterpolatedGrid(layfile, numpoints, coords): """ Function to create and save an interpolated tecplot simulation grid for radio emission calculation This will only work with Tecplot 360 installed on your system. :param layfile: Tecplot .lay file to be interpolated :param numpoints: Number of points in each spatial dimension :param coords: Size of the grid in Rstar :return: """ cwd = os.getcwd() tp.load_layout(layfile) frame1 = tp.active_frame() cur_dataset = frame1.dataset zone1 = cur_dataset.zone( 0) # zone1 is what tecplot uses for plotting in the layfile tp.macro.execute_command('''$!CreateRectangularZone IMax = {0:} JMax = {0:} KMax = {0:} X1 = -{1:} Y1 = -{1:} Z1 = -{1:} X2 = {1:} Y2 = {1:} Z2 = {1:} XVar = 1 YVar = 2 ZVar = 3'''.format(numpoints, coords)) zone2 = cur_dataset.zone(1) # name second zone for interpolation tp.data.operate.interpolate_linear(zone2, source_zones=zone1, variables=[3, 10, 22]) # create second zone and fill with variables tp.data.save_tecplot_ascii( cwd + '/interpol_grid_{0:}Rstar_{1:}points.dat'.format(coords, numpoints), zones=[zone2], variables=[0, 1, 2, 3, 10, 22], include_text=False, precision=9, include_geom=False, use_point_format=True) return
from os import path import tecplot as tp from tecplot.constant import LinePattern, Color examples_dir = tp.session.tecplot_examples_directory() datafile = path.join(examples_dir, 'SimpleData', 'Sphere.lpk') dataset = tp.load_layout(datafile) plot = tp.active_frame().plot() plot.axes.grid_area.fill_color = Color.Grey for axis in (plot.axes.x_axis, plot.axes.y_axis): axis.show = True #{DOC:highlight}[ grid_lines = axis.grid_lines grid_lines.show = True grid_lines.line_pattern = LinePattern.LongDash grid_lines.color = Color.Cyan #] plot.view.fit() tp.export.save_png('grid_lines.png', 600, supersample=3)
default=1024) parser.add_argument("-supersample", help="Supersample factor to use for image export", type=int, default=2) parser.add_argument("-imagebasename", help="Basename for exported PNG images", default="image") args = parser.parse_args() # Get the solution times over which to iterate. Stop PyTecplot in # the main process to free up the license for the workers. PyTecplot # cannot be restarted once stopped! tp.new_layout() tp.load_layout(args.layoutfile) solution_times = tp.active_frame().dataset.solution_times tp.session.stop() # !!! IMPORTANT !!! # On Linux systems, Python's multiprocessing start method # defaults to "fork" which is incompatible with PyTecplot # and must be set to "spawn" multiprocessing.set_start_method('spawn') # Set up the pool with initializing function and associated arguments pool = multiprocessing.Pool(processes=args.numprocs, initializer=initialize_process, initargs=(args.layoutfile, )) try:
from os import path import numpy as np import tecplot as tp # load layout examples_dir = tp.session.tecplot_examples_directory() example_layout = path.join(examples_dir, 'SimpleData', '3ElementWing.lpk') tp.load_layout(example_layout) frame = tp.active_frame() #{DOC:highlight}[ levels = frame.plot().contour(0).levels levels.reset_levels(np.linspace(55000, 115000, 61)) #] # save image to file tp.export.save_png('contour_adjusted_levels.png', 600, supersample=3)
from os import path import tecplot as tp from tecplot.constant import Color examples_dir = tp.session.tecplot_examples_directory() infile = path.join(examples_dir, 'SimpleData', 'Sphere.lpk') dataset = tp.load_layout(infile) frame = tp.active_frame() plot = frame.plot() #{DOC:highlight}[ plot.axes.orientation_axis.position = 15, 15 plot.axes.orientation_axis.color = Color.BrightCyan #] plot.axes.reset_range() plot.view.fit() tp.export.save_png('axes_orientation.png', 600, supersample=3)
cwd = os.getcwd().split('/')[-1] print('CurrentFolder : %s' % (cwd, )) infiles = glob.glob('*/*T*.lay', recursive=True) infiles = [i for i in infiles if 'VibDistT=10000.lay' not in i] infiles = [os.path.join(cwd, i) for i in infiles] infiles = [i for i in infiles if 'DissRatesNonEq_O2-O' not in i] Temperature = [re.search('T[=_]?(\d+)', i).group(1) for i in infiles] outfiles = [ os.path.join(os.path.dirname(i), 'T=' + j + '.eps') for i, j in zip(infiles, Temperature) ] for infile, outfile in zip(infiles, outfiles): tp.load_layout(infile) frame = tp.active_frame() plt = frame.plot() for lmapid in plt.active_linemap_indices: lmap = plt.linemap(lmapid) zonename = lmap.zone.name line = lmap.line if 'ROT' in zonename or 'rot' in zonename: print(zonename) line.color = Color.Green line.line_pattern = LinePattern.LongDash line.pattern_length = 0.8 elif 'MF' in zonename: print(zonename + ' 2') line.color = Color.Blue line.line_pattern = LinePattern.Dashed
except TecplotLogicError: # It is a logic error when acquiring license when # already connected to Tecplot 360 TecUtil Server if not tecplot.session.connected(): raise except TecplotError: logging.exception('Could not initialize pytecplot') exit(1) examples_dir = tecplot.session.tecplot_examples_directory() infile = os.path.join(examples_dir, 'SimpleData', 'SpaceShip.lpk') outfile = 'spaceship.png' try: logging.info('Opening layout file: ' + infile) tecplot.load_layout(infile) logging.info('Exporting Image: ' + outfile) tecplot.export.save_png(outfile, 600, supersample=3) logging.info('Finished, no errors') except IOError: logging.debug("I/O Error: Check disk space and permissions") except TecplotSystemError: logging.exception('Failed to export image: ' + outfile) finally: # tecplot.session.stop() may be called manually to # shut down Tecplot and release the license. # If tecplot.session.stop() is not called manually # it will be called automatically when the script exits.
command = r'''#!MC 1410 $!PRINTSETUP PALETTE = COLOR $!EXPORTSETUP EXPORTFNAME = "%s" $!EXPORTSETUP EXPORTFORMAT = EPS $!EXPORT EXPORTREGION = CURRENTFRAME ''' % (filename, ) # print(command) tecplot.macro.execute_command(command) ## Export equilibrium reaction rates infiles = [ "N2N2.lay", ] name = [os.path.basename(i) for i in infiles] outfiles = [ os.path.join("/home/Figure", i.replace(".lay", "_EqRate.eps")) for i in name ] outfiles2 = [ os.path.join("/home/Draft/Figs", i.replace(".lay", "_EqRate.eps")) for i in name ] for i, j in enumerate(infiles): tecplot.load_layout(j) save_eps(outfiles[i]) shutil.copyfile(outfiles[i], outfiles2[i])
import os import numpy as np import tecplot from tecplot.constant import * # By loading a layout many style and view properties are set up already examples_dir = tecplot.session.tecplot_examples_directory() datafile = os.path.join(examples_dir, 'SimpleData', 'RainierElevation.lay') tecplot.load_layout(datafile) frame = tecplot.active_frame() plot = frame.plot() # Rename the elevation variable frame.dataset.variable('E').name = "Elevation (m)" # Set the levels to nice values plot.contour(0).levels.reset_levels(np.linspace(200,4400,22)) #{DOC:highlight}[ legend = plot.contour(0).legend legend.show = True legend.vertical = False # Horizontal legend.auto_resize = False legend.label_step = 5 legend.overlay_bar_grid = False legend.position = (55, 94) # Frame percentages legend.box.box_type = TextBox.None_ # Remove Text box
filenames_dir = listdir(dir_in) filenames_out_list = [] ## Process lay files for filename_dir in filenames_dir: if '.lay' in filename_dir: f = open(dir_in + filename_dir, 'r') lay_old = f.read() f.close() lay_new = lay_old for data_old, data_new in filename_data.iteritems(): lay_new = lay_new.replace(data_old, data_new) if replaced: filename_new = dir_out + filename_dir else: filename_new = dir_out + filename_dir[: -4] + '_new' + filename_dir[ -4:] filenames_out_list.append(filename_new) f_new = open(filename_new, 'w') f_new.write(lay_new) f_new.close() ## generate .png files if export_png: import tecplot as tp import logging logging.basicConfig(level=logging.INFO) for filename in filenames_out_list: dset = tp.load_layout(filename) tp.export.save_png(filename.replace('.lay', '.png'))
import os import tecplot as tp frame = tp.active_frame() examples = tp.session.tecplot_examples_directory() layoutfile = os.path.join(examples, 'SimpleData', 'F18.lay') #{DOC:highlight}[ tp.load_layout(layoutfile) #] # frame object is no longer usable. # the following will print: # <class 'ValueError'> 255 is not a valid PlotType try: frame.plot_type except Exception as e: print(type(e), e)