Visualization¶
See visualization and video for rendering requirements, field selection, camera settings, fixed color limits, and output naming.
Mesh rendering¶
Visualization with pyvista.
Figure out how to add multiple layers to the visualization. E.g. streamlines in addition to other data.
DataRangeType
¶
Bases: str, Enum
Enum for handling the data range.
Local: use the data range of every individual variable GLOBAL: use the global range over multiple variables
DataLayer
dataclass
¶
DataLayer(sid, title, colormap='magma', viz_type=AttributeType.SCALAR, color_limits=None, scalar_bar=True, conversion_factor=None)
Data layer for plot.
Currently only a single data layer is supported but this will be extended to map multiple layers in a single visualiztion
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
Name of the mesh data array to render. |
title |
str
|
Scalar bar title. |
colormap |
ColormapOptions
|
PyVista colormap name or definition. |
viz_type |
AttributeType
|
Type of mesh attribute to activate. |
color_limits |
tuple[float, float] | None
|
Fixed minimum and maximum scalar values. |
scalar_bar |
bool
|
Whether to show a scalar bar. |
conversion_factor |
float | None
|
Factor for converting data before plotting. |
update_color_limits
¶
Update color limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_limits
|
DataLimits
|
Available limits indexed by the data layer identifier. |
required |
only_empty
|
bool
|
Update only layers without existing limits when true. |
True
|
VisualizationSettings
dataclass
¶
VisualizationSettings(window_size=(lambda: [1000, 1000])(), off_screen=True, camera_position=(0, 0.0003, 0.001), zoom=1.1)
General visualization settings for panel.
These should be determined once for a given geometry and then be used consistently.
visualize_data_layers
¶
Visualize geometry with pyvista.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Geometry and data for one time point. |
required |
data_layers
|
Iterable[DataLayer]
|
Layers to render as separate panels. |
required |
output_dir
|
Path
|
Directory for per-layer output folders. |
required |
image_name
|
str
|
Output image name without its extension. |
required |
visualization_settings
|
VisualizationSettings | None
|
Camera and rendering settings, or defaults. |
None
|
visualize_datalayers_timecourse
¶
Create visualizations for individual panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xdmf_path
|
Path
|
Input XDMF time course. |
required |
output_dir
|
Path
|
Directory for rendered panels. |
required |
data_layers
|
Iterable[DataLayer]
|
Layers to render separately for each time point. |
required |
window_size
|
tuple[int, int]
|
Width and height of each panel in pixels. |
(600, 600)
|
visualize_interactive
¶
Visualize geometry with pyvista.
create_combined_images
¶
Create combined images for all timepoints.
VTU conversion¶
Read VTU files for visualization.
vtu_to_xdmf
¶
Convert a static VTU mesh to XDMF/HDF and return the mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vtu_path
|
Path
|
Input VTU mesh path. |
required |
xdmf_path
|
Path
|
Destination XDMF path. Its HDF sidecar stays beside it. |
required |
overwrite
|
bool
|
Explicitly allow replacement of existing regular output files. |
False
|
Returns:
| Type | Description |
|---|---|
Mesh
|
The mesh read from the VTU file. |
Matplotlib styling¶
Opt-in Matplotlib styling that restores the application's configuration.
Image processing¶
Image manipulation.
Combine and annotate images using PIL.
merge_images
¶
Combine images into a vertical strip, horizontal strip, or grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Iterable[Path]
|
Input images in panel order. |
required |
output_path
|
Path
|
Destination image path. |
required |
direction
|
str
|
Layout: "vertical", "horizontal", "square", or "custom". |
'vertical'
|
ncols
|
int | None
|
Positive column count required for a custom grid. |
None
|
nrows
|
int | None
|
Positive row count required for a custom grid. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no images are supplied or the layout is invalid. |
Annotate images with text.
annotate_image_text
¶
annotate_image_text(image_in_path, image_out_path, text, xy=(10, 10), *, font_path=None, font_size=40)
Annotate an image with a portable default font or an explicit TrueType font.
Video¶
These helpers require FFmpeg on PATH.
Tools related to videos.
Requires ffmpeg for video generation.
create_video
¶
Create a video from image frames using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_pattern
|
str
|
ffmpeg input pattern for the image sequence. |
required |
video_path
|
Path
|
Destination video path. |
required |
frame_rate
|
int
|
Frames per second. |
30
|
codec
|
str
|
ffmpeg video codec name. |
'mpeg4'
|
overwrite
|
bool
|
Whether ffmpeg may overwrite an existing video. |
True
|
Raises:
| Type | Description |
|---|---|
FileExistsError
|
If the destination exists and overwrite is false. |
CalledProcessError
|
If ffmpeg fails. |
create_gif_from_video
¶
Convert a video to a GIF using ffmpeg.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
Path
|
Existing source video path. |
required |
gif_path
|
Path
|
Destination GIF path. |
required |
overwrite
|
bool
|
Whether ffmpeg may overwrite an existing GIF. |
True
|
Raises:
| Type | Description |
|---|---|
OSError
|
If the source video does not exist. |
FileExistsError
|
If the destination exists and overwrite is false. |
CalledProcessError
|
If ffmpeg fails. |