open_viewmin.filter_tree_plot_Qt.filter_tree_plot_Qt

Contents

open_viewmin.filter_tree_plot_Qt.filter_tree_plot_Qt#

Extend pyvistaqt.BackgroundPlotter functionality to include auto-updating filter trees and more complete UI.

Classes#

FilterTreePlot

PyVista Plotter with meshes organized into a "filter tree".

FilterTreePlotQt

Implement some PyVista functionality, with filter trees, in the PyVistaQt

Functions#

sort_filenames_by_timestamp(filenames)

Sort names of output files from the same run by timestamp

Module Contents#

class FilterTreePlot(filenames=None, user_settings=None, theme=None, reader=ovm_utilities.fast_import, dims=None, data_stride=1, **kwargs)#

Bases: pyvista.Plotter

PyVista Plotter with meshes organized into a “filter tree”.

Updates to any mesh are automatically followed by updates to its child meshes and actors, recursively.

Parameters:
  • filenames (list[str], str, or None, optional) – Files to import.

  • user_settings (dict or None, optional) – Customizations to default plotter settings.

  • theme (['dark' | 'document' | 'paraview' | None], optional) – PyVista plot theme

  • reader (callable()) – Function to import and process data files

  • dims (tuple of ints or None, optional) – System dimensions used if no filenames are given.

  • data_stride (int, optional) – Spacing between grid sites used if no filenames are given.

  • kwargs (dict, optional) – Keyword arguments to pyvista.Plotter()

__getitem__(mesh_name)#

Mimic dictionary key-value behavior for mesh names and meshes.

Parameters:

mesh_name (str)

Return type:

FilterFormula

__repr__()#

Represent plotter as a textual representation of its filters tree.

Returns:

Textual representation of filters tree.

Return type:

str

__setitem__(mesh_name, filter_formula_lambda)#

Mimic dictionary key-value behavior for mesh names and meshes.

Parameters:
  • mesh_name (str)

  • filter_formula_lambda (callable()) – Callable that creates filter formula

Return type:

FilterFormula

_add_checkbox_generic(callback, current_val, size=50, position=None, color_on=None, **kwargs)#

Add checkbox

Parameters:
  • callback (callable)

  • current_val (bool)

  • size (int)

  • position (tuple(float), optional)

  • color_on (pyvista.plotting.colors.Color, optional)

  • kwargs – keyword arguments to :meth:pyvista.Plotter.add_checkbox_button_widget

_add_inplot_slider(callback, mesh_name, current_val=None, min_val=None, max_val=None, title=None, title_height=0.03, style='classic', label_height=0.03, pointa=None, pointb=None, loc='top right', **kwargs)#
Parameters:
  • callback (callable)

  • mesh_name (str)

  • current_val (float, optional)

  • min_val (float, optional)

  • max_val (float, optional)

  • title (str, optional)

  • title_height (float, optional)

  • style (str, optional) – Options in pyvista.global_theme.slider_styles

  • label_height (float)

  • pointa (tuple(float), optional)

  • pointb (tuple(float), optional)

  • loc (str, optional) – Slider location by keyword; options are “top left”, “bottom left”, “bottom right”. If any other string or None is given, slider is positioned in top right.

  • kwargs – keyword arguments to pyvista.Plotter.add_slider_widget()

Return type:

vtk.vtkSliderWidget

_set_pyvista_plotter_properties()#

Initialization choices for PyVista Plotter

_visibility_callback(actor_name)#
actor_names()#

Names of all actors in filters tree.

Returns:

List of actor names.

Return type:

list[str]

add_axes()#

Add x,y,z axes widget.

add_filter_formula(name=None, **kwargs)#

Add a filter formula to the plotter.

Parameters:
  • name (str or None, optional) – Name of new mesh. Pass None to do nothing.

  • **kwargs – Keyword arguments to FilterFormula

Returns:

New child mesh created by filter formula, or None if no filter formula was created.

Return type:

pyvista.dataset or None

add_isosurface_slider(mesh_name, min_val=None, max_val=None, title=None, title_height=0.02, style='classic', label_height=0.02, pointa=None, pointb=None, loc='top right', **kwargs)#

Add isosurface slider

Parameters:
  • mesh_name (str)

  • min_val (float, optional)

  • max_val (float, optional)

  • title (str, optional)

  • title_height (float)

  • style (str, optional) – Options in pyvista.global_theme.slider_styles

  • label_height (float, optional)

  • pointa (tuple(float), optional)

  • pointb (tuple(float), optional)

  • loc (str, optional) – Slider location by keyword; options are “top left”, “bottom left”, “bottom right”. If any other string or None is given, slider is positioned in top right.

  • kwargs – keyword arguments to _add_inplot_slider()

Return type:

vtk.vtkSliderWidget

add_plane_widget(*args, **kwargs)#

Overload add_plane_widget to take a string argument as name of mesh controlled by widget.

Parameters:
  • *args (tuple, optional)

  • **kwargs (dict, optional)

Return type:

vtkmodules.vtkInteractionWidgets.vtkImplicitPlaneWidget

add_root_mesh(mesh, mesh_name='fullmesh')#

Add a filter formula as a new root of the filter tree.

Parameters:
  • mesh (pyvista.DataSet) – PyVista mesh

  • mesh_name (str, optional) – Name of the new root mesh.

Returns:

Name of the new root mesh (possibly altered to avoid overwriting existing mesh names).

Return type:

str

add_threshold_slider(mesh_name, min_val=None, max_val=None, title=None, title_height=0.02, style='classic', label_height=0.02, pointa=None, pointb=None, loc='top right', **kwargs)#

Add slider for threshold

Parameters:
  • mesh_name (str)

  • min_val (float, optional)

  • max_val (float, optional)

  • title (str, optional)

  • title_height (float, optional)

  • style (str, optional) – Options in pyvista.global_theme.slider_styles

  • label_height (float, optional)

  • pointa (tuple(float), optional)

  • pointb (tuple(float), optional)

  • loc (str, optional) – Slider location by keyword; options are “top left”, “bottom left”, “bottom right”. If any other string or None is given, slider is positioned in top right.

  • kwargs – keyword arguments to _add_inplot_slider()

add_visibility_checkbox(actor_name, size=50, position=None, **kwargs)#

Add checkbox to toggle an actor’s visibility

Parameters:
  • actor_name (str)

  • size (int)

  • position (tuple(float), optional)

  • kwargs – Keyword arguments to _add_checkbox_generic()

add_widget_checkbox(widget_name, size=50, position=None, background_color='red', **kwargs)#

Add checkbox that activates/deactivates a widget

Parameters:
  • widget_name (str)

  • size (int)

  • position (tuple(float), optional)

  • background_color (str)

  • kwargs – Keyword arguments to _add_checkbox_generic()

add_widget_formula(name=None, **kwargs)#

Add a widget formula to the plotter.

Parameters:
  • name (str or None, optional) – Name of new widget. Pass None to do nothing.

  • **kwargs (dict, optional) – Keyword arguments to WidgetFormula

Returns:

The new widget formula, or None if none was created.

Return type:

WidgetFormula or None

array_dims()#

System array-size dimensions.

Returns:

(array_Lx, array_Ly, array_Lz)

Return type:

tuple(int)

assign_file_data_to_frame(file_data, filename, do_load_frame=True)#

Store data from a file as a new frame in the plotter’s timeseries data.

Parameters:
  • file_data (np.ndarray)

  • filename (str)

  • do_load_frame (bool, optional) – Whether to view the frame

colorbar_titles()#

Get titles of all scalar bars

Returns:

List of scalar bar titles

Return type:

list[str]

colorbars()#

Get list of all existing colorbars (scalar bars) for filter tree actors.

Return type:

list of VTK scalar bar actors

copy_all_actors(to_plotter)#

Copy actors to another plotter, such as for displaying in Jupyter notebooks.

Parameters:

to_plotter (pyvista.Plotter)

Return type:

None

create_fullmesh(dat=None, mesh_name='fullmesh', frame_num=None)#

Create a uniform grid mesh as a root mesh for the filter tree.

Parameters:
  • dat (np.ndarray, optional) – Data array, with first three columns holding integer coordinates X, Y, Z.

  • mesh_name (str, optional) – Name of root mesh.

  • frame_num (int or None, optional) – Frame number for this root mesh. Pass None to append as a new frame.

Returns:

Frame number and new root mesh.

Return type:

int, pyvista.dataset

dims()#

System linear dimensions.

Returns:

(Lx, Ly, Lz)

Return type:

tuple(int)

disable_eye_dome_lighting()#
disable_shadows()#
do_orbit()#

Move camera along orbit path

Removes actor named “orbit”, if it exists, before starting the motion.

enable_eye_dome_lighting()#
enable_shadows()#
extract_actors(jupyter_backend='trame')#

Set up a new PyVista plotter with a copy of all this plotter’s actors.

Parameters:

jupyter_backend (str, optional) – PyVista plotting backend. See https://docs.pyvista.org/version/stable/user-guide/themes.

Returns:

New PyVista Plotter containing this Plotter’s actors.

Return type:

pyvista.Plotter

filter_tree_roots()#

Names of meshes whose generating FilterFormula ‘s are roots of the filter tree

Return type:

list[str]

find_actor_for_scalar_bar(scalar_bar)#

Get the name of the filter tree mesh corresponding to a given scalar bar.

Parameters:

scalar_bar (VTK scalar bar actor)

Returns:

Mesh name

Return type:

str

first_frame()#

View first frame in data timeseries.

get_actor(actor_name)#

Return actor with a given name, if it exists.

Parameters:

actor_name (str) – Name of actor.

Returns:

PyVista actor.

Return type:

vtkmodules.vtkRenderingOpenGL2.vtkOpenGLActor

get_actor_name(actor)#

Given an actor, return its name.

Parameters:

actor (vtkOpenGLActor) – PyVista actor.

Returns:

Name of actor.

Return type:

str

get_filter_formula(actor_name)#

Get the formula needed to re-create an actor from its parent mesh.

Parameters:

actor_name (str) – Name of the actor.

Returns:

Actor recipe.

Return type:

types.SimpleNamespace

get_grandparent_mesh_name(actor_or_mesh_name)#

Get the name of the parent of the parent of a given actor or mesh.

Parameters:

actor_or_mesh_name (str) – Name of actor of mesh

Returns:

Name of grandparent mesh.

Return type:

str

get_mesh(mesh_name)#

Return mesh with a given name, if it exists. For non-mesh actors, return parent mesh.

Parameters:

mesh_name (str)

Returns:

PyVista mesh

Return type:

pyvista.DataSet

get_mesh_name(mesh)#

Get the name of a given mesh.

Parameters:

mesh (pyvista.DataSet)

Returns:

name of the mesh

Return type:

str

get_points()#

Get array of coordinates belonging to root mesh “fullmesh”

Returns:

Array of point coordinates.

Return type:

np.ndarray

get_widget(widget_name)#

Get widget by name

Parameters:

widget_name (str)

Return type:

vtkmodules.vtkInteractionWidgets.vtk3DWidget

get_widget_formula(widget_name)#

Get WidgetFormula by name

Parameters:

widget_name (str)

Return type:

WidgetFormula

hide_all_actors()#

Make all actors invisible

hide_all_meshes()#

Make actors of all meshes invisible

hide_orbit()#

Remove the mesh visualizing the camera orbit.

initialize_plotter(**kwargs)#

Run pyvista.Plotter initialization.

Note: This is removed from __init__() for purposes of multiple inheritance of NematicPlot.

last_frame()#

View last frame in data timeseries.

load(filenames, reader=ovm_utilities.fast_import, mpi_group=True, do_load_frame=True)#

Import a file or files.

Parameters:
  • filenames (str or list[str]) – Files to load.

  • reader (callable, optional) – Function to read each file.

  • mpi_group (bool, optional) – Whether to stitch files together as separate outputs from the same timestep from an MPI run.

  • do_load_frame (bool, optional) – Whether to view the frame containing the loaded data.

mesh_names()#

Names of all meshes in filters tree.

Returns:

List of mesh names.

Return type:

list[str]

name_mesh_without_overwriting(mesh_name)#

Modify a proposed new mesh name to be distinct from existing mesh names

Parameters:

mesh_name (str) – Proposed mesh name

Returns:

Distinct mesh name to use

Return type:

str

name_widget_without_overwriting(widget_name)#
Modify a proposed new widget name to be distinct from existing

widget names

Parameters:

widget_name (str) – Proposed widget name

Returns:

Distinct widget name to use

Return type:

str

next_frame()#

View next frame in data timeseries.

non_filter_tree_actor_names()#

List actors that don’t belong to open_viewmin’s filter tree.

Returns:

List of actor names.

Return type:

list[str]

num_frames()#

Number of frames in timeseries data.

static organize_filenames(filenames, mpi_group=True)#

For data to be imported, sort filenames alphabetically after grouping MPI files appropriately.

Parameters:
  • filenames (list[str] | str)

  • mpi_group (bool)

Return type:

list[str]

play(pause_time=0.5)#

In-GUI animation; will be slow because it loads and renders on the fly

previous_frame()#

View previous frame in data timeseries.

probe_at_picked_surface_point(result_name=None)#

Create a FilterFormula with the sample filter probing a picked mesh at a picked point

Parameters:

result_name (str, optional) – Name of new FilterFormula; defaults to “_probed” appended to name of picked mesh

Returns:

result_name – Name of new FilterFormula

Return type:

str

refresh()#

Re-apply all filter formulas to refresh meshes

remove_mesh_completely(mesh_name, remove_children=True)#

Remove a mesh (filter or actor) from the plotter and from the filters tree.

Parameters:
  • mesh_name (str) – Name of mesh to remove.

  • remove_children (bool, optional) – Whether to recursively remove all meshes descended from this mesh in the filters tree.

Return type:

None

rename_mesh(from_name, to_name, do_refresh=True)#

Copy a mesh in the filters tree by copying its recipe.

Parameters:
  • from_name (str) – Name of mesh to copy.

  • to_name (str) – Name of new mesh.

  • do_refresh (bool, optional) – Whether to create the mesh anew from its filter after renaming.

Return type:

None

save_meshes(file_prefix)#

Save all meshes to .vtk files

Parameters:

file_prefix (str) – File location will be [mesh_name].vtk appended to this.

scalar_fields(mesh_name='fullmesh')#

List names of datasets with one value at each site.

Parameters:

mesh_name (str or pyvista.DataSet) – PyVista mesh or its name.

Returns:

List of array names.

Return type:

list[str]

set_actor_visibility(actor, visibility: bool)#

Set visibility of a mesh or meshes

Parameters:
  • actor (str, sequence of str, VTK actor, or sequence of VTK actors)

  • visibility (bool) – Whether mesh(es) are to be visible.

set_background(*args, **kwargs)#

Set plotter’s background color(s)

If called with no arguments, retrieves color from FilterTreePlot.settings[“background_color”], defaulting to black. Otherwise, args and kwargs are sent to pyvista.Plotter.set_background.

Parameters:
  • args

  • kwargs

set_lights_intensity(intensity)#

Rescale intensity of all lights.

Parameters:

intensity (float)

set_orbit(**kwargs)#

Set orbit properties and get its camera locations

Parameters:

kwargs – keyword arguments to set_orbit_kwargs()

Returns:

Orbit points

Return type:

pyvista.core.pointset.PolyData

set_orbit_kwargs(factor=3.0, n_points=20, viewup=None, shift=0.0, step=0.1)#

Modify camera orbit

Parameters:
  • factor (float) – orbit radius relative to data extent

  • n_points (int) – number of points subdividing circle at which to generate images

  • viewup (iterable[float], optional) – orientation vector for camera’s up direction

  • shift (float) – translation of camera location along viewup

  • step (float) – orbit speed in seconds per frame

Returns:

vis – Visibility of orbit points actor

Return type:

bool

show_orbit()#

Add a mesh of points visualizing the camera orbit.

symmetric_tensor_fields(mesh_name='fullmesh')#

List names of datasets with nine values at each site, whose corresponding 3x3 matrix is everywhere symmetric.

Parameters:

mesh_name (str or pyvista.DataSet) – PyVista mesh or its name.

Returns:

List of array names.

Return type:

list[str]

tensor_fields(mesh_name='fullmesh')#

List names of datasets with nine values at each site.

Parameters:

mesh_name (str or pyvista.DataSet) – PyVista mesh or its name.

Returns:

List of array names.

Return type:

list[str]

static toggle_actor_visibility(actor)#

Toggle visibility of an actor

Parameters:

actor (VTK actor)

Returns:

new_visibility

Return type:

bool

toggle_eye_dome_lighting()#

Switch eye dome lighting on/off

toggle_filter_tree_actor_visibility(actor_name)#

Toggle visibility of a mesh in the filter tree.

Parameters:

actor_name (str) – Name of mesh

toggle_floor()#

Toggle visibility of floor (-z) plane.

toggle_last_colorbar()#

Toggle visibility of most recently modified colorbar.

toggle_orbit_visibility(toggle=True)#

Toggle visibility of mesh visualizing camera orbit.

toggle_scalar_bar_visibility(scalar_bar_actor)#

Toggle visibility of a scalar bar

Parameters:

scalar_bar_actor (VTK scalar bar actor)

toggle_shadows()#

Turn shadow rendering on/off

toggle_stereo_render()#

Turn anaglyph stereo 3D effect on/off

unique_array_names(mesh=None)#

Get array names for datasets attached to a mesh, deleting duplicates.

Parameters:

mesh (str or pyvista.DataSet) – PyVista mesh or name of mesh

Returns:

Mesh along with the list of unique array names.

Return type:

(pyvista.DataSet, list[str])

update_actor(actor_name, **kwargs)#

Update a filter formula’s mesh visualization options.

Shorthand for self.get_filter_formula(ellipsoid_mesh_name).set()

Parameters:
update_filter(mesh_name, update_actor=False, **kwargs)#

Update a filter formula.

Shorthand for self.get_filter_formula(parent_mesh_name).update().

Parameters:
vector_fields(mesh='fullmesh')#

List names of datasets with three values at each site.

Parameters:

mesh (str or pyvista.DataSet) – PyVista mesh or its name.

Returns:

List of array names.

Return type:

list[str]

view_frame(frame_num=0, keep_camera_dist=True)#

Use one of the (already imported) sets of data as the source for all PyVista meshes, e.g. for generating a frame of an animation from timeseries data.

Parameters:
  • frame_num (int, optional) – Index in self.data of the timeframe to display.

  • keep_camera_dist (bool, optional) – Whether to force camera to maintain position after frame load.

property default_mesh#
property fullmesh#
class FilterTreePlotQt(filenames=None, user_settings=None, theme=None, reader=ovm_utilities.fast_import, **kwargs)#

Bases: open_viewmin.filter_tree_plot.filter_tree_plot.FilterTreePlot, pyvistaqt.BackgroundPlotter

Implement some PyVista functionality, with filter trees, in the PyVistaQt GUI

Parameters:
  • filenames (list[str], str, or None, optional) – Files to import.

  • user_settings (dict or None, optional) – Customizations to default plotter settings.

  • theme (['dark' | 'document' | 'paraview' | None], optional) – PyVista plot theme

  • reader (callable()) – Function to import and process data files

  • kwargs (dict, optional) – Keyword arguments to open_viewmin.FilterTreePlot

_assign_keypress_events()#

Assign actions to keyboard keys.

static _get_menu(parent, title)#

Get a menu with a given title

Parameters:
  • parent (PyQt5.QtWidgets.QMenuBar) – Menu bar to search

  • title (str) – Title of menu

Returns:

Menu

Return type:

PyQt5.QtWidgets.QMenu

_init_procedures_after_data_import()#

Initialization steps that can be carried out only after some data is imported

add_filter_formula(name=None, **kwargs)#
add_slice_with_controls(scalars_name, mesh_to_slice_name='fullmesh')#

Create a callable that adds a slice filter formula controlled by sliders and buttons in the controls area.

Parameters:
  • scalars_name (str or None) – Name of scalar dataset to use for coloring the slice. Pass None to use a solid color.

  • mesh_to_slice_name (str, optional) – Name of parent mesh to slice

Return type:

callable()

add_widget_formula(name=None, **kwargs)#
customize_controls_dock()#

Modify settings of controls area

enable_pyvista_3_lights(only_active=False)#
enable_pyvista_lightkit(only_active=False)#
initialize_plotter(**kwargs)#

Override parent class’s plotter initialization to use pyvistaqt.BackgroundPlotter instead of pyvista.Plotter

Parameters:

kwargs (dict, optional) – Keyword arguments to pyvistaqt.BackgroundPlotter

load(filenames, **kwargs)#
open_files_dialog(sort=True)#

Launch GUI widget for selecting files to import

Parameters:

sort (bool, optional) – Whether to sort filenames by timestamp

refresh()#
remove_actor_completely(actor_name)#
remove_mesh_completely(mesh_name, remove_children=True)#
rename_mesh(from_name, to_name, do_refresh=False)#
save_html(filename=None)#

Export plotter scene as interactive html widget

Parameters:

filename (str or None) – Filename to write to. Pass None to launch GUI file selector.

save_mesh(mesh_name, mesh_filename=None)#

Export a mesh.

Note that the allowed file types depend on the type of mesh.

Parameters:
  • mesh_name (str) – Mesh name

  • mesh_filename (str or None) – File to write to. Pass None to launch GUI file selector.

save_meshes_launch_dialog(file_prefix=None)#
set_actor_visibility(actor, visibility)#
set_orbit_dlg(**kwargs)#
show_editor()#

Show editor widget controlling actors’ visibility

update_actor(actor_name, **kwargs)#
update_filter(mesh_name, update_actor=False, **kwargs)#
update_filters_tree()#
update_frame_spinbox()#

Update the spinbox controlling the frame

view_frame(frame_num=0, **kwargs)#

Use one of the imported data files as the source for all datasets

property actor_control_toolbars#
Get toolbars controlling individual actors
Returns:

Dictionary of toolbars

Return type:

dict

sort_filenames_by_timestamp(filenames)#

Sort names of output files from the same run by timestamp

Parameters:

filenames (sequence of str)

Return type:

list of str