How can I optimize my PyTecplot scripts? This blog can help you optimize your PyTecplot scripts using best practices.
1. Debug in Connected and Use Python Optimize in Production
PyTecplot is a unique plotting package. You not only get a fully functional script from recording, but you can run the script to drive the Tecplot 360 user interface. Seeing your results in Tecplot 360 can help you debug issues with your script more easily. You can debug your scripts in connected mode, or run them in batch mode with Python optimized mode, “-O”.
Example: allow interaction of script with GUI
if '-c' in sys.argv:
Once your script is ready for production, running in batch mode with -O will improve the run time.
Example: optimize the run time
2. Use the tp.session.suspend() Context
When running PyTecplot connected to the Tecplot 360 user interface, the GUI reacts to your script, updating the GUI as the script is played. This can be good if you want to see how the script is progressing, however there is a significant performance penalty.
You can limit the interaction of the script with the GUI by using the tp.session.suspend() context.
Example: limit the interaction of the script with the GUI
#Perform your actions
Using tp.session.suspend() will also improve performance when running batch scripts, but the performance improvements are not as significant.
3. Get and Set Data Variables as Arrays
PyTecplot allows you to access the raw data stored in Tecplot 360. Not only can you access the data, but you can modify it as well. When accessing data, operate on the whole array with [:] instead of value by value.
Example: normalize the values of a variable
wing_pressure = frame.dataset().zone(“wing”).values(“Pressure”)
data = wing_pressure[:]
# Normalize the values
data = (data – min(data)) / (max(data) – min(data))
# Set the values for the Pressure variable in the zone named ‘wing’
wing_pressure[:] = data
4. Install Numpy
Numpy (https://numpy.org/) is a Python package used for fast and efficient storage and modification of multi-dimensional data. If numpy is installed, PyTecplot will take advantage of numpy operations to improve performance.
Example: install numpy
5. Update PyTecplot Frequently and Subscribe
PyTecplot is pushed to PyPi installers frequently with new functions and performance updates.
Get PyTecplot (Tecplot 360) Updates
Get notified by email when PyTecplot and Tecplot 360 are released.