cape.filecntl.tecplot: Interface to Tecplot scripts¶
This is a module built off of the cape.filecntl module customized for
manipulating Tecplot layout files and macros.
It allows users to edit quantities of any layout command in addition to
declaring and adding layout variables. In addition, the ExportLayout()
function provides a utility to open a layout using Tecplot in batch mode to
export an image.
The class provides two classes, the first of which is the generic version typically used for layout files. The second class has a few extra methods for handling Tecplot macros specifically.
cape.filecntl.tecplot.Tecsript
- See also:
- cape.filecntl.tecplot.ExportLayout(lay='layout.lay', fname='export.png', fmt='PNG', **kw)¶
Stand-alone function to open a layout and export an image
- Call:
>>> ExportLayout(lay="layout.lay", fname="export.png", **kw)
- Inputs:
- lay: {
"layout.lay"} |str Name of Tecplot layout file
- fname: {
"export.png"} |str Name of image file to export
- fmt: {
"PNG"} |"JPEG"|str Valid image format for Tecplot export
- w: {
None} |float Image width in pixels
- clean: {
True} |False Clean up extra files
- v, verbose: {
True} |False Option to display information about shell command
- lay: {
- Versions:
2015-03-10
@ddalle: Version 1.02022-09-01
@ddalle: Version 1.1; add clean
- class cape.filecntl.tecplot.TecMacro(fname='export.mcr')¶
File control class for Tecplot macr files
- Call:
>>> tec = pyCart.tecplot.TecMacro() >>> tec = pyCart.tecplot.TecMacro(fname="export.mcr")
- Inputs:
- fname:
str Name of Tecplot script to read
- fname:
- Outputs:
- tec:
cape.filecntl.tecplot.TecMacro Instance of Tecplot macro interface
- tec:
- Versions:
2015-03-10
@ddalle: First version
- SetExportFileName(fname='export.png')¶
Set the name of the exported image file
- Call:
>>> tec.SetExportFileName(fname="export.png")
- Inputs:
- tec:
cape.filecntl.tecplot.TecMacro Instance of Tecplot macro interface
- fname:
str Export image file name
- tec:
- Versions:
2015-03-10
@ddalle: First version
- SetExportFormat(fmt='PNG')¶
Set Tecplot macro export format
- Call:
>>> tec.SetExportFormat(fmt="PNG")
- Inputs:
- tec:
cape.filecntl.tecplot.TecMacro Instance of Tecplot macro interface
- fmt:
str Export format
- tec:
- Versions:
2015-03-10
@ddalle: First version
- SetImageWidth(w=1024)¶
Set the export image width
- Call:
>>> tec.SetImageWidth(w=1024)
- Inputs:
- tec:
cape.filecntl.tecplot.TecMacro Instance of Tecplot macro interface
- w:
int Image width in pixels
- tec:
- Versions:
2015-03-10
@ddalle: First version
- SetLayout(lay='layout.lay')¶
Set the Tecplot layout file name
- Call:
>>> tec.SetLayout(lay="layout.lay")
- Inputs:
- tec:
cape.filecntl.tecplot.TecMacro Instance of Tecplot macro interface
- lay:
str Tecplot layout file name
- tec:
- Versions:
2015-03-10
@ddalle: First version
- class cape.filecntl.tecplot.Tecscript(fname='layout.lay')¶
File control class for Tecplot script files
- Call:
>>> tec = cape.filecntl.tecplot.Tecscript() >>> tec = cape.filecntl.tecplot.Tecscript(fname="layout.lay")
- Inputs:
- fname:
str Name of Tecplot script to read
- fname:
- Outputs:
- tec:
pyCart.tecplot.Tecscript Instance of Tecplot script base class
- tec:
- Versions:
2015-02-26
@ddalle: Started2015-03-10
@ddalle: First version
- ConvertToVal(val)¶
Convert a text string to a scalar Python value
- Call:
>>> v = tec.ConvertToval(val)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script interface
- val:
str|unicode Text of the value from file
- tec:
- Outputs:
- Versions:
2017-01-05
@ddalle: First version
- DeleteCommand(cmd, txt=None, lines=None)¶
Delete text for a specific command or commands and update text
- Call:
>>> kcmd = tec.DeleteCommand(cmd, txt=None, lines=None)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to delete
- txt:
str Regular expression for text after the command
- lines:
list[str] Additional lines to filter for (regular expressions)
- tec:
- Outputs:
- kcmd:
int Index of earliest deleted command or
Noneif no deletions
- kcmd:
- Versions:
2015-03-10
@ddalle: First version
- DeleteCommandN(cmd, n=0)¶
Delete the nth instance of a command
- Call:
>>> kcmd = tec.DeleteCommandN(cmd, n=0)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to delete
- n: {
0} |int>= 0 Instance of command to delete
- tec:
- Outputs:
- kcmd:
int Index of deleted command or
Noneif no deletions
- kcmd:
- Versions:
2016-10-05
@ddalle: First version
- EditColorMap(name, cmap, vmin=None, vmax=None, **kw)¶
Replace the contents of a color map
- Call:
>>> tec.EditColorMap(name, cmap, vmin=None, vmax=None, **kw) >>> tec.EditColorMap(name, {f0:c0, f1:c1, f2:c2, ...}, ... )
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script
- cmap:
dict(list) Dictionary of color map fractions and colors
- f0:
float Level for the first color, either 0 to 1 or vmin to vmax
- c0:
str|list Either color name, hex code, or RGB list
- vmin: {
None} |float Minimum value to use for determining COLORMAPFRACTION values
- vmax: {
None} |float Maximum value to use for determining COLORMAPFRACTION values
- nContour: {
None} |int Global contour number to edit
- nColorMap: {
None} |int Number of color map to edit
- tec:
- Versions:
2017-01-05
@ddalle: First version
- GetCommand(cmd, n=0)¶
Get the start and end line numbers in the nth instance of cmd
This allows the user to get the lines of text in the command to be
tec.lines[ibeg:iend].- Call:
>>> ibeg, iend = tec.GetCommand(cmd, n=0)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to find
- n: {
0} |None|int>= 0 Instance of command to find; if
Nonereturn all
- tec:
- Outputs:
- Versions:
2017-10-05
@ddalle: First version
- GetCommandByKey(cmd, key, val)¶
Search for a command based on a key and value
- Call:
>>> ibeg, iend = tec.GetCommandByKey(cmd, key, val)
- Inputs:
- Outputs:
- Versions:
2017-10-05
@ddalle: First version
- GetCommandByPar(cmd, val)¶
Search for a command based on name and parameter
A ‘parameter’ is a value printed on the same line as the command name
- Call:
>>> ibeg, iend = tec.GetCommandByPar(cmd, val)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to find
- val:
None|str|int|float Target value for the parameter, often an index number
- tec:
- Outputs:
- Versions:
2017-10-05
@ddalle: First version
- GetCommandIndex(cmd, nmax=1)¶
Find indices of command by name
- Call:
>>> Kcmd = tec.GetCommandIndex(cmd, nmax=1)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to find
- nmax: {
1} |int> 0 Maximum finds to locate
- tec:
- Outputs:
- Versions:
2020-01-28
@ddalle: First version
- GetKey(cmd, key, n=0, par=None, k=None, v=None)¶
Get the value of a key from the nth instance of a command
- Call:
>>> val = tec.GetKey(cmd, key, n=0, par=None, k=None, v=None)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to find
- key:
str Name of the key to find within the command
- n: {
0} |int>= 0 Instance of command to find
- par: {
None} |int|str Optional parameter value for which to search
- k: {
None} |str Optional key to use as search value
- v: {
None} |str|int If k is used, value to test for search key
- tec:
- Outputs:
- val:
any|None Value of the key if present
- val:
- Versions:
2017-10-05
@ddalle: First version
- GetPar(cmd, n=0)¶
Read a parameter value on the header line of a command
- InsertCommand(k, cmd, txt='', lines=[])¶
Insert a command
- Call:
>>> tec.InsertCommand(k, cmd, txt="", lines=[])
- Inputs:
- Versions:
2015-03-10
@ddalle: First version
- InsertKey(i, key, val)¶
Insert a new key
- Call:
>>> tec.InsertKey(i, key, val)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- i:
int Line number on which to start
- key:
str Name of the key
- val:
any Value for that line
- tec:
- Versions:
2018-03-29
@ddalle: First version
- InsertLines(i, lines)¶
Insert a list of lines starting at a certain location
- Call:
>>> tec.InsertLines(i, lines)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- i:
int Index at which to insert the first line
- lines:
list[str] Lines to insert, lines[0] is inserted at line i
- tec:
- Versions:
2015-03-10
@ddalle: First version
- KeyToText(key, val, m=0)¶
Create text for a key and value pair
- Call:
>>> lines = tec.KeyToText(key, val, m=0)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script/layout interface
- key:
str Name of the key
- val:
any Value to write
- m: {
2} | nonnegativeint Number of leading spaces
- tec:
- Versions:
2016-01-05
@ddalle: First version
- ReadKey(i)¶
Read a key by converting text to a value
- Call:
>>> key, val, m = tec.ReadKey(i)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- i:
int Line number on which to start
- tec:
- Outputs:
- Versions:
2016-01-05
@ddalle: First version
- ReplaceCommand(cmd, txt='', lines=[], k=1, reg=None, regs=None)¶
Replace a command
- Call:
>>> tec.ReplaceCommand(cmd,txt="",lines=[],k=1,reg=None,regs=None)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to replace
- txt:
str Text to add after the command on the same line
- lines:
list[str] Additional lines to add to the command
- k:
int Default command index at which to insert command
- reg:
str Regular expression for text after the command
- regs:
list[str] Additional lines to filter for (regular expressions)
- tec:
- Versions:
2015-03-10
@ddalle: First version
- SetContourLevels(n, V)¶
Set contour levels for global contour map n
- Call:
>>> tec.SetContourLevels(n, V)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- n:
int Contour map number (as labeled in layout file)
- V:
np.ndarray[float] List of contour levels
- tec:
- Versions:
2017-10-05
@ddalle: First version
- SetFieldMap(grps)¶
Set active zones for a Tecplot layout, mostly for Overflow
- Call:
>>> tec.SetFieldMap(grps)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script interface
- grps:
list[int] List of last zone number in each
FIELDMAPsection
- tec:
- Versions:
2016-10-04
@ddalle: First version
- SetKey(cmd, key, val, n=0, par=None, k=None, v=None)¶
Find a key in a specified command and rewrite it
- Call:
>>> tec.SetKey(cmd, key, val, n=0, par=None, k=None, v=None)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- cmd:
str Title of the command to find
- key:
str Name of the key to edit
- val:
any New value of the key to write
- n: {
0} |int>= 0 Instance of command to find
- par: {
None} |int|str Optional parameter value for which to search
- k: {
None} |str Optional key to use as search value
- v: {
None} |str|int If k is used, value to test for search key
- tec:
- Versions:
2017-10-05
@ddalle: First version
- SetMach(mach)¶
Set the freestream Mach number
- Call:
>>> tec.SetMach(mach)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- mach:
float Freestream Mach number
- tec:
- Versions:
2015-10-15
@ddalle: First version
- SetPar(cmd, val, n)¶
Set a parameter value on the header line of a command
- Call:
>>> tec.SetPar(cmd, val, n)
- Inputs:
- Versions:
2016-10-04
@ddalle: Version 1.02017-01-05
@ddalle: Version 1.1; i -> n2022-02-06
@ddalle: Version 2.0; case insensitive
- SetSliceLocation(n=1, **kw)¶
Set slice location
- Call:
>>> tec.SetSlice(n=1, **kw)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script interface
- n: {
1} | positiveint Slice number to edit
- x: {
None} |float x-coordinate of slice
- y: {
None} |float y-coordinate of slice
- z: {
None} |float z-coordinate of slice
- i: {
None} |int Index of I slice to plot
- j: {
None} |int Index of J slice to plot
- k: {
None} |int Index of K slice to plot
- tec:
- Versions:
2017-02-03
@ddalle: First version
- SetVar(key, val)¶
Set a variable to a particular value
- Call:
>>> tec.SetVar(key, val)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- key:
str Name of variable
- val: any
Value to set the variable, converted via
str()
- tec:
- Versions:
2015-10-15
@ddalle: First version
- UpdateCommands()¶
Find lines that start with ‘$!’ and report their indices
- Call:
>>> tec.UpdateCommands()
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- tec:
- Effects:
- Versions:
2015-02-28
@ddalle: First version
- WriteKey(i, key, val)¶
Replace a key with a new value
- Call:
>>> tec.WriteKey(i, key, val)
- Inputs:
- tec:
cape.filecntl.tecplot.Tecscript Instance of Tecplot script base class
- i:
int Line number on which to start
- key:
str Name of the key
- val:
any Value for that line
- tec:
- Versions:
2016-01-05
@ddalle: First version