cape.filecntl.tecplot: Interface to Tecplot macro and layout files

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.

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

Versions:
  • 2015-03-10 @ddalle: Version 1.0

  • 2022-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

Outputs:
tec: cape.filecntl.tecplot.TecMacro

Instance of Tecplot macro interface

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

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

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

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

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

Outputs:
tec: pyCart.tecplot.Tecscript

Instance of Tecplot script base class

Versions:
  • 2015-02-26 @ddalle: Started

  • 2015-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

Outputs:
v: str | int | float

Evaluated value of the text

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)

Outputs:
kcmd: int

Index of earliest deleted command or None if no deletions

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

Outputs:
kcmd: int

Index of deleted command or None if no deletions

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

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 None return all

Outputs:
ibeg: None | int | list[int]

Index of start of command (or None if less than n instances of commands named cmd)

iend: None | int | list[int]

Index of start of next command

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:
tec: cape.filecntl.tecplot.Tecscript

Instance of Tecplot script base class

cmd: str

Title of the command to find

key: str

Name of key to filter

val: None | str | int | float

Target value for the key

Outputs:
ibeg: None | int

Index of start of command (or None if less than n instances of commands named cmd)

iend: None | int

Index of start of next command

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

Outputs:
ibeg: None | int

Index of start of command (or None if less than n instances of commands named cmd)

iend: None | int

Index of start of next command

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

Outputs:
Kcmd: list[int]

List of indices of tec.cmds that match cmd

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

Outputs:
val: any | None

Value of the key if present

Versions:
  • 2017-10-05 @ddalle: First version

GetPar(cmd, n=0)

Read a parameter value on the header line of a command

Call:
>>> val = tec.GetPar(cmd, n=0)
Inputs:
tec: cape.filecntl.tecplot.Tecsript

Instance of Tecplot script

cmd: str

Name of command

n: int

Alter the instance n of this command

Outputs:
val: None | str | int | float

Value of the parameter on that line, if any

Versions:
  • 2017-01-05 @ddalle: First version

InsertCommand(k, cmd, txt='', lines=[])

Insert a command

Call:
>>> tec.InsertCommand(k, cmd, txt="", lines=[])
Inputs:
tec: pyCart.tecplot.Tecscript

Instance of Tecplot script base class

k: int

Default command index at which to insert command

cmd: str

Title of the command to insert

txt: str

Text to add after the command on the same line

lines: list[str]

Additional lines to add to the command

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

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

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} | nonnegative int

Number of leading spaces

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

Outputs:
key: str

Name of the key whose definition starts on this line

val: any

Value for that line

m: int

Number of lines used for definition of this key

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)

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

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 FIELDMAP section

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

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

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:
tec: cape.filecntl.tecplot.Tecsript

Instance of Tecplot script

cmd: str

Name of command

val: str

String to set on the header line

n: int

Alter the instance n of this command

Versions:
  • 2016-10-04 @ddalle: Version 1.0

  • 2017-01-05 @ddalle: Version 1.1; i -> n

  • 2022-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} | positive int

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

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()

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

Effects:
tec.icmd: list[int]

Indices of lines that start commands

tec.cmds: list[str]

Name of each command

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

Versions:
  • 2016-01-05 @ddalle: First version