Commit 08e89627 authored by Qusai Al Shidi's avatar Qusai Al Shidi 💬
Browse files

Merge branch 'cdha/swmfpy-tecplottools'

parents 8981fcdb 63a40aa0
# author: Camilla D. K. Harris
# email:
Visualization of SWMF output with Tecplot
To be completed.
Generating Tecplot-readable output
- summary of tecplot functionality in #SAVEPLOT command
- brief note on szplt file type, how to create them, and the szplt server tool
for HPC/linux systems
Using pytecplot
The pytecplot documentation can be found at Tecplot and pytecplot require a valid
Tecplot 360 license to use.
The latest version of pytecplot can be installed with `pip install pytecplot`.
Linux and Windows users should consult the appropriate sections of the
pytecplot documentation (
for further details; the rest of this section pertains to MacOS users.
MacOS users running python scripts which use pytecplot can connect to the
Tecplot engine either through a running instance of the Tecplot GUI or
automatically by setting the appropriate environment variable.
To connect a script to a running instance of Tecplot, open the Tecplot GUI.
Select `Scripting > PyTecplot Connections...` from the drop-down menus to open
the PyTecplot Connections dialog. Then tick the box to `Accept connections` from
the port number of your choice. Then in your python script add the following
line immediately after your import statements:
import tecplot
Be sure that the port numbers match.
In the command line you will be able to run your script:
And the effects will be mirrored in the GUI.
To run a script without connecting to a running instance of Tecplot requires
setting the `DYLD_LIBRARY_PATH` environment variable so that it references the
Tecplot libraries. However, it is not recommended to set this variable
permanently as this will cause severe conflicts with other applications. Tecplot
provides their own recommendations for temporarily setting the environment
variable ( but a simple
solution is as follows:
Add the following line to your `.bash_profile` or `.bashrc` file:
alias runpytecplot='env DYLD_LIBRARY_PATH="/Applications/Tecplot 360 EX 2019 R1/Tecplot 360 EX 2019"'
Be sure to replace `2019 R1` with the appropriate version and check that the
path is valid on your system. Then your script can be run like so:
runpytecplot python
\ No newline at end of file
......@@ -13,6 +13,8 @@ These are automatically imported.
- `` Tools used in swmfpy. You might find these useful but it is
- `swmfpy.tecplottools` Tools for working with the Tecplot visualization
software. Requires a Tecplot license and the pytecplot python package.
__author__ = 'Qusai Al Shidi'
__license__ = 'MIT'
......@@ -24,6 +26,7 @@ __email__ = ''
import sys
from . import paramin
from . import io
from . import tecplottools
from . import web
assert sys.version_info >= (3, 6), "swmfpy requires Python >=3.6. Sorry :(."
#!/usr/bin/env python
"""Tools for working with the Tecplot visualization software.
Requires an active Tecplot license and the pytecplot python package.
pytecplot ships with Tecplot 360 2017 R1 and later versions
but it is recommended that you install the latest version with
`pip install pytecplot`.
See the pytecplot documentation for more details about
See also [TECPLOT](TECPLOT.markdown) for tips targeted to SWMF users.
Some useful references:
- [Tecplot User's Manual](
- [Tecplot Scripting Guide](
- [Pytecplot documentation](
__all__ = [
__author__ = 'Camilla D. K. Harris'
__email__ = ''
import tecplot
def apply_equations(eqn_path: str, verbose: bool = False):
"""Apply an equations file in the Tecplot macro format to the active dataset
Please reference the Tecplot User's Manual for more details on
equation files and syntax. It is recommended to use this function with eqn
files generated with the Tecplot GUI.
See [TECPLOT](TECPLOT.markdown) for tips on using pytecplot.
eqn_file_path (str): The path to the equation macro file (typically with
extension `.eqn`).
verbose (bool): (Optional) Whether or not to print the equations as they are
applied. Default behavior is silent.
import tecplot
import swmfpy.tecplottools as tpt
## Uncomment this line if you are connecting to a running tecplot
## session. Be sure that the port number matches the port the GUI is
## listening to. See TECPLOT.markdown for tips on connecting to a
## running session or running your script seperately.
## load a dataset
dataset ='./z=0_mhd_1_n00000000.plt')
## apply an equations file
tpt.apply_equations('./gse_to_ephio.eqn', verbose= True)
## apply a frame style
frame = tecplot.active_frame()
## annotate with the zone name
frame.add_text('&(ZONENAME[ACTIVEOFFSET=1])', position= (5, 95))
## save the image
tecplot.export.save_png('./density.png', width= 1200, supersample= 8)
if verbose:
with open(eqn_path, 'r') as eqn_file:
for line in eqn_file:
if line[0] == ' ':
eqnstr = line.split("'")[1]
if verbose:
if verbose:
print('Successfully applied equations.')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment