cape.pvutils: Utilities for using PyVista with CAPE

This module provides common utilities to create PyVista flow visualization figures in combination with CAPE. It includes a main_template() that can be used as the main interface to PyVista for individual customized templates.

This includes the class PVArgs to process various command-line options, which can either make a single frame or a video. Videos can be made using multiple processes working in parallel (each process working a specific frame).

class cape.pvutils.PVArgs(*args, **kw)

Argument and CLI parser for PyVista utilities

cape.pvutils.genr8_filenames(OUTS: list, n: int | None = None, j: int | None = None) → list

Create list of file names, which may have frame number

The inputs are simple prefixes. If n is None, the outputs will simply add ".png" to each template:

>>> genr8_filenames(["y0-far", "y0-near"])
["y0-far.png", "y0-near.png"]

If an iteration is given, the output will have a frame number

>>> genr8_filenames(["y0-far", "y0-near"], 1000)
["y0-far.001000.png", "y0-near.001000.png"]
>>> genr8_filenames(["y0-far", "y0-near"], 1000, 20)
["y0-far.000020.png", "y0-near.000020.png"]
Call:
>>> outfiles = genr8_filenames(outs, n=None, j=None)
Inputs:
outs: list[str]

List of prefixes for file names

n: {None} | int

Iteration number to plot (or use latest if None)

j: {None} | int

Output frame number (or use n if None)

Outputs:
outfiles: list[str]

List of output files

cape.pvutils.main_template(frame_func: Callable, outs: list, pat: str) → int

Template function for customized PyVista scripts

Call:
>>> ierr = main_template(frame_func, outs, pat)
Inputs:
frame_func: callable

Function to process a single frame, takes args as follows: frame_func(runner, parser, n=None, j=None)

outs: list[str]

List of prefixes for file names

pat: str

Template file name to search for iterations of

Outputs:
ierr: int

Return code

cape.pvutils.make_video(runner: CaseRunner, outs: list, pat: str | int, frame_func: Callable, parser: PVArgs, cutplanes: list | None = None, surfaces: list | None = None) → int

Template to assemble PyVista frames into a video

Call:
>>> make_video(runner, outs, pat, frame_func, parser)
Inputs:
runner: cape.cfdx.casecntl.CaseRunner

Single-case control instance

outs: list[str]

List of prefixes for file names

pat: str

Template file name to search for iterations of

frame_func: callable

Function to process a single frame, takes args as follows: frame_func(runner, parser, n=None, j=None)

parser: PVArgs

CLI args parsed using PVAgs

cape.pvutils.savefig(pl: Plotter, outs: list, w: int = 1920, h: int = 1080)

Save an image from a PyVista plotter

Call:
>>> savefig(pl, outs, w, h)
Inputs:
pl: pyvista.Plotter

Active PyVista plotter instance

outs: list[str]

List of output file names; uses first entry and pops it

w: {1920} | int

Width of output image in pixels

h: {1080} | int

Height of output image in pixels