cape.pycart.dataBook: pyCart data book module

This module contains functions for reading and processing forces, moments, and other statistics from cases in a trajectory. Data books are usually created by using the cape.pycart.cntl.Cntl.ReadDataBook() function.

# Read Cart3D control instance
cntl = pyCart.Cntl("pyCart.json")
# Read the data book
cntl.ReadDataBook()
# Get a handle
DB = cntl.DataBook

# Read a line load component
DB.ReadLineLoad("CORE_LL")
DBL = DB.LineLoads["CORE_LL"]
# Read a target
DB.ReadTarget("t97")
DBT = DB.Targets["t97"]

Data books can be created without an overall control structure, but it requires creating a run matrix object using cape.pycart.runmatrix.RunMatrix, so it is a more involved process.

Data book modules are also invoked during update and reporting command-line calls.

$ pycart --aero
$ pycart --ll
$ pycart --report

The available components mirror those described on the template data book modules, cape.cfdx.dataBook, cape.cfdx.lineLoad, and cape.cfdx.pointSensor. However, some data book types may not be implemented for all CFD solvers.

See Also:
class cape.pycart.dataBook.CaseFM(comp)

Cart3D case force and moment history

This class contains methods for reading data about an the history of an individual component for a single case. It reads the file $comp.dat where comp is the name of the component. From this file it determines which coefficients are recorded automatically. If some of the comment lines from the Cart3D output file have been deleted, it guesses at the column definitions based on the number of columns.

Call:
>>> FM = pyCart.dataBook.CaseFM(comp)
Inputs:
comp: str

Name of component to process

Outputs:
FM: cape.pycart.aero.FM

Instance of the force and moment class

FM.coeffs: list[str]

List of coefficients

FM.i: numpy.ndarray shape=(0,)

List of iteration numbers

FM.CA: numpy.ndarray shape=(0,)

Axial force coefficient at each iteration

FM.CY: numpy.ndarray shape=(0,)

Lateral force coefficient at each iteration

FM.CN: numpy.ndarray shape=(0,)

Normal force coefficient at each iteration

FM.CLL: numpy.ndarray shape=(0,)

Rolling moment coefficient at each iteration

FM.CLM: numpy.ndarray shape=(0,)

Pitching moment coefficient at each iteration

FM.CLN: numpy.ndarray shape=(0,)

Yaw moment coefficient at each iteration

Versions:
  • 2014-11-12 @ddalle: Starter version

  • 2014-12-21 @ddalle: Copied from previous aero.FM

  • 2015-10-16 @ddalle: Self-contained version

MakeEmpty()

Create empty CaseFM instance

Call:
>>> FM.MakeEmpty()
Inputs:
FM: cape.pycart.dataBook.CaseFM

Case force/moment history

Versions:
  • 2015-10-16 @ddalle: First version

ProcessColumnNames(lines)

Determine column names

Call:
>>> FM.ProcessColumnNames(lines)
Inputs:
FM: cape.pycart.dataBook.CaseFM

Case force/moment history

lines: list[str]

List of lines from the data file

Versions:
  • 2015-10-16 @ddalle: First version

Write(fname)

Write contents to force/moment file

Call:
>>> FM.Write(fname)
Inputs:
FM: cape.pycart.dataBook.CaseFM

Instance of the force and moment class

fname: str

Name of file to write.

Versions:
  • 2015-03-02 @ddalle: First version

class cape.pycart.dataBook.CaseResid

Iterative history class

This class provides an interface to residuals, CPU time, and similar data for a given run directory

Call:
>>> hist = pyCart.dataBook.CaseResid()
Outputs:
hist: cape.pycart.dataBook.CaseResid

Instance of the run history class

Versions:
  • 2014-11-12 @ddalle: Starter version

class cape.pycart.dataBook.DBComp(comp, cntl, targ=None, check=False, lock=False, **kw)

Individual component data book

Call:
>>> DBi = DBComp(comp, x, opts, targ=None)
Inputs:
comp: str

Name of the component

x: cape.pycart.runmatrix.RunMatrix

RunMatrix for processing variable types

opts: cape.pycart.options.Options

Global pyCart options instance

targ: {None} | str

If used, read a duplicate data book as a target named targ

Outputs:
DBi: cape.pycart.dataBook.DBComp

An individual component data book

Versions:
  • 2014-12-20 @ddalle: Started

class cape.pycart.dataBook.DBTarget(targ, x, opts, RootDir=None)

Class to handle data from data book target files. There are more constraints on target files than the files that data book creates, and raw data books created by pyCart are not valid target files.

Call:
>>> DBT = pyCart.dataBook.DBTarget(targ, x, opts)
Inputs:
targ: cape.pycart.options.DataBook.DBTarget

Instance of a target source options interface

x: cape.pycart.runmatrix.RunMatrix

Run matrix interface

opts: cape.pycart.options.Options

Global pyCart options instance to determine which fields are useful

Outputs:
DBT: cape.pycart.dataBook.DBTarget

Instance of the pyCart data book target data carrier

Versions:
  • 2014-12-20 @ddalle: Started

class cape.pycart.dataBook.DBTriqFM(x, opts, comp, **kw)

Force and moment component extracted from surface triangulation

Call:
>>> DBF = DBTriqFM(x, opts, comp, RootDir=None)
Inputs:
x: cape.runmatrix.RunMatrix

RunMatrix/run matrix interface

opts: cape.options.Options

Options interface

comp: str

Name of TriqFM component

RootDir: {None} | st

Root directory for the configuration

Outputs:
DBF: cape.pycart.dataBook.DBTriqFM

Instance of TriqFM data book

Versions:
  • 2017-03-29 @ddalle: First version

