Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

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: cdha@umich.edu
Visualization of SWMF output with Tecplot
=========================================
To be completed.
Generating Tecplot-readable output
----------------------------------
- summary of tecplot functionality in #SAVEPLOT command
- use of #SAVETECPLOT and #SAVETECPLOTBINARY commands
- 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
https://www.tecplot.com/docs/pytecplot/. 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 (https://www.tecplot.com/docs/pytecplot/install.html)
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:
```python
import tecplot
tecplot.session.connect(port=7600)
...
```
Be sure that the port numbers match.
In the command line you will be able to run your script:
```bash
python my_pytecplot_script.py
```
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 (https://www.tecplot.com/docs/pytecplot/install.html#id22) but a simple
solution is as follows:
Add the following line to your `.bash_profile` or `.bashrc` file:
```bash
alias runpytecplot='env DYLD_LIBRARY_PATH="/Applications/Tecplot 360 EX 2019 R1/Tecplot 360 EX 2019 R1.app/Contents/MacOS/"'
```
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:
```bash
runpytecplot python my_pytecplot_script.py
```
\ No newline at end of file
......@@ -13,6 +13,8 @@ These are automatically imported.
- `swmfpy.tools` Tools used in swmfpy. You might find these useful but it is
unecessary.
- `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__ = 'qusai@umich.edu'
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
[installation](https://www.tecplot.com/docs/pytecplot/install.html).
See also [TECPLOT](TECPLOT.markdown) for tips targeted to SWMF users.
Some useful references:
- [Tecplot User's Manual](download.tecplot.com/360/current/360_users_manual.pdf)
- [Tecplot Scripting Guide](download.tecplot.com/360/current/360_scripting_guide.pdf)
- [Pytecplot documentation](www.tecplot.com/docs/pytecplot/index.html)
"""
__all__ = [
'apply_equations'
]
__author__ = 'Camilla D. K. Harris'
__email__ = 'cdha@@umich.edu'
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.
Args:
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.
Examples:
```python
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.
#tecplot.session.connect(port=7600)
## load a dataset
dataset = tecplot.data.load_tecplot('./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()
frame.load_stylesheet('./density.sty')
## 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:
print('Executing:')
with open(eqn_path, 'r') as eqn_file:
for line in eqn_file:
if line[0] == ' ':
eqnstr = line.split("'")[1]
tecplot.data.operate.execute_equation(eqnstr)
if verbose:
print(eqnstr)
if verbose:
print('Successfully applied equations.')
Markdown is supported
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