GetTriqFile()

Get most recent triq file and its associated iterations

Call:
>>> qtriq, ftriq, n, i0, i1 = DBF.GetTriqFile()
Inputs:
DBF: cape.pycart.dataBook.DBTriqFM

Instance of TriqFM data book

Outputs:
qtriq: {False}

Whether or not to convert file from other format

ftriq: str

Name of triq file

n: int

Number of iterations included

i0: int

First iteration in the averaging

i1: int

Last iteration in the averaging

Versions:
  • 2016-12-19 @ddalle: Added to the module

class cape.pycart.dataBook.DataBook(cntl, RootDir=None, targ=None, **kw)

This class provides an interface to the data book for a given CFD run matrix.

Call:
>>> DB = pyCart.dataBook.DataBook(x, opts)
Inputs:
x: cape.pycart.runmatrix.RunMatrix

The current pyCart trajectory (i.e. run matrix)

opts: cape.pycart.options.Options

Global pyCart options instance

Outputs:
DB: cape.pycart.dataBook.DataBook

Instance of the pyCart data book class

Versions:
Delete(I)

Delete list of cases from data book

Call:
>>> DB.Delete(I)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of the pyCart data book class

I: list[int]

List of trajectory indices or update all cases in trajectory

Versions:
  • 2015-03-13 @ddalle: First version

GetCurrentIter()

Determine iteration number of current folder

Call:
>>> n = DB.GetCurrentIter()
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of data book class

Outputs:
n: int | None

Iteration number

Versions:
  • 2017-04-13 @ddalle: First separate version

ReadCaseFM(comp)

Read a CaseFM object

Call:
>>> FM = DB.ReadCaseFM(comp)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of data book class

comp: str

Name of component

Outputs:
FM: pyFun.dataBook.CaseFM

Residual history class

Versions:
  • 2017-04-13 @ddalle: First separate version

ReadCaseResid()

Read a CaseResid object

Call:
>>> H = DB.ReadCaseResid()
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of data book class

Outputs:
H: pyFun.dataBook.CaseResid

Residual history class

Versions:
  • 2017-04-13 @ddalle: First separate version

ReadDBComp(comp, check=False, lock=False)

Initialize data book for one component

Call:
>>> DB.ReadDBComp(comp, check=False, lock=False)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of the pyCart data book class

comp: str

Name of component

check: True | {False}

Whether or not to check LOCK status

lock: True | {False}

If True, wait if the LOCK file exists

Versions:
  • 2015-11-10 @ddalle: First version

  • 2016-06-27 @ddalle: Added targ keyword

  • 2017-04-13 @ddalle: Self-contained and renamed

ReadLineLoad(comp, conf=None, targ=None)

Read a line load data book target if it is not already present

Call:
>>> DB.ReadLineLoad(comp)
Inputs:
DB: pycart.dataBook.DataBook

Instance of the pycart data book class

comp: str

Line load component group

conf: {"None"} | cape.config.Config

Surface configuration interface

targ: {"None"} | str

Sets alternate directory to read from, defaults to DB.targ

Versions:
  • 2015-09-16 @ddalle: First version

  • 2016-06-27 @ddalle: Added targ

ReadPointSensor(name, pts=None)

Read a point sensor group if it is not already present

Call:
>>> DB.ReadPointSensor(name)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of the pyCart data book class

name: str

Name of point sensor group

Versions:
  • 2015-12-04 @ddalle: First version

ReadTarget(targ)

Read a data book target if it is not already present

Call:
>>> DB.ReadTarget(targ)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of the Cape data book class

targ: str

Target name

Versions:
  • 2015-09-16 @ddalle: First version

ReadTriqFM(comp, check=False, lock=False)

Read a TriqFM data book if not already present

Call:
>>> DB.ReadTriqFM(comp, check=False, lock=False)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of pyCart data book class

comp: str

Name of TriqFM component

check: True | {False}

Whether or not to check LOCK status

lock: True | {False}

If True, wait if the LOCK file exists

Versions:
  • 2017-03-29 @ddalle: First version

UpdatePointSensor(name, I=None)

Update a point sensor group data book for a list of cases

Call:
>>> DB.UpdatePointSensorGroup(name)
>>> DB.UpdatePointSensorGroup(name, I)
Inputs:
DB: cape.pycart.dataBook.DataBook

Instance of the pyCart data book class

I: list[int] or None

List of trajectory indices or update all cases in trajectory

Versions:
  • 2015-10-04 @ddalle: First version

cape.pycart.dataBook.get_xlim(ha, pad=0.05)

Calculate appropriate x-limits to include all lines in a plot

Plotted objects in the classes matplotlib.lines.Lines2D are checked.

Call:
>>> xmin, xmax = get_xlim(ha, pad=0.05)
Inputs:
ha: matplotlib.axes.AxesSubplot

Axis handle

pad: float

Extra padding to min and max values to plot.

Outputs:
xmin: float

Minimum x coordinate including padding

xmax: float

Maximum x coordinate including padding

Versions:
  • 2015-07-06 @ddalle: First version

cape.pycart.dataBook.get_ylim(ha, pad=0.05)

Calculate appropriate y-limits to include all lines in a plot

Plotted objects in the classes matplotlib.lines.Lines2D and matplotlib.collections.PolyCollection are checked.

Call:
>>> ymin, ymax = get_ylim(ha, pad=0.05)
Inputs:
ha: matplotlib.axes.AxesSubplot

Axis handle

pad: float

Extra padding to min and max values to plot.

Outputs:
ymin: float

Minimum y coordinate including padding

ymax: float

Maximum y coordinate including padding

Versions:
  • 2015-07-06 @ddalle: First